'AXE110 PICAXE-18X - New Datalogger Mission Program
'Automatically generated by Wizard and Manually modified by Westaust55
'LED will flash green as readings are taken.
'Data can be retrieved after mission (LED red) by Datalink tool (F9).
'Use Datalink options: Baud rate - 4800, Sensors - 4, Send G - Enabled
' *******************
' ***** Options *****
' *******************
'Title -
'Date - 13/03/2010
'Time - 12:53:07 PM
'Options Selected
'Sensors:
'Sensor 0 - Future 2
'Sensor 1 - Future 3
'Sensor 2 - Future 4
'Sensor 7 - Temperature
'Memory:
'No of readings = 200
'8 x 24LC256
'Outputs:
' Bi-colour LED
' AXE033 LCD
''Logging Period:
' DS1307 RTC
' Hours: 0 Mins: 5 Secs: 0
' ********************
' ***** Symbols *****
' ********************
'Symbol definitions
symbol data0 = b0
symbol day = b0
symbol data1 = b1
symbol month = b1
symbol data2 = b2
symbol data7 = b3
symbol top_address = w2 '(b4 + b5)
symbol address = w3 '(b6 + b7)
symbol temp_word = w4 '(b8 + b9)
symbol temp_byte = b10
symbol hours = b11
symbol mins = b12
symbol secs = b13
SYMBOL year = b2 ; all other date/time parameters are already defined at the top
SYMBOL LCD = b.0 ; LCD on Output 0 becasue we are using the EEPROM Write Protect
SYMBOL Events = 200 ; the number of events/records to log
; 600 / 60 ==> 12 hours
; 1 count made at start and any PICAXE power recycle an extra
; address location is used to store the complete time and data again
symbol COM = 44 ' comma
symbol RET = 13 ' carriage return
symbol LFEED = 10 ' line feed
'Preload sensor names and title into data memory
EEPROM 0,(0,0,0,0) ; clear the address counter and the power-up/cycle counter
EEPROM 16,("Future 1")
EEPROM 32,("Future 2")
EEPROM 48,("Future 3")
EEPROM 64,("Temperature")
EEPROM 80,("Time Stamping Example")
' ***************************
' ***** Initialisation *****
' ***************************
init:
'high 5 ' write protect eeprom
;
; Here we clear the AXE033 LCD and check if the logging is completed
high LCD
pause 2000
SEROUT LCD, T2400,("?f") 'clear LCD
PAUSE 150
READ 3, temp_byte ; will be set to $FF if memory is full or required number of events have been logged
IF temp_byte =$FF THEN memory_full
SEROUT LCD, T2400,("The Data Logger ?n")
SEROUT LCD, T2400,(" is Activated ")
PAUSE 2000
;
; ===============================================================================
; Here we read the RTC once to collect all data and save time and date across all EEPROMs
; If the power is cycled we end up back here and it will again log the entire time and date information
; This can act as a flag that the power went off and then back on as opposed to just missing some data
; can move the next one line up near other SYMBOL stements if you want
; Fetch the address previously stored in EEPROM -
; If it is a new campain should be zero else indicates PICAXE power was cycled
READ 0,b6 ; fetch any previously stores EEPROM address value
READ 1,b7
;
; Here we save the full data and time data with a marker in the first EEPROM for the transfer to PC phase
Logfulltime: ; we only log the full time and date once per PICAXE power-up/reset at the start
'LOW 5 ; enable writing to EEPROM
i2cSLAVE %11010000, i2cSLOW, i2cBYTE ; set up to read the clock
READi2c 0,(secs,mins,hours,temp_byte,day,month,year) ; read in BCD format
temp_word = $FF ; used as flag when doing BCD to decimal conversion to store full data
GOSUB bcd_decimal ; convert all the BCD values to decimal
temp_word = $00
i2cSLAVE %10100000, i2cSLOW, i2cWORD ; EEPROM 0 save a "-" character in the first EEPROM as a flag
WRITEi2c address,("-")
PAUSE 10 ; pause needed to give EEPROM time to write data before it can be read back
READi2c address,(temp_byte)
IF temp_byte <> "-" THEN ee_error
i2cSLAVE %10100010, i2cSLOW, i2cWORD ; EEPROM 1 save a "-" character in the second EEPROM for good measure
WRITEi2c address,("-")
PAUSE 10
READi2c address,(temp_byte)
IF temp_byte <> "-" THEN ee_error
i2cSLAVE %10100100, i2cSLOW, i2cWORD ; EEPROM 2
WRITEi2c address,(year)
PAUSE 10
READi2c address,(temp_byte)
IF temp_byte <> year THEN ee_error
i2cSLAVE %10100110, i2cSLOW, i2cWORD ; EEPROM 3
WRITEi2c address,(month)
PAUSE 10
READi2c address,(temp_byte)
IF temp_byte <> month THEN ee_error
i2cSLAVE %10101000, i2cSLOW, i2cWORD ; EEPROM 4
WRITEi2c address,(day)
PAUSE 10
READi2c address,(temp_byte)
IF temp_byte <> day THEN ee_error
i2cSLAVE %10101010, i2cSLOW, i2cWORD ; EEPROM 5
WRITEi2c address,(hours)
PAUSE 10
READi2c address,(temp_byte)
IF temp_byte <> hours THEN ee_error
i2cSLAVE %10101100, i2cSLOW, i2cWORD ; EEPROM 6
WRITEi2c address,(mins)
PAUSE 10
READi2c address,(temp_byte)
IF temp_byte <> mins THEN ee_error
i2cSLAVE %10101110, i2cSLOW, i2cWORD ; EEPROM 7
WRITEi2c address,(secs)
PAUSE 10
READi2c address,(temp_byte)
IF temp_byte <> secs THEN ee_error
'HIGH 5 ; write protect the EEPROM
SEROUT LCD, T2400,("?f?n") 'clear LCD and start new line
PAUSE 1000
SEROUT LCD, T2400,("Date ")
IF day <10 THEN
SEROUT LCD, T2400,(" ") ; For single digit values put a blank in front
ENDIF
SEROUT LCD, T2400,(#day,"/")
IF month <10 THEN
SEROUT LCD, T2400,("0") ; For single digit values put a zero in front
ENDIF
SEROUT LCD, T2400,(#month,"/20")
IF year <10 THEN
SEROUT LCD, T2400,("0") ; For single digit values put a zero in front
ENDIF
SEROUT LCD, T2400,(#year)
SEROUT LCD, T2400,(254,192,"?nTime ")
IF hours <10 THEN
SEROUT LCD, T2400,(" ") ; For single digit values put a blank in front
ENDIF
SEROUT LCD, T2400,(#hours,":")
IF mins <10 THEN
SEROUT LCD, T2400,("0") ; For single digit values put a zero in front
ENDIF
SEROUT LCD, T2400,(#mins,":")
IF secs <10 THEN
SEROUT LCD, T2400,("0") ; For single digit values put a zero in front
ENDIF
SEROUT LCD, T2400,(#secs)
PAUSE 2000
; The first address (0) is NOW used to log the full time and date at the start of campaign
; so we increment the address in preparation for event logging and saving of the data
LET address = address + 1
WRITE 0,b6
WRITE 1,b7
; Here we advance the power up/cycle counter while still logging data
READ 2, temp_byte
temp_byte = temp_byte + 1 ; set the start number - increments by 1 each time power up occurs
WRITE 2, temp_byte
;
; The following is back to the standard wizard auto generated program code
'reload the last address from data memory
read 0,b6
read 1,b7
' *********************************
' ***** Main loop - read data *****
' *********************************
'Now read each sensor
main:
high c.3 ' flash green LED
low c.2
; readadc 0, data0
; readadc 1, data1
; readadc 2, data2
readtemp c.7, data7
; These next 3 lines are just some dummy values until you have need for other sensors above
data0 = 1
data1 = 2
data2 = 3
pause 1000
low c.3 ' end of flash LED
; *********************************
; ***** Display values on LCD *****
; *********************************
; Here is continuously display the last logged temperature, how many thimes the power has been cycled or reset performed
; and the number of records stored thus far in the current campaign
;
SEROUT LCD, T2400,("?f?n") 'clear LCD
PAUSE 1000
READ 2,temp_byte
SEROUT LCD, T2400, ("Temp=",#data7," ?n")
SEROUT LCD, T2400, ("PwrOn=",#temp_byte," ?n")
SEROUT LCD, T2400, ("Rec-Count=",#address,"?n")
' *****************************
' ***** Now Save the Data *****
' *****************************
'Now save the data
save_data:
'LOW 5 ' write enable eeprom
;
; ===============================================================================
; This arrangement has changed from the typical wizard auto setup details
; to suit logging of the data and time as well as up to 4 sensors
;
;24LC256 addr 0 = Input0 in IC0 as Humidity
;24LC256 addr 1 = Input1 in IC1 as Future 1
;24LC256 addr 2 = Input2 in IC2 as Future 2 - year at address 0 only
;24LC256 addr 3 = Input3 in IC3 as Temperature - month at address 0 only
;24LC256 addr 4 = Input0 in IC4 as Date
;24LC256 addr 5 = Input0 in IC5 as Hours
;24LC256 addr 6 = Input0 in IC6 as Mins
;24LC256 addr 7 = Input0 in IC7 as Secs
; with 8 x 24LC256 EEPROMs = 32768 bytes each as 0 to 32667
;
; If there was a single 24L16 EEPROM, then that EEPROM is in 8 blocks
; so no change needed below other than the max is now 255 instead of 32767
; in which case adjust the next line of code
if address > 255 then memory_full
;
;
;