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

Use Data EEprom In 18F452?

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







Use Data EEprom In 18F452?
PostPosted: Mon Apr 15, 2002 11:36 pm     Reply with quote

I'm using version 3.084 PCH Compiler .
The code dosen't work in 18f452 with write_eeprom() .

Data EEprom Write:
AdLp = 0;
while(AdLp < 4)
{
write_eeprom(AdLp,AdLp);
delay_ms(5);
AdLp++;
}
Data EEprom Read:
AdLp = 0;
while(AdLp < 4)
{
eedata_c = read_eeprom(AdLp);
printf("\r\n\%2d",eedata_c);
delay_ms(5);
AdLp++;
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 3812
gelly
Guest







Re: Use Data EEprom In 18F452?
PostPosted: Tue Apr 16, 2002 11:57 am     Reply with quote

the same problem here !
The code that PCH compiles in 18f452 with ;

-write_eeprom()
-read_eeprom()*
-write_program_eeprom()
-read_program_eeprom

does not work !

*sometimes reads sometimes not ?!? can't get a grip onn it.


spent time checking my programmer, but programmer
works fine.

filling data eeprom with pch works well
with command #rom 0x....... = {data,data,data....}

ps: this all with compiler v3.078 till 3.084

___________________________
This message was ported from CCS's old forum
Original Post ID: 3820
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: Use Data EEprom In 18F452?
PostPosted: Wed Apr 17, 2002 9:00 am     Reply with quote

<font face="Courier New" size=-1>Check your listing file. You will notice that there is no code listed for the write or read. I would suggest that you write your own routines and use as little of the built in functions as possible. Here are some routines to help you out


#define EEADR 0xFA9
#define EEDATA 0xFA8
#define EECON1 0xFA6
#define RD 0
#define WR 1
#define WREN 2
#define WRERR 3
#define FREE 4
#define CFGS 6
#define EEPGD 7

#define EECON2 0xFA7
#define PIR2 0xFA1
#define EEIF 4

void writeeeprom(int address, int data)
{

bit_clear(*PIR2, EEIF); // Make sure that the int flag is cleared
(int)*EEADR = address; // Load our address
(int)*EEDATA = data; // Load our data
bit_clear(*EECON1, EEPGD); // Point to data memory
bit_set(*EECON1, WREN); // Enable writes


// Microchip recommends disabling ints here
disable_interrupts(GLOBAL);
(int)*EECON2 = 0x55; // Write 0x55
(int)*EECON2 = 0xAA; // Write 0xAA
bit_set(*EECON1, WR); // Set WR to begin write

// Ok to turn back on ints
enable_interrupts(GLOBAL);

// Wait for the write to complete
while (!bit_test(*PIR2, EEIF));
bit_clear(*EECON1, WREN); // disable writes

}

int readeeprom(int address)
{
(int)*EEADR = address; // Load our address
bit_clear(*EECON1, EEPGD); // Point to data memory
bit_set(*EECON1, RD); // EEPROM Read
return(*EEDATA); // Return with our value
}

Notice that the Global ints will be enabled after you call the writeeeprom routine. If this is a problem, then change the routine to check the status first (INTCON register, bit 7) and only set this bit if it was set before.

Mark

:=I'm using version 3.084 PCH Compiler .
:=The code dosen't work in 18f452 with write_eeprom() .
:=
:=Data EEprom Write:
:= AdLp = 0;
:= while(AdLp < 4)
:= {
:= write_eeprom(AdLp,AdLp);
:= delay_ms(5);
:= AdLp++;
:= }
:=Data EEprom Read:
:= AdLp = 0;
:= while(AdLp < 4)
:= {
:= eedata_c = read_eeprom(AdLp);
:= printf("\r\n\%2d",eedata_c);
:= delay_ms(5);
:= AdLp++;
:= } ___________________________
This message was ported from CCS's old forum
Original Post ID: 3839
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: Use Data EEprom In 18F452?
PostPosted: Wed Apr 17, 2002 12:17 pm     Reply with quote

:=I'm using version 3.084 PCH Compiler .
:=The code dosen't work in 18f452 with write_eeprom() .
:=
:=Data EEprom Write:
:= AdLp = 0;
:= while(AdLp < 4)
:= {
:= write_eeprom(AdLp,AdLp);
:= delay_ms(5);
:= AdLp++;
:= }
:=Data EEprom Read:
:= AdLp = 0;
:= while(AdLp < 4)
:= {
:= eedata_c = read_eeprom(AdLp);
:= printf("\r\n\%2d",eedata_c);
:= delay_ms(5);
:= AdLp++;
:= }
___________________________
This message was ported from CCS's old forum
Original Post ID: 3856
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