|
|
View previous topic :: View next topic |
Author |
Message |
kuosda Guest
|
Use Data EEprom In 18F452? |
Posted: Mon Apr 15, 2002 11:36 pm |
|
|
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? |
Posted: Tue Apr 16, 2002 11:57 am |
|
|
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
|
Re: Use Data EEprom In 18F452? |
Posted: Wed Apr 17, 2002 9:00 am |
|
|
<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
|
Re: Use Data EEprom In 18F452? |
Posted: Wed Apr 17, 2002 12:17 pm |
|
|
:=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 |
|
|
|
|
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
|