CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problem in write and read eeprom

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
serching



Joined: 06 Apr 2004
Posts: 9

View user's profile Send private message

problem in write and read eeprom
PostPosted: Thu Apr 29, 2004 3:35 am     Reply with quote

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
Rolling Eyes
RD
Guest







PostPosted: Thu Apr 29, 2004 4:17 am     Reply with quote

Try setting the fuses for EEPROM protection off Question
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu Apr 29, 2004 5:29 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 29, 2004 7:45 pm     Reply with quote

Ok i will try for it. Thank you. Laughing
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu Apr 29, 2004 8:20 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group