rem "DAUController.BAS" 3/9/2008 rem This program is intended to be used only with an adapter which was made,and still rem is usable with, Ocean controls (NZ) "Kit 118" PC parallel port 12-bit data logger rem as an alternative which does not tie up a PC, but has lower (10-bit) resolution. rem This is optionally used with a separate box containing a Rogue Robotics (Canada) rem Outputs to Secure Digital module writer on Positions 0 and A once a minute rem Outputs to terminal on Position B Mode 2) each other second rem Outputs to PicaxeMeter on Position C Mode 3) each other second rem Clock on Pin4. is 1sec period, 67 ms pos pulse #PICAXE 40X1 #Com 1 symbol Version = 14 rem Bit variables - uses bytes 0 and 1 symbol BlinkPhase = bit1 'Controls blinking during adjustments symbol Set = bit2 'Set Button - 1 if pressed symbol OldSet = bit3 symbol Clr = bit4 'Clear Button - 1 if pressed symbol Entr = bit5 'Enter Button - 1 if pressed symbol OldEntr = bit6 'State of Enter in previous iteration symbol Blink = bit7 'Flag to DispDEC to blink on Phase symbol UpdateFlag = bit8 'Allows sending data to SD writer symbol MinuteFlag = bit9 'Set by interrupt to initiate recording data symbol HeaderFlag = bit10 'Triggers recording header row in SD writer symbol FieldFlag = bit11 'Flag to DispDec to deliniate digits symbol SpaceFlag = bit12 'Flag to DispChar to follow character with a space symbol CommaFlag = bit13 'Flag to DispChar to precede character with a comma symbol Pin6isOut = bit14 'Pin 6 is an output, portc pin 1 symbol Pin9isOut = bit15 'Pin 9 is an output, portc pin 2 rem word variables - uses bytes 2 - 5 symbol Remainder = w1 'Multi-use scratchpad variable symbol DECdata = w2 'Multi-use scratchpad variable rem byte variables - uses bytes 6 - 27 symbol DispMode = b8 'Tells DispDEC how to present the number symbol Seconds = b9 '0..59 symbol Minutes = b10 '0..59 symbol Hours = b11 '0..13 symbol Day = b12 '1..DayInMonth symbol Month = b13 '1..12 symbol Year = b14 'last 2 digits only symbol Mode = b15 'Position of rotary switch: 0..6 symbol OldMode = b16 'Restores the display when changing mode symbol SettingIndex = b17 'During adjustment, indicates which field to adjust symbol Index = b19 'Multi-use scratchpad variable symbol Iter = b20 'Multi-use scratchpad variable symbol CharData = b21 'Multi-use scratchpad variable symbol BitPos = b22 'Used only in DispCmd symbol Hundreds = b23 'Used only in DispDEC symbol Tens = b24 'Used only in DispDEC symbol Units = b25 'Used only in DispDEC symbol DayInMonth = b26 'Used only in Interrupt symbol DayInMonthIndex = b27 'Used only in Interrupt symbol row0addr = $80 'instruction value for top row symbol row1addr = $C0 'second row symbol row2addr = $94 'third row symbol row3addr = $D4 'bottom row symbol DispInitData = 1 symbol DispEndData = 7 DATA 1,($30,$30,$30,$38,$0C,$01,$06,$14,$80) 'Display Init strings '5 4/40V Analog inputs: Location, pin# , Display Mode 'Order is: ' Second row: Left BNC, Right BNC, Differential Amp ' Third Row: Yellow Jack, Green Jack, Temperature ' Fourth row: Bi-polar Amp, Pin 1, Pin 3, Pin 5, AC Opto, DC Opto, Pin 6 ,Pin 9, symbol AnalogDataLoc0 = 10 symbol AnalogDataLoc4 = 22 DATA 10,($C0,0,$A,$C6,1,$A,$CC,5,$A,$94,2,$A,$9A,3,$C) symbol DayInMonthLoc = 25 DATA 25,(31,28,31,30,31,30,31,31,30,31,30,31) symbol DayLoc = 37 DATA 37,(09) 'using EEPROM to reduce need to re-enter when reset symbol MonthLoc = 38 DATA 38,(03) 'using EEPROM to reduce need to re-enter when reset symbol YearLoc = 39 DATA 39,(08) 'using EEPROM to reduce need to re-enter when reset symbol InOutLoc = 42 'Pin direction for port C depends on adapter hardware DATA 42,(%11011110) 'Enable,R/S,ENTR,DC Relay,AC Relay,Pin 9,Pin 6, Pin 5 symbol ParamLoc = 43 DATA 43, ("BNC:LEFT RIGHT ") DATA 63, ("DIFF AMP GREEN ") DATA 83, ("+- 200mv OFFSET ") DATA 103,("PIN 6 PIN 9 ") symbol BNCLeftLoc = $89 symbol BNCRightLoc = $92 symbol DiffLoc = $C9 symbol GreenLoc = $D2 symbol ShuntLoc = $97 symbol OffsetLoc = $A5 symbol Pin6Loc = $DA symbol Pin9Loc = $E5 symbol OffsetValue = 123 'Used for the +/- 200 mv input DATA 123,(99) 'Actual Offset is 300 more - can be set symbol OutLoc = 124 DATA 124,("OUT") symbol InLoc = 127 DATA 127,("IN ") symbol BlankLoc = 130 DATA 130,(" ") symbol LegendLoc = 134 DATA 134,("L BNC | R BNC | DIFF") DATA 154,("YELLOW| GREEN | TEMP") DATA 174,("+/- 200 mv|Pin1|Pin3") DATA 194,("Pin5|AC|DC|Pin6|pin9") DATA 214,(3) 'Scale value for A5:full-scale = 50*scale,1 to 20, 0=200mv symbol ScaleLoc = 214 Main: SETFREQ m8 READ InOutLoc,Iter LET dirsc = Iter LOW portc 7 PAUSE 100 'For the display READ YearLoc,Year READ MonthLoc,Month READ DayLoc,Day LET Seconds = 0 LET Hours = 0 LET SettingIndex = 0 LET HeaderFlag = 0 ResetScreen: rem Initialize Display FOR Iter = DispInitData TO DispEndData READ Iter,CharData GOSUB DispCmd PAUSE 100 NEXT LET MinuteFlag = 0 LET UpdateFlag = 0 LET HeaderFlag = 0 SERTXD ("S 1 5",13) 'Set SD Interface timeout at 10ms steps anyway rem set initial interrupt on positive edge of pulse on pin4 every second from RTC SETINT %00010000,%00010000 looping: 'Main loop tied to interrupt by long pause LET BlinkPhase = ~BlinkPhase 'Used when setting time or parameters #rem Mode is position of rotary switch control Mode Label Use Push-buttons 0 O SD recording w/o backlight Enter records the header 1 A SD recording Enter records a data row 2 B Output to Terminal None 3 C Output to PicaxeMeter None 4 D Displays location legend None 5 P Sets range and in/out parameters Entr=next field,Set=out,Clr=In 6 T Sets time and date Entr=next field,Set=inc,Clr=dec (NA) R Hardware reset #endrem ReadControls: 'takes 3ms LET OldMode = Mode LET OldEntr = Entr LET OldSet = Set LET Iter = Pin5 LET CharData = 2 * Pin6 LET Mode = 4 * Pin7 LET Mode = Mode + CharData + Iter IF Mode > 3 then LET Set = pin2 LET Clr = pin3 ENDIF IF portc pin5 = 1 then LET Entr = 1 ELSE LET Entr = 0 ENDIF rem Manual controls over SD recording IF Mode = 0 and Entr <> OldEntr THEN 'Write the header to the SD LET HeaderFlag = 1 ELSEIF Mode = 1 and Entr <> OldEntr THEN 'Write a record to the SD LET MinuteFlag = 1 ENDIF IF Mode = OldMode then DispData 'display data to the display rem Screen operations when changing mode IF Mode = 5 then 'Write the background for adjusting parameters GOSUB DispFixed ELSE GOTO ResetScreen 'Re-writes the display ENDIF DispData: LET Blink = 0 'Default state IF Mode = 4 THEN 'Show location of each connector's measurements GOTO DispLegend ENDIF IF Mode = 5 THEN GOTO DispParams ENDIF IF Mode = 0 OR Mode = 1 THEN IF MinuteFlag = 1 OR HeaderFlag = 1 then 'Open the file READ YearLoc,Iter LET Iter = Iter + "A" 'Make filename first character READ MonthLoc,Index LET Index = Index + "a" 'Make filename second character READ Dayloc,Day SERTXD ("O 1 A /",Iter,Index,#Day,".CSV",13) PAUSE 50 ENDIF ENDIF IF HeaderFlag = 1 THEN 'Write the header and then enable data recording IF Mode < 2 THEN SERTXD ("W 1 72",13) ENDIF IF Mode < 3 THEN SERTXD ("Time,Date,L BNC,R BNC,Diff,Yellow,Green,Temp,200mv,P1,P3,P5,AC,DC,P6,P9",13,10) ENDIF IF Mode < 2 THEN PAUSE 100 SERTXD ("C 1",13) ENDIF LET MinuteFlag = 1 LET UpdateFlag = 0 LET HeaderFlag = 0 PAUSE 1000 GOTO looping ENDIF IF MinuteFlag = 1 AND Mode < 2 THEN 'Prepare to record data Let MinuteFlag = 0 SERTXD ("W 1 81",13) LET UpdateFlag = 1 ENDIF IF Mode = 3 THEN SERTXD ("Picaxe") ENDIF 'Write the time DispTime: '148ms to display, 126 to SD Writer rem Display time and date on top line LET Chardata = Row0Addr 'Home cursor GOSUB DispCmd LET FieldFlag = 0 LET DECData = Hours LET DispMode = 1 'Two digits IF SettingIndex = 0 AND Mode = 6 THEN LET Blink = 1 ENDIF GOSUB DispDec LET CharData = ":" GOSUB Dispchar LET DECData = Minutes IF SettingIndex = 1 AND Mode = 6 THEN LET Blink = 1 ENDIF GOSUB DispDec LET CharData = ":" GOSUB Dispchar LET DECData = Seconds GOSUB DispDec LET CharData = Row0Addr + 9 GOSUB DispCmd READ Monthloc,DECData IF SettingIndex = 2 AND Mode = 6 THEN LET Blink = 1 ENDIF LET FieldFlag = 1 GOSUB DispDec LET CharData = "/" GOSUB Dispchar READ Dayloc,DECData IF SettingIndex = 3 AND Mode = 6 THEN LET Blink = 1 ENDIF GOSUB DispDec LET CharData = "/" GOSUB Dispchar LET CharData = "2" GOSUB Dispchar LET CharData = "0" GOSUB Dispchar READ Yearloc,DECData IF SettingIndex = 4 AND Mode = 6 THEN LET Blink = 1 ENDIF GOSUB DispDec IF Mode = 6 then SetTimeDate rem Read and display 7 analogs on lines 2,3 and 4 ReadAnalog: '279ms to Display, 241.2 to SD Writer. '---------------------------------------------------- rem Read and display 5 analogs on lines 2 and 3 which have the same math FOR Index = AnalogDataLoc0 to AnalogDataLoc4 step 3 READ Index, CharData 'The location to display the measurement GOSUB DispCmd LET Remainder = Index + 1 'The pin for the measurement READ Remainder, CharData READADC10 CharData,DECData IF Mode = 3 THEN LET CharData = DECData / 4 SERTXD (Chardata) PAUSE 2 ENDIF LET Remainder = Index + 2 'Where to put the decimal point - can be set for some READ Remainder, DispMode IF Index < AnalogDataLoc4 THEN LET DECData = 5 * DECData 'Displays 5 mv or 50mV resolution: 0 to 4000 on the display ELSE 'May be connected to the 20db AC voltmeter or 16 V green jack IF DispMode = $C THEN LET DECData = 25 * DECData LET DECData = DECData/2 ELSE LET DECData = 2 * DECData ENDIF ENDIF LET FieldFlag = 1 GOSUB DispDEC NEXT rem The remaining 2 analogs require custom math '---------------------------------------------------- LET CharData = row2addr + 12 'The location to display the measurement GOSUB DispCmd ReadADC10 7,Remainder 'Voltage from temperature sensor is 10mv per Deg Kelvin LET DECData = 9 * Remainder - 4597 'Convert to 1/10 DEG F resolution - go figure! IF Mode = 3 THEN LET CharData = DECData / 4 SERTXD (CharData) PAUSE 2 ENDIF LET DispMode = $C LET FieldFlag = 1 GOSUB DispDec '---------------------------------------------------- LET CharData = row3addr 'The location to display the measurement GOSUB DispCmd READADC10 6,Remainder 'Bipolar -200 mv to +200 mv IF Mode = 3 THEN LET CharData = Remainder / 4 SERTXD (CharData) ENDIF READ OffsetValue,Chardata LET DECData = Chardata + 300 'This value can be set IF Remainder > DECData THEN 'Measured count for 0V in LET CharData = "+" LET DECData = Remainder - DECData ELSE LET CharData = "-" LET DECData = DECData - Remainder ENDIF LET SpaceFlag = 0 LET CommaFlag = 1 'No space after, but comma before GOSUB DispChar READ ScaleLoc,Index 'This indicates the voltage or shunt value IF Index = 0 THEN LET Index = 4 ENDIF IF Index < 3 THEN 'Format depends on the current range LET Index = 50 * Index LET DispMode = $B ELSE LET Index = 5 * Index LET DispMode = $C ENDIF LET DECData = Index * DECData LET DECData = DECData / 4 LET FieldFlag = 0 'No comma before this value GOSUB DispDec rem Read and display Display Digitals on line 4 ReadDigital: '34.5ms to Display, 29.5 to SD Writer LET CharData = Row3Addr + 7 GOSUB DispCmd LET CommaFlag = 1 LET SpaceFlag = 1 LET FieldFlag = 0 LET CharData = Pin2 + "0" 'DA9 Pin 1 GOSUB DispChar '---------------------------------------------------- LET CharData = Pin3 + "0" 'DA9 Pin 3 GOSUB DispChar '---------------------------------------------------- LET CharData = "0" IF Portc pin0 = 0 then Pin5isoff 'DA9 Pin 5 LET CharData = "1" Pin5isoff: GOSUB DispChar '---------------------------------------------------- LET CharData = Pin0 + "0" 'AC Opto Isolator GOSUB DispChar '---------------------------------------------------- LET CharData = Pin1 + "0" 'DC Opto Isolator GOSUB DispChar '---------------------------------------------------- READ InOutLoc,Iter LET Iter = Iter & %00000010 LET Pin6isOut = 1 IF Iter > 0 then SixIsOut LET Pin6isOut = 0 LET CharData = "0" IF Portc pin1 = 0 then Pin6isoff 'DA9 Pin 6 LET CharData = "1" Pin6isoff: GOSUB DispChar SixIsOut: '---------------------------------------------------- READ InOutLoc,Iter LET Iter = Iter & %00000100 LET Pin9isOut = 1 IF Iter > 0 then NineIsOut LET CharData = "0" LET Pin9isOut = 0 IF Portc pin2 = 0 then Pin9isoff 'DA9 Pin 9 LET CharData = "1" Pin9isoff: LET SpaceFlag = 0 'No space after last pin if > 5 GOSUB DispChar NineIsOut: rem end of transmission: put in the CR, LF, and close the file IF Mode = 2 THEN SERTXD (13,10) ENDIF IF UpdateFlag = 1 AND Mode < 2 THEN SERTXD (13,10) LET UpdateFlag = 0 PAUSE 100 SERTXD ("C 1",13) ENDIF PAUSE 1000 'This will be terminated by the interrupt GOTO looping rem start of subroutines DispCmd: 'puts a command into the display IF UpdateFlag = 0 then LET pins = CharData LET BitPos = CharData & %10000000 'the pins = variable command mat fail to clear pin 7 IF BitPos = 0 then LOW 7 ELSE HIGH 7 ENDIF LOW portc 6 'instruction function is low, HIGH portc 7 'clocks the instruction and the function into the display LOW portc 7 ENDIF RETURN DispChar: 'writes CharData to the display or to the SD Writer IF UpdateFlag = 1 OR Mode = 2 THEN 'Write to SD or terminal IF CommaFlag = 1 then 'Optionally precede with a comma SERTXD (",") ENDIF SERTXD (CharData) ENDIF 'Put CharData to Display HIGH portc 6 'data function is high IF Blink = 1 AND BlinkPhase = 0 then 'Display a space instead LET outpins = " " ELSE LET outpins = CharData ENDIF LOW 7 'Always for English characters HIGH portc 7 'clocks the character into the display LOW portc 7 IF SpaceFlag = 1 then 'Optionally add a space after the character LET outpins = " " LOW 7 HIGH portc 7 'clocks the space into the display LOW portc 7 ENDIF RETURN DispDec: 'Displays DECData at current cursor position in Digital LET SpaceFlag = 0 LET CommaFlag = 0 IF FieldFlag = 1 THEN IF UpdateFlag = 1 OR Mode = 2 THEN 'Write a preceding comma to SD SERTXD (",") ENDIF ENDIF IF Mode < 4 then 'No blink except when in setups LET Blink = 0 ENDIF BINTOASCII DECData,CharData,CharData,Hundreds,Tens,Units IF DispMode = 0 THEN OneDigit IF DispMode = 1 THEN TwoDigit IF DispMode = 2 THEN ThreeDigit ' Only 4-digit can have decimal points GOSUB DispChar IF Dispmode = $A THEN LET CharData = "." GOSUB DispChar ENDIF ThreeDigit: LET CharData = Hundreds GOSUB DispChar IF Dispmode = $B THEN LET CharData = "." GOSUB DispChar ENDIF LET DecData = Remainder TwoDigit: LET CharData = Tens GOSUB DispChar IF Dispmode = $C THEN LET CharData = "." GOSUB DispChar ENDIF OneDigit: LET CharData = Units GOSUB DispChar LET Blink = 0 LET SpaceFlag = 0 LET FieldFlag = 0 RETURN DispFixed: LET FieldFlag = 0 LET SpaceFlag = 0 For Iter = 0 to 3 'Display 4 lines of static data for setting parameters LOOKUP Iter,(Row0Addr,Row1Addr,Row2Addr,Row3Addr),CharData GOSUB DispCmd LET DECData = 20 * Iter + ParamLoc For Index = 0 to 19 LET Remainder = DECData + Index READ Remainder, CharData GOSUB DispChar NEXT NEXT PAUSE 1000 'Syncs with interrupt, which cuts short this pause GOTO Looping DispParams: LET FieldFlag = 0 LET SpaceFlag = 0 For Iter = 0 to 7 LOOKUP Iter,(BNCLeftLoc,BNCRightLoc,DiffLoc,GreenLoc,ShuntLoc,OffsetLoc,Pin6Loc,Pin9Loc),CharData GOSUB DispCmd SELECT Iter CASE 0,1,2 IF SettingIndex = Iter then LET Blink = 1 ENDIF LET CharData = "4" GOSUB DispChar LET Remainder = 3 * Iter + AnalogDataLoc0 + 2 READ Remainder,CharData IF CharData = $A then LET CharData = " " ELSE LET CharData = "0" ENDIF GOSUB DispChar CASE 3 IF SettingIndex = Iter then LET Blink = 1 ENDIF LET Remainder = AnalogDataLoc4 + 2 READ Remainder,CharData IF CharData = $C then 'AC 20 db voltmeter into 3.5 mm stereo jack on back LET CharData = "A" ELSE LET CharData = "D" '16 Volt into green banana socket ENDIF GOSUB DispChar CASE 4 IF SettingIndex = Iter then LET Blink = 1 ENDIF READ ScaleLoc,Index IF Index = 0 THEN '200 mv range ' LET DECData = 200 ELSE 'Current scale when using the attached shunt LET DECData = 50 * Index ENDIF LET DispMode = 3 '4 digits, no DP GOSUB DispDEC LET CharData = "m" GOSUB DispChar IF Index = 0 THEN LET CharData = "v" ELSE LET Chardata = "a" ENDIF GOSUB DispChar CASE 5 IF SettingIndex = Iter then LET Blink = 1 ENDIF READ OffsetValue,Chardata DECData = CharData + 300 DispMode = 2 '3 digits, no DP GOSUB DispDEC CASE 6,7 READ InOutLoc,Index CharData = 2 * Iter - 6 '2 or 4 Index = Index & Chardata IF Index = 0 then LET DECData = InLoc ELSE LET DECData = OutLoc ENDIF IF SettingIndex = Iter then LET Blink = 1 ENDIF FOR Index = 0 to 2 Remainder = DECData + Index READ Remainder,Chardata GOSUB DispChar NEXT ENDSELECT LET Blink = 0 NEXT SetParams: IF Entr = 1 AND OldEntr = 0 THEN INC SettingIndex IF SettingIndex > 7 THEN LET SettingIndex = 0 ENDIF ENDIF SELECT SettingIndex CASE 0,1,2 'The two BNC jacks and the diff amp switch 4 & 40 V LET Remainder = 3 * SettingIndex + AnalogDataLoc0 + 2 IF SET = 1 THEN WRITE Remainder,$B ENDIF IF CLR = 1 THEN WRITE Remainder,$A ENDIF CASE 3 'This may be the rear 3.5 mm jack or the green banana LET Remainder = AnalogDataLoc4 + 2 IF SET = 1 THEN 'Rear WRITE Remainder,$C ENDIF IF CLR = 1 THEN 'Front WRITE Remainder,$B ENDIF CASE 4 '0 = volts, rest current, not all values are valid READ ScaleLoc,CharData LET Iter = 20 GOSUB AdjustValue WRITE ScaleLoc,CharData CASE 5 'Set this for zero display with input shorted READ OffsetValue,CharData LET Iter = 127 GOSUB AdjustValue WRITE OffsetValue,CharData CASE 6 'port2 pin 1 - DA9 pin 6 READ InOutLoc,Chardata IF SET = 1 THEN 'Output LET Iter = %00000010 CharData = Chardata | Iter ELSEIF CLR = 1 THEN LET Iter = %11111101 'Input CharData = Chardata & Iter ENDIF WRITE InOutLoc,Chardata LET dirsc = CharData CASE 7 'port2 pin 2 - DA9 pin 9 READ InOutLoc,Chardata IF SET = 1 THEN 'Output LET Iter = %00000100 CharData = Chardata | Iter ELSEIF CLR = 1 THEN 'Input LET Iter = %11111011 CharData = Chardata & Iter ENDIF WRITE InOutLoc,Chardata LET dirsc = CharData ENDSELECT GOTO looping DispLegend: LET FieldFlag = 0 LET SpaceFlag = 0 For Iter = 0 to 3 'Display 4 lines to show where measurements are placed LOOKUP Iter,(Row0Addr,Row1Addr,Row2Addr,Row3Addr),CharData GOSUB DispCmd LET DECData = 20 * Iter + LegendLoc For Index = 0 to 19 LET Remainder = DECData + Index READ Remainder, CharData GOSUB DispChar NEXT NEXT PAUSE 1000 'Syncs with interrupt, which cuts short this pause GOTO Looping SetTimeDate: IF Entr = 1 AND OldEntr = 0 THEN inc SettingIndex IF SettingIndex > 4 THEN LET SettingIndex = 0 ENDIF Seconds = 0 ENDIF SELECT SettingIndex CASE 0 LET CharData = Hours LET Iter = 23 GOSUB AdjustValue LET Hours = CharData CASE 1 LET CharData = Minutes LET Iter = 59 GOSUB AdjustValue LET Minutes = CharData CASE 2 LET CharData = Month - 1 LET Iter = 11 'computations start at 0, corrected in DispTime GOSUB AdjustValue LET Month = CharData + 1 WRITE MonthLoc,Month CASE 3 LET CharData = DayInMonthLoc + Month READ Chardata,Iter 'to index Day in month LET CharData = Day - 1 GOSUB AdjustValue LET Day = CharData + 1 WRITE DayLoc,Day CASE 4 LET CharData = Year LET Iter = 99 GOSUB AdjustValue WRITE YearLoc,CharData LET Year = CharData ENDSELECT GOTO looping 'This mode is not synced with interrupt AdjustValue: 'value to be updated is in CharData, Limit is in Iter IF Clr = 1 THEN IF CharData = 0 THEN LET CharData = Iter ELSE DEC CharData ENDIF ENDIF IF Set = 1 THEN IF CharData >= Iter THEN LET CharData = 0 ELSE inc CharData ENDIF ENDIF RETURN interrupt: rem Update time & date first - takes 41ms if no no update INC seconds IF seconds > 59 THEN LET seconds = 0 IF Mode < 2 then LET MinuteFlag = 1 ENDIF INC minutes IF minutes > 59 THEN LET minutes = 0 LET hours = hours + 1 IF hours > 23 THEN LET hours = 0 LET HeaderFlag = 1 READ MonthLoc,Month LET DayInMonthIndex = DayInMonthLoc + Month - 1 READ DayInMonthIndex,DayInMonth 'No of Days in month Read DayLoc, Day 'Day INC Day WRITE DayLoc,Day IF Day > DayInMonth THEN WRITE DayLoc,1 READ MonthLoc, Month 'Month INC Month WRITE MonthLoc,Month IF Month > 12 THEN WRITE MonthLoc,1 Read YearLoc, Year 'Year last 2 digits INC Year WRITE YearLoc,Year ENDIF ENDIF ENDIF ENDIF ENDIF DO WHILE pin4 = 1 Pause 1 'Wait until end of pulse if necessary LOOP SETINT %00010000,%00010000 'interrupt on falling edge only RETURN