'PicAXE data logger 'Based on the work of Peter Anderson www.phanderson.com 'Revised 11-27-06 profmason pins = 0 'Declarations Symbol ADVal = B4 'Current Value in the ADC symbol N = B0 ' Generic counter variable symbol X = B2 'Generic storage variable symbol Y = B2 'Generic storage variable Symbol AddressPtr = 253 'This contains the number of datapoints saved. 'IE if the EEPROM has 20 datapoints this will store $14 Symbol FirstTime0 = 254 Symbol FirstTime1 = 255 Main: Pause 1000 Read FirstTime0, X ' read location 254 and 255 to Read FirstTime1, Y ' determine if this is first time If X <> $55 And Y <> $AA Then FirstTime ' first time clear and reset Main_1: X = Pins & $03 'By ANDing the input pins with %00000011 this returns 0 if (0,0) ' 1 if (1,0) 2 if (0,1) and 3 if (1,1) Branch X, (Lock, ResetEEPROM, DumpData, Log) ' 00 Nothing, 01 Reset, 10 Dump Data, 11 Init, ResetEEPROM: high 0 pause 1000 low 0 Write AddressPtr, 00 SerTxD ("Memory Reset", 13, 10) Goto Lock Lock: X = Pins & $03 Branch X, (Lock, ResetEEPROM, DumpData, Log) ' 00 Nothing, 01 Reset, 10 Dump Data, 11 Init 'Now can do a new datalogging run without rebooting Goto Lock: DumpData: Read AddressPtr, X high 1 If X = 0 Then NoLoggedData ' else X = X-1 For N = 0 to X Read N, Y ' read and display SerTxD (#N, " , ", #Y, " ",13,10) Next low 1 Goto Lock NoLoggedData: SerTxD ("No Data", 13, 10) 'Output Error to the Serial Port (13,10) is New Line pause 1000 low 1 Goto Lock Log: Read AddressPtr, X If X = 0 Then Log_1 ' else Write X, $ff ' to indicate there was a power interruption X = X + 1 Write AddressPtr, X 'allow recovery of data Log_1: GoSub Measure ' Read AddressPtr, X Write X, ADval 'Write to data location in AddressPtr the ADC value X = X + 1 Write AddressPtr, X 'Update the Address Ptr GoSub Blip ' If X >= 250 Then Lock 'Limit of 250 data points! ' else Pause 1000 'Take data once a second X = Pins & $03 If X = 2 then Lock 'Jump out of logging and dump data Goto Log_1 Blip: Pin0 = 1 Pause 250 Pin0 = 0 ' Blink the LED at Pin 1 SerTxD ("Reading ",#X, 13, 10) 'Output to the serial port that DA is happening Return Measure: ReadADC 2, ADVal Return FirstTime: For N = 1 to 5 high 0 high 1 pause 150 low 0 low 1 pause 150 next N Write FirstTime0, $55 Write FirstTime1, $AA Write AddressPtr, $00 ' location of where data is to be stored SerTxD ("Init OK!", 13, 10) Goto Main_1