karthickiw
Joined: 09 Aug 2007 Posts: 82 Location: TN, India
|
problem in write and read the eeprom |
Posted: Sat Sep 01, 2007 11:19 am |
|
|
i write the program for count the number 0 to 9999 and also store that number in to the eeprom. but i face the problem when switch off and on the circuit. count don't resume from ending number... pls check the program and give the correct solution..
Code: | #include<16f873a.h>
#device adc=8
#include<math.h>
#use delay(clock=4000000)
#fuses NOWDT,XT, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#byte port_b=6
int CONST LED_MAP[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
long int d1,d2,d3,d4;
void display(long int v)
{
d1=v/1000; //separate three digits
d2=(v-1000*d1)/100;
d3=(v-1000*d1-100*d2)/10;
d4=(v-1000*d1-100*d2-10*d3);
output_high(pin_c4);
port_b= LED_MAP[d1];
delay_ms(5);
output_low(pin_c4);
output_high(pin_c5);
port_b= LED_MAP[d2];
delay_ms(5);
output_low(pin_c5);
output_high(pin_c6);
port_b= LED_MAP[d3];
delay_ms(5);
output_low(pin_c6);
output_high(pin_c7);
port_b= LED_MAP[d4];
delay_ms(5);
output_low(pin_c7);
}
unsigned long READ_LONG_INT_EEPROM(long int n)
{
int i;
long int data;
for (i = 0; i < 2; i++)
*(&data + i) = read_eeprom(i + n);
return(data);
}
void WRITE_LONG_INT_EEPROM(long int n, long int data)
{
int i;
restart_wdt();
for (i = 0; i < 2; i++)
{
write_eeprom(i + n, *(&data + i) ) ;
}
}
void main()
{
long int s,ch;
int i;
set_tris_b(0);
loop:
ch=READ_LONG_INT_EEPROM(0);
if(ch>=9999)
{
WRITE_LONG_INT_EEPROM(0, 0);
}
s=READ_LONG_INT_EEPROM(0);
s=s+1;
for(i=0;i<=1;i++)
{
display(s);
}
WRITE_LONG_INT_EEPROM(0,s);
goto loop;
}
|
|
|