Need help with write function
Yes, I have RTFD and still don't quite understand how to do it. In the PBP manual, it says that you can do something like:
Write 0, Brakes
Write 1, Lights
Then, you can read them by doing this:
Read 0, Brakes
Read 1, Lights
But according to the 16F688 datasheet, it says that the memory register is different and has to be accesed through the EECON1, EECON2........and I am not sure how to set up the code to write.
Can someone help me with the write function please?
Thanks,
Chris
Feeling as an apprentice among these guys (and girls) allow me to add the followings
Hi Chris,
EEPROM is already a reserved word.
So in your code, you should be using a different name for EEPROM subroutine, say WriteRom.
Code:
EEPROM 0,[0,0]
'This will write 0 to EEPROM location 0
'and 0 to EEPROM location 1.
'works only during the programming of PIC
'Not each time PIC powers up
Beep var byte
Flash var byte
Gosub readrom
'Since EEPROM locations 0 and 1 have known values now,
'we can read and store them.
'This will be done each time PIC powers up.
'So each time PIC powers up we will get the last saved values.
Start:
if portb.4=1 then
beep=beep+1
gosub WriteRom 'We Write the new value into EEPROM.
gosub ReadRom 'Then we read it right away and store it.
if beep=1 then high portb.0
endif
if portb.3=1 then
flash=flash+1
gosub WriteRom 'We Write the new value into EEPROM.
gosub ReadRom 'Then we read it right away and store it.
if flash=2 then high portb.1
endif
goto start
WriteRom:
write 0, beep 'Takes approx. 10mSec to complete.
pause 15
write 1, flash
pause 15
return
ReadRom:
read 0, beep 'Reading is almost instantenous
read 1, flash
return
end
- In your code, when will you "low" the ports after you pull them high?
- Pulling the ports high is(are) inside the IF statements; are not they supposed to be outside the IF statements but inside the main loop?
-----------------------------------------------