rem NixieClock.bas 3/23/2008 rem The two dials are for setting the time to the next five minute rem To set, put the switch to the left for AM, else right, and push the button rem After it reaches the set time, put the switch to the right immediately to hold rem set the switch to the middle when the five-minute point is reached. rem uses 127 bytes out of 128 #picaxe 18 rem Input ports symbol Duration = 1 'No space to implement symbol RTC = Input2 symbol Wipers = Input7 symbol SRData = Input6 rem Output ports symbol SRCLK = 0 'For inputs except analog duration and wipers symbol SRLoad = 1 'For inputs except analog duration and wipers symbol Relay = 2 'No space to implement symbol DimAMLED = 3 symbol TestPoint = 5 'Used to set the oscillator symbol BrtAMLED = 6 'No space to implement, dim is bright enough symbol NixieCLK = 7 'Advances on negative edge, which is HIGH rem global variables symbol Phase = bit0 'Of the 2 hz square wave symbol Cycles = b1 'Of the half-cycles symbol Mask = b2 'For shift register values symbol BitPos = b3 'Shift register iterator symbol Control = b4 'Control and status inputs symbol Old12Hrs = b5 'Both inputs high betwen 12:00 and 12:59 symbol New12Hrs = b6 'Both inputs high betwen 12:00 and 12:59 symbol SetMode = b7 'After button is pressed until set time is reached symbol AM = b8 'Non-zero for AM symbol Hold = b9 'Non-zero for hold rem constants to isolate particular inputs symbol RunMask = %00000001 'QH symbol SetMask = %00000010 'QG symbol AMMask = %00000100 'QF symbol HoldMask = %00001000 'QE symbol PotMask = %01000000 'QB - No space to implement symbol HrsMask = %10100000 'QA & QC rem EEPROM data DATA 0,(1,2,4,8,16,32,64,128) 'Mask of bits for Shifting init: main: ReadControl: 'shifts 8 bits QH first low voltage gives a one HIGH SRCLK LOW SRLoad 'Loads on low volts - pulse high because of darlington PULSOUT SRLoad,1 'Load the control data into the '165 LET Control = 0 FOR BitPos = 0 TO 7 IF SRData = 1 THEN NotOn 'Invert sense because switches go to common READ BitPos,Mask LET Control = Control | Mask NotOn: PULSOUT SRCLK,1 NEXT rem Turn the AM LED on or off IF AM = 0 THEN LOW DimAMLED 'LED off ELSE HIGH DimAMLED 'LED on ENDIF rem Set the time IF SetMode = SetMask THEN InSetMode 'Button has been pressed LET SetMode = Control & SetMask 'See if the set button is pressed InSetMode: 'Continue once in set mode IF Wipers = 1 OR SetMode = 0 THEN NotSetting 'reached the time setting, LET Cycles = 0 'First advance is one minute after time is reached PULSOUT NixieCLK, 100 'Count up until the set time is reached LET AM = Control & AMMask 'Set the AM during setting only GOTO main NotSetting: LET SetMode = 0 'go to normal operation rem wait for end of RTC half-cycle - 250 milliseconds IF Phase = RTC THEN main LET Phase = RTC rem quarter-second processing LET Hold = Control & HoldMask 'Hold updating until the next 5-min time is reached IF Hold = HoldMask THEN main INC Cycles rem one minute processing IF Cycles > 239 THEN 'Clock the counter and determine AM or PM LET Cycles = 0 HIGH NixieCLK 'Clocks on going high, low volts after darlington LET New12Hrs = Control & HrsMask IF New12Hrs <> Old12Hrs AND New12Hrs = 0 THEN 'Got to 12:01 LET AM = AM ^ AMMask ENDIF LET Old12Hrs = New12Hrs ELSEIF Cycles <> 40 THEN 'The nixie counter prefers a squareish wave LOW NixieCLK ENDIF GOTO main END