View previous topic :: View next topic |
Author |
Message |
serching
Joined: 06 Apr 2004 Posts: 9
|
problem in write and read eeprom |
Posted: Thu Apr 29, 2004 3:35 am |
|
|
I met the problem in read and write internal eeprom. Below is my code:
#include <18F452.H>
#fuses HS,WDT128
#use delay(clock = 10000000)
#OPT 9
#define DB9Xmit pin_E1
#define DB9Rcv pin_E2
#use rs232(baud = 9600, xmit = DB9Xmit, rcv=DB9Rcv) //DB9
#include <stdio.h>
#include <string.h>
main()
{
restart_wdt();
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTs(NO_ANALOGS);
write_eeprom(0,'0');
write_eeprom(1,'1');
write_eeprom(2,'2');
putc(read_eeprom(0));
putc(read_eeprom(1));
putc(read_eeprom(2));
}
Why after execute i found the result is the last character i write.
Result:
222
|
|
|
RD Guest
|
|
Posted: Thu Apr 29, 2004 4:17 am |
|
|
Try setting the fuses for EEPROM protection off |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Thu Apr 29, 2004 5:29 pm |
|
|
Never let your code reach the end of main(). Because some compiler versions put a SLEEP instruction there which may make you miss some of the outputs. Add this code:
Quote: | while(1)
restart_wdt(); |
at the end of the main() function and see if it helps. |
|
|
serching
Joined: 06 Apr 2004 Posts: 9
|
|
Posted: Thu Apr 29, 2004 7:45 pm |
|
|
Ok i will try for it. Thank you. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Thu Apr 29, 2004 8:20 pm |
|
|
Actually some other compiler versions do not use SLEEP, they just generate an endless loop at the end of main(). Since you have watchdog enabled, this will cause the PIC to reset every couple of seconds. |
|
|
|