|
|
View previous topic :: View next topic |
Author |
Message |
pasini
Joined: 12 Dec 2005 Posts: 50 Location: Curitiba - Brazil
|
PIC16F913 + EEPROM (internal) |
Posted: Mon Nov 17, 2008 7:00 pm |
|
|
MPLAB 8.10 + CCS3.223 + PIC16F913
Hi, I am trying to read/write data from the internal eeprom of the PIC but I have no success. I cannot read or write anything. But if I initialize data with #rom directive, it works.
My code is (interrupts are not shown / not important):
Code: |
#include <16F913.H>
#fuses LP, NOPROTECT, NOBROWNOUT, PUT, NOWDT, NOCPD
#use delay(clock=32768)
#include <stdio.h>
#include <stdlib.h>
#IF defined (__PCM__)
#rom 0x2100={9,2,3,4}
#elif defined(__PCH__)
#rom int 0xf00000={8,2,3,4}
#endif
void main()
{
int32 temp;
int8 h0,h1,h2;
while(!OSTS); // clock is running from proper oscillator
while(SCS); // clock must be running from external oscillator
ANSEL = 0x00; // all digital
set_tris_a(0xFF);
h0 = read_eeprom(1);
h1 = read_eeprom(2);
h2 = read_eeprom(3);
if((h0 == 0xFF) && (h1 == 0xFF) && (h2 == 0xFF))
hora = 0;
else
hora = h2 * 65536 + h1 * 256 + h0;
Inicializa();
Zera();
set_timer1(64680); //31,25ms = 1/32s
T1CON = 0b10001111; // pre-scaler=1:1
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(1)
{
while(atual==0)
{ if(deb)
lcd_symbol(0xFF, P3);
if(hora<10000) // 9999
{
temp = (int32)hora*10+(int32)min/6;
temp=read_eeprom(0x00);
printf(lcd_putc,"\f%05u",temp);
lcd_symbol(0xFF, P2);
write_eeprom(0x00,temp++);
}
else
{
printf(lcd_putc,"\f%05lu",hora);
lcd_symbol(0x00, P2);
}
atual = 1;
}
Go2Sleep();
}
}
|
How can I read/write data to the internal eeprom ?
Thanks in advance,
Luiz |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Nov 18, 2008 3:11 am |
|
|
Quite a few people seem to make this mistake.
Your EEPROM is at 0x2100 or 0xf00000
You need to use these addresses within the read_eeprom routines, it does not start your eeprom code at 0 as you have assumed.
h0 = read_eeprom(0xF00000); |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Nov 18, 2008 10:23 am |
|
|
It has just been pointed out to me that I am actually wrong on this point.
Looking at the help
"address is a (8 bit or 16 bit depending on the part) int, the range is device dependent
value is an 8 bit int"
This would mean that when I am specifying an address of 0xF00000 that the function write_eeprom truncates this to 0x0000. This means that the base address is actually 0. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 18, 2008 1:50 pm |
|
|
If a basic feature doesn't work, then make a simple test program to
test it. Also, restore everything to a "baseline" level. For example,
you are using LP mode at 32.768 KHz. Possibly that could cause a
problem. We don't know for sure. So, run a test at a more normal
frequency. The 16F913-16F917 series have an internal oscillator.
Use it for this test. Here's an example:
Code: | #include <16F913.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=8000000) |
This post has a short test program for the internal eeprom:
http://www.ccsinfo.com/forum/viewtopic.php?t=17590&start=1 |
|
|
Ttelmah Guest
|
|
Posted: Wed Nov 19, 2008 4:24 am |
|
|
Some 'obvious' comments do apply. The base address for the #rom statement on a 16 chip, is 2100, not F00000, so the comment in the original post that " if I initialize data with #rom directive, it works", is itself suspect...
The values read will not be the expected figures.
The location is in section 5.3.2 of the programming manual.
Remember when using the internal functions, that the values start at address '0', not '1', so that if you were initialising the memory correctly, you would expect 2,3,4, for H0 to H2.
Best Wishes |
|
|
|
|
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
|