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

External eeprom reading and writing

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



Joined: 09 Apr 2012
Posts: 19
Location: Salem

View user's profile Send private message

External eeprom reading and writing
PostPosted: Mon Jul 02, 2012 11:23 pm     Reply with quote

Hi,

I am using pic16f877a. I have to store a large amount of hours and minutes in memory. So I am planning to use external eeprom(24c64). I have checked the example program of external eeprom using Proteus. I used the 2464.c file for the external memory driver.

In Proteus, I have connected the microcontroller with 24c64 ic with wp,a0,a1,a2 shorted to ground. But the result is not as expected. I can't get the same write data when I read it from the same location (Proteus result). I have not checked in real time.

My ccs version is 4.074. My code is same as PCM programmer's code,
Code:

#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=4000000)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3

#include <2464.c>

//=====================================
void main()
{
   printf("Start\n\r");
   
   init_ext_eeprom();
   
   write_ext_eeprom(0, 55);
   delay_ms(10);
   write_ext_eeprom(2, 85);
   delay_ms(10);
   
   printf("%d  ", read_ext_eeprom(0));
   delay_ms(10);
   printf("%d", read_ext_eeprom(2));
   delay_ms(10);
   
   
   while(1);
}



I have used the following line in the 24c64.c .
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL, FORCE_HW)

The result is 111 and 43 for the program.

Please give me any suggestions to store and read the correct value from external eeprom.

Thanks
_________________
Embedding Innovation
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 1:08 am     Reply with quote

Obvious 'common question', with I2C. You _have_ got the pull-up resistors on SDA and SCL?. Typically 2K2R or similar value needed.
You'd not normally get the value you are seeing without these, but Proteus commonly gets things like this 'wrong' (the PIC simulator is cr%p).....

Best Wishes
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 6:31 am     Reply with quote

Are you saying you have TWO use I2C lines? One in the main code, as shown above, and in 2464.c? This may cause all sorts of problems and confusion. Only the last should have any effect, but that may not be the case. Only have ONE, in this case the best one to keep is the one in 2464.c, and remove the one in your main C file.

That's often the way a well written driver file works: it has all the code it needs to do its job, in this including the I2C stuff. All you need to do is point it to the IO ports you are using, by the defines.

RF Developer
varadharaj



Joined: 09 Apr 2012
Posts: 19
Location: Salem

View user's profile Send private message

Problem solved
PostPosted: Thu Jul 05, 2012 12:34 am     Reply with quote

Hi,


Thanks for the replies...

In real time it is working perfectly.. But in proteus, the results are bad. Why it is so?
_________________
Embedding Innovation
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

Re: Problem solved
PostPosted: Thu Jul 05, 2012 12:41 am     Reply with quote

varadharaj wrote:
Hi,


Thanks for the replies...

In real time it is working perfectly.. But in proteus, the results are bad. Why it is so?


Because proteus is an interpretation of complex hardware...

Everyone says proteus is to be avoided. Just build a proto and work real hardware.

Less headaches in the long run.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Jul 05, 2012 3:00 am     Reply with quote

Quote:
In real time it is working perfectly.. But in proteus, the results are bad. Why it is so?

Lesson #1. Forget Proteus. It's so full of bugs you're wasting valuable time trying to emulate a PIC with it.

Mike
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