Code:
' 24LC16B SERIAL EEPROM DUPLICATOR / ERASER
' (c) Brek Martin 2002!
'
pause 100 'breif pause at startup
INCLUDE "modedefs.bas" 'include serial modes
B0 var byte 'set up variables
B1 var byte 'B0, B1 & B2 as bytes
B2 var byte
addr var byte 'set up address & chip
chip var byte 'variables for EEPROM
B0 = 0 'clear copy buffer
B1 = 0 'clear verify buffer
trisb.0 = 1 'set button pins as inputs
trisb.3 = 1
'
'
fird:
'
onel:
IF portb.3 = 1 THEN twol 'checking for first of two buttons
' at startup
'
GOSUB pron
GOSUB pron
GOSUB pron
GOSUB pron
GOSUB pron
GOSUB pron
GOSUB pron
GOSUB pron
GOSUB pron
GOSUB pron
GOSUB pron
'
'
'
'
'
'
comd:
IF portb.3 = 1 THEN dupl
IF portb.0 = 1 THEN eras
goto comd
'
dupl:
chip = 158 'set chip variable to the
' value of first location minus 2
rone:
chip = chip + 2 'add 2 to the chip variable
IF chip = 176 THEN rnin 'check for last chip location
addr = 0
aone: 'go back here every 256 bytes
high portb.1 'turn source LED on
low portb.1 'and off again
portb.1 = 0
I2CREAD porta.0,porta.1,chip,addr,[B0],eror 'read the byte from source EEPROM
'serout2 portb.7,16780,[hex B0," "] 'send byte out serial port
I2CWRITE portb.4,portb.5,chip,addr,[B0],eror 'write the byte to target EEPROM
pause 15 'wait for the write to complete
high portb.2 'turn target LED on
low portb.2 'and off again
I2CREAD portb.4,portb.5,chip,addr,[B1],eror 'read byte back from target EEPROM
IF B0 != B1 THEN verr 'verify the copied byte
IF addr = 255 THEN rone 'check for last address of each location
addr = addr + 1 'add 1 to addr variable for next read
goto aone 'go back for next read
rnin:
serout portb.7,n2400,[" Copy completed!"]
GOSUB cpyc
GOSUB cpyc
GOSUB cpyc
GOSUB cpyc
GOSUB cpyc
GOSUB cpyc
goto fnsh
'
'
eror: 'label to jump to if error is detected
serout portb.7,n2400,[" A read/write error occured !"]
GOSUB eled
GOSUB eled
GOSUB eled
GOSUB eled
goto fnsh
verr:
serout portb.7,n2400,[" A verify error occured !"]
GOSUB eled
GOSUB eled
GOSUB eled
GOSUB eled
GOSUB eled
goto fnsh
'
eras:
chip = 158 'set chip variable to the
B0 = 0 'value of first location minus 2
B1 = 0 'reset copy and verify buffers
rtwo:
chip = chip + 2 'add 2 to the chip variable
IF chip = 176 THEN rten 'check for last chip location
addr = 0
atwo: 'go back here every 256 bytes
low portb.2 'turn LED on
I2CWRITE portb.4,portb.5,chip,addr,[B0],eror 'write B0 to EEPROM (B0 = 0)
pause 15 'wait for write to complete
I2CREAD portb.4,portb.5,chip,addr,[B1],eror 'read the byte back in
IF B0 != B1 THEN verr 'verify the byte has zero value
'serout2 portb.7,16780,[hex B0," "] 'send byte out serial port
high portb.2 'turn LED off
IF addr = 255 THEN rtwo 'check for last address of each location
addr = addr + 1 'add 1 to addr variable for next read
goto atwo 'go back for next read
rten:
serout portb.7,n2400,[" Erase completed!"]
GOSUB cpyc
GOSUB cpyc
GOSUB cpyc
GOSUB cpyc
GOSUB cpyc
GOSUB cpyc
'
fnsh:
goto comd 'go back and check for button push
'
'
' >>>>>>>>>>>>and now all the gosub LED sequences
pron:
low portb.1 'display power on LED sequence
pause 75
low portb.2
pause 75
high portb.1
pause 75
high portb.2
pause 75
return
'
cpyc: 'start copy completed LED sequence
low portb.1
pause 250
low portb.2
pause 250
high portb.1
pause 250
high portb.2
pause 250
return
'
eled: 'start error LED sequence
low portb.1
low portb.2
pause 1000
HIGH portb.1
HIGH portb.2
pause 1000
return
'
twol:
IF portb.0 = 1 THEN thrl 'checking for second of two buttons
goto comd 'at startup
'
thrl: 'custom sequence starts here
low portb.1 'start LED sequence for early command
'
'
I2CWRITE portb.4,portb.5,164,62,["T"],eror 'EDIT SOME CUSTOM CODE HERE
pause 20
I2CWRITE portb.4,portb.5,164,61,["U"],eror
pause 20
I2CWRITE portb.4,portb.5,164,60,["R"],eror
pause 20
'
'
I2CWRITE portb.4,portb.5,164,150,["T"],eror 'AND HERE
pause 20
I2CWRITE portb.4,portb.5,164,149,["U"],eror
pause 20
I2CWRITE portb.4,portb.5,164,148,["R"],eror
pause 20
'
'
gosub cpyc 'goto the LED sequence
gosub cpyc
'
end
Bookmarks