Code:
Range:
HIGH ext_pwr ' Temporarily turn on power to SRF02 for I2C bus use
PAUSE 500 ' Delay to let I2C bus stabilize after SRF02 turn on
'DEFINE WRITE_USED 1 'Required if only writing WORD variables in v2.6
' Update day counter and address offset for day's measurements
READ 9,day_cnt ' Test if EEPROM data has been captured
' & cleared by PC & new monthly epoch
' started.
day_cnt = day_cnt + 1 ' Increment day counter
Write 9,day_cnt 'Update contents of day_count memory address
Pause 10
If J >= 240 Then
J = 0 ' If allocated EEPROM already used, start over
ENDIF
' Make SRF02 Range Measurement
I2CWRITE SDA,SCL,$E0,0,[80] ' Request start of ranging in inches
pause 100 ' Wait for ranging to finish
I2CREAD SDA,SCL,$E0,2,[rng1,rng0] ' Get ranging results
'WRITE 253,rng1
'Write 254,rng0
WRITE 240,Word w0 ' Write range to EEPROM
' Display time & range measurement on LCD display in inches
LCDOut $FE,1:FLAGS=0:Pause 250 ' Clear Display
I2CREAD SDA, SCL, RTCdevice, SecReg,[sec,MINs,hr,day,date,mon,yr]
LCDOUT $fe,1
LCDOUT $fe,Line1,Hex2 mon,"/",hex2 date,"/",hex2 yr
LCDOUT $fe,Line2,hex2 hr,":",hex2 MINs,":",hex2 sec
Pause 2000 ' Allow Time for user to view
LCDOUT $FE,1
LCDOut $FE,Line1,"Range:" ' Display on 1st line
LCDOut $FE,Line2,#w0," in." ' Display on 2nd line
PAUSE 5000 ' Allow Time for user to view
' Clear STATUS register & Alarm flags..ready for next interrupt
I2CWrite SDA, SCL, rtcdevice, StatusReg,[$00]
LOW ext_pwr ' Turn off power to the SRF02 at end of display.
' This statement will distort the I2C bus and ext_pwr
' must be set HIGH again before any attempts are made to
' use the I2C bus.
' Store range as date-stamped value in EEPROM
WRITE 17+J,WORD w0 'Store day's range in EEPROM
PAUSE 10
Write 16+J,date ' with day of month date-stamp
PAUSE 10
' Step pointer to next logging address in EEPROM
J = J + 3
WRITE 10,J 'Update contents of J index EEPROM memory address
Pause 10
PAUSE 470 ' Delay to permit I2C bus to stabilize after SRF02 off
' Resume Main Program
@ INT_RETURN
Bookmarks