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 support@ccsinfo.com

write/read eeprom

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







write/read eeprom
PostPosted: Sat Jul 03, 2004 11:58 am     Reply with quote

I am new in pic18f458 mcu. Now i learn how to use eeprom. I try to write code as show below. but the result is the data in each address that show is the the data that write finally.
Code:
#include <18f458.h>
#fuses HS,NOPROTECT,NOWDT,NOCPD,WRTD
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <input.c>

main() {
      byte  data,address,new_dat;
      write_eeprom(0x00,0x41);
      write_eeprom(0x01,0x50);
      write_eeprom(0x02,0x55);
      printf("\rdata in eeprom at 0x00: %x \n\r",read_eeprom(0x00));
      printf("\rdata in eeprom at 0x01: %x \r\n",read_eeprom(0x01));
      printf("\rdata in eeprom at 0x02: %x \r\n",read_eeprom(0x02));
   }


The result is
data in eeprom at 0x00: 55
data in eeprom at 0x01: 55
data in eeprom at 0x02: 55

pcm programmer or anyone,could you suggest me why? And how can i force it? Thank you in advance. Surprised
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jul 03, 2004 1:08 pm     Reply with quote

Ideally, you shouldn't ask a question to me by name because
I might not be available or I might not know the answer, and
then others might be too shy to reply your post.

But to get to your question:

The first thing I noticed was WRTD in the #fuses statement.
If you check the data sheet, this fuse is in bit 7 of the CONFIG6H
register. If you then look at the at end of the .LST file generated
for your program, you see that the CCS WRTD fuse causes this
bit to be set = 0. According to the data sheet, this will Write Protect
the Data EEPROM. So if it was previously filled with 0x55 (perhaps
due to running a previous test program ?), then your code that
writes to EEPROM will not work. That's what you're seeing.

You should do these two things:
1. Remove the WRTD fuse.
2. Add a while(1); statement at the end of your program, to
prevent the program from falling off the end of main().
CCS puts a hidden Sleep instruction there, which, if it's executed,
will cause the PIC to shut down before the last two chars are
transmitted from your hardware USART. (ie., the \n and \r chars)
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