'AXE110 PICAXE-18X - New Datalogger Mission Program
'Automatically generated by Wizard
'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 - Event based Diff Pressure
'Date - 27/11/2007
'Time - 11:28:10 AM
'Options Selected
'Sensors:
'Sensor 0 - Tank (Analogue 0-5V)
'Sensor 1 - Manifold( Analogue 0-5V)
'Sensor 2 - Boom (PWM)
'Sensor 3 - Temperature (Digital - DS18B20)
'Memory:
'No of readings = 105
'4 x 24LC256
'Outputs:
'AXE111 EE WP on output6
'Logging Period:
'DS1307 RTC
'Hours: 1 Mins: 15 Secs: 0
' ********************
' ***** Symbols *****
' ********************
'Symbol definitions
symbol data0 = b0
symbol data1 = b1
symbol data2 = w5 '(b10 + b11)
symbol data3 = b3
symbol top_address = w2 '(b4 + b5)
symbol address = w3 '(b6 + b7)
symbol temp_word = w4 '(b8 + b9)
symbol temp_byte = b10
symbol temp_byte1 = b11
symbol temp_byte2 = b12
symbol temp_byte3 = b13
symbol hours = b11
symbol mins = b12
symbol secs = b13
symbol day = b0
symbol month = b1
symbol COM = 44 'comma
symbol RET = 13 'carriage return
symbol LFEED = 10 'line feed
Symbol limit = 350 'Boom Angle Limit - determied on site
symbol boom = w4
'Preload sensor names and title into data memory
EEPROM 0,(0,0)
EEPROM 16,("Diff Press")
EEPROM 32,("Time")
EEPROM 48,(" ")
EEPROM 64,("Temperature")
EEPROM 80,("Event based Diff Pressure")
' ***************************
' ***** Initialisation *****
' ***************************
init:
high 5 ' write protect eeprom
high 6 ' write protect eeprom
'reload the last address from data memory
read 0,b6
read 1,b7
' *********************************
' ***** Main loop - read data *****
' *********************************
i2cslave $50,i2cfast,i2cbyte ‘set up i2cslave for LCD
pause 500 ‘ wait for display to initialise
writei2c ($80,$0c) '0x0c = CLS & first line
main:
mainup:
' test for 2 consecutive readings above limit
pulsin 0,1,boom
if boom < limit then
pause 250
sertxd ("down ",#boom,13,10)
goto mainup
endif
pulsin 0,1,boom
if boom < limit then goto mainup
' If it gets to this point the boom is up.
sertxd ("up ",#boom,13,10)
writei2c ($80, $0d) 'Goto beginning of first line
writei2c ($80,"Boom High ")
maindown:
' test for 2 consecutive readings below limit before saying down
pulsin 0,1,boom
pause 250
if boom > limit then
sertxd ("up ",#boom,13,10)
goto maindown
endif
pulsin 0,1,boom
if boom > limit then goto maindown
' If it gets to this point the boom has gone from up to down.
'Write Boom Drop to LCD
writei2c ($80,$0c) '$0c = Clear display goto first line
writei2c ($80,"Boom Drop ")
pause 50
' Capture the data
readadc 0,data0 'Pressure Tank
pause 30
readadc 1,data1 'Pressure Return Manifold
pause 30
let temp_byte = data1 - data0
readtemp 2,data3 'Read Temp (Includes delay)
pause 30
'Display change onPC
sertxd ("DP ",#temp_byte," Temp ",#data3,13,10)
'Display Data on Modtronix LCD.
writei2c ($8a,2,1) 'goto row 2 pos 1
writei2c ($80,"DP ")
bintoascii temp_byte,temp_byte1,temp_byte2,temp_byte3
writei2c ($80, temp_byte1,temp_byte2,temp_byte3)
pause 30
writei2c ($80," Temp ")
bintoascii data3,temp_byte1,temp_byte2,temp_byte3
pause 30
writei2c ($80, temp_byte1,temp_byte2,temp_byte3)
'send to PC
Pause 1000
writei2c ($80,$0d) '0x0d = first line
writei2c ($80,"Boom Low ")
'*** At this point test for time condition
'**** if met, save the data go to a subrioutine
goto main
' *****************************
' ***** Now Save the Data *****
' *****************************
' ***** I have not done anything on this yet, just happy that the loop works *****
'Now save the data
save_data:
low 5 ' write enable eeprom
low 6 ' write enable eeprom
'4x 24LC256. Input0 in IC0, input1 in IC1
'4x 24LC256. Input2 in IC2, input3 in IC3
if address > 16383 then memory_full
i2cslave %10100000, i2cslow, i2cword
writei2c address,(data0)
pause 10
readi2c address,(temp_byte)
if temp_byte <> data0 then ee_error
i2cslave %10100010, i2cslow, i2cword
writei2c address,(data1)
pause 10
readi2c address,(temp_byte)
if temp_byte <> data1 then ee_error
i2cslave %10100100, i2cslow, i2cword
writei2c address,(data2)
pause 10
readi2c address,(temp_byte)
if temp_byte <> data2 then ee_error
i2cslave %10100110, i2cslow, i2cword
writei2c address,(data3)
pause 10
readi2c address,(temp_byte)
if temp_byte <> data3 then ee_error
'increment address and save in data memory
inc_address:
high 5 ' write protect eeprom
high 6 ' write protect eeprom
let address = address + 1
write 0,b6
write 1,b7
if address > 1050 then memory_full
' ***********************
' ***** Time Delays *****
' ***********************
'Now do time delay
'Read time now
read_rtc_now:
i2cslave %11010000, i2cslow, i2cbyte
readi2c 0,(secs,mins,hours)
'Convert to decimal then add offset
gosub bcd_decimal
let data0 = secs
let data1 = mins
let data2 = hours
Add_Secs:
let data0 = data0 + 0
if data0 < 60 then Add_Mins
'Secs is now greater than 60 so add 1 to minute instead
let data0 = data0 - 60
let data1 = data1 + 1
Add_Mins:
let data1 = data1 + 15
if data1 < 60 then Add_Hours
'Mins is now greater than 60 so add 1 to hour instead
let data1 = data1 - 60
let data2 = data2 + 1
Add_Hours:
let data2 = data2 + 1
if data2 < 24 then read_rtc
'Hours is now greater than 24 so correct
let data2 = data2 - 24
'Read rtc to test alarm'
read_rtc:
i2cslave %11010000, i2cslow, i2cbyte
readi2c 0,(secs,mins,hours)
gosub bcd_decimal
if secs <> data0 then read_rtc
if mins <> data1 then read_rtc
if hours <> data2 then read_rtc
'now do next reading
goto main