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 CCS Technical Support

Store large integer to I2C eeprom 24lc32

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



Joined: 22 Apr 2010
Posts: 6
Location: UK

View user's profile Send private message

Store large integer to I2C eeprom 24lc32
PostPosted: Thu Apr 22, 2010 2:56 am     Reply with quote

Hello everyone,

I am using PIC 18lf4550, 24LC32 EEprom, Compiler CCS C V:4.013

I have built an electronic counter with the above hardware. Every time a switch is activated the counter increment by one. At the same time the count variable is stored to eeprom (24LC32) as the circuit gets power down and power up often. After power up the electronic counter the count variable is read from eeprom and continues to be incremented when the switch is activated, and the process repeats.The count variable is displayed to the LCD. My count variable needs to be a positive number up to 100000. Therefore I have declared the count as a unsigned long int.
I can write to the I2C eeprom and read from it except that I can only write one byte and then rolls over.

How can I split my count variable into two or more bytes and store them to different addresses and then read them re-assembled them and display them to LCD?

Here is my code:
Code:

unsigned long int count;
unsigned long int eeprom;
long int addr;
addr=5;
.........
 while(1)
    {
output_high(PIN_E0);                                             
delay_ms(20);                                                   
eeprom = read_ext_eeprom(addr);   
dt_lcd_gotoxy(0,7);                                                         
 printf(dt_lcd_printchar,"EEprom:\%lu",eeprom);                                         
printf(dt_lcd_printchar,"Add:\%lu",addr);                     
if(!input(PIN_C0))                                                     
  {
      count = count +1;               
     dt_lcd_gotoxy(0,1)
     printf(dt_lcd_printchar,"Fixture count:\%lu     ",count);                   
     output_low(PIN_E0);                                                 
     delay_ms(40);                                         
     write_ext_eeprom(addr, count);   
     delay_ms(10);                                              // Delay 10ms
     eeprom = read_ext_eeprom(addr);                                             
     dt_lcd_gotoxy(0,7);                                                      
    printf(dt_lcd_printchar,"EEprom:\%lu   ",eeprom);         
          }
         reset();
}

I am using the eeprom 2432.c driver from CCS C directory.
Please help!!!
Any sugestions are welcome.
_________________
test
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 22, 2010 1:28 pm     Reply with quote

Quote:

My count variable needs to be a positive number up to 100000. Therefore
I have declared the count as a unsigned long int.

That won't work. In CCS, an unsigned long int is 65535 max (0xFFFF).
You need to declare it as 'int32'.

Look in this CCS driver file. It has routines to read and write an 'int32' to
external eeprom:
Quote:

c:\program files\picc\drivers\external_eeprom.c
marken



Joined: 22 Apr 2010
Posts: 6
Location: UK

View user's profile Send private message

It works with the new driver!!
PostPosted: Tue Apr 27, 2010 7:10 am     Reply with quote

Thanks PCM Programmer, I have followed your advice and it work perfect.
Thank you for your time.
_________________
test
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