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

I2c Using 2416EEprom and 16C57

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



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

I2c Using 2416EEprom and 16C57
PostPosted: Mon Aug 07, 2006 2:35 pm     Reply with quote

I am trying to write a simple program to store and retrieve a byte of data to address 1 on an 24LC16B EEprom using a PIC16C57. The idea is to write the value 9 to the EEPROM reset value to 0. Then read the the EEPROM to see if the value read is 9. My simple code is below.

I do have pullups on the SDA and SCL lines.

The program gets into a loop when it does the initial write.

I also have a memory problem that I describe after the code listing below.

Code:
//  ---------------------   I2C   ---------------------------------------


#include <16C57.h>
#device *=8,
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=40000000)

#define EEPROM_SDA  PIN_B6
#define EEPROM_SCL  PIN_B7
#include <2416.c>

long int   address;
byte   value;


/* Prototypes */
void main();         /* Main Routine */


void write_eeprom()
{
   BYTE value;
   EEPROM_ADDRESS address;
   init_ext_eeprom();
   WRITE_EXT_EEPROM( address, value );
}

void read_eeprom()
{
   BYTE value;
   EEPROM_ADDRESS address;
   init_ext_eeprom();
   value = READ_EXT_EEPROM( address );
}

void main()
{
   while (1==1)
   {
         address = 1;
         value = 9;
         write_eeprom();
         value = 0;
         read_eeprom();   
//         value = 8;
//         write_eeprom();   
//         value = 0;
//         read_eeprom();
   }
}




I planned on doing this again with the value of 8 but of I unremark the the last four lines I get the following when I compile the simple program:

    Error[71] C:\A_TEST\I2C.C 54 : Out of ROM, A segment or the program is too large main
    Seg 00000-001FF, 0125 left, need 01ED
    0000
    Seg 00200-003FF, 0200 left, need 0206
    0000
    Seg 00400-005FF, 0200 left, need 0206
    0000
    Seg 00600-007FF, 0200 left, need 0206
    0000
    Seg 00000-001FF, 0125 left, need 0206
    0000

    1 Errors, 0 Warnings.



With the last four lines remarked out I get the following when it is compiled:


    ROM used: 991 words (48%)
    Largest free fragment is 512
    RAM used: 25 (35%) at main() level
    34 (47%) worst case
    Stack: 1 locations



I am not sure why I use up so much memory with 4 commands?


Any input would be greatfully accepted.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 07, 2006 2:52 pm     Reply with quote

You have set the clock speed to 40 MHz. Max speed allowed is 20 MHz.
This setting must match your crystal value.


This PIC has only 2 stack levels. Sherpa Doug would be the one
with experience in writing CCS code for this type of PIC.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Aug 07, 2006 2:55 pm     Reply with quote

Your code could be longer than you might expect because it also includes 2416.c. You are declaring 'address' and 'value' as global variables and then RE-declare them as local variables inside read_eeprom() and write_eeprom(). Either use Only the global variables and have each function and main() use them or declare them inside of main() and then pass the variables to each function.

Ronald
edbfmi1



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PostPosted: Mon Aug 07, 2006 3:05 pm     Reply with quote

I got a little carried away with the "0" it should have been 4Mhz Embarassed
I also made the variables global for this simple program but still no luck Sad

Thanks for the input.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 07, 2006 3:11 pm     Reply with quote

How do you tell if the program is working ? Are you using an ICE ?
edbfmi1



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PostPosted: Mon Aug 07, 2006 3:20 pm     Reply with quote

Yes I am using MPLAB v5.7 with the Picmaster in curcuit emulator to watch the values of the registers.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 07, 2006 3:49 pm     Reply with quote

Have you run a very simple program (without EEPROM access) so that
you can prove that the ICE is working ?
Guest








PostPosted: Mon Aug 07, 2006 4:05 pm     Reply with quote

Yes,
I have used the ICE to debug a portion of the program that this will be incorporated with. The program multiplexes a 4 digit 7-segment display. All works fine with that part of the program. I removed it for simplicty while I write the next part of the program that stores the data displayed in the EEPROM. I just re-ran the display program again to verify the ICE is working and it worked fine.
edbfmi1



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PostPosted: Mon Aug 07, 2006 4:08 pm     Reply with quote

OOPs,

The "guest" reply above was from me. I just got on line at home and forgot to log in before I replied.
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