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

problem in write and read the eeprom

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



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

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

problem in write and read the eeprom
PostPosted: Sat Sep 01, 2007 11:19 am     Reply with quote

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;

}


PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 01, 2007 11:34 am     Reply with quote

Quote:
*(&data + i) = read_eeprom(i + n);

write_eeprom(i + n, *(&data + i) ) ;


See these posts:
http://www.ccsinfo.com/forum/viewtopic.php?t=31783
http://www.ccsinfo.com/forum/viewtopic.php?t=30461
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