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

need help!! on 24lc256 EEPROM

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







need help!! on 24lc256 EEPROM
PostPosted: Tue Apr 20, 2004 5:41 pm     Reply with quote

I am using a 24lc256 eeprom, can someone tell me how to declare the address for write_ext_eeprom() and read_ext_eeprom() functions; ex:

write_ext_eeprom(1, 9);
a = read_ext_eeprom(1);

is this able to work???

thanks for the help!!

/////////////////////// MY PREVIOUS POSTING ////////////////////////////
hi! i am trying to get my fisrt eeprom program work. my LCD and Keypad sections are working ok, but after i added an eeprom program, i could not get it through, it has stuck on writing to the eeprom.

in 24256.c program i make few changes:
#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3
i also added pull-up 2.2k resistors on both pins.

here is my program:

#define(__PCM__)
#include <16f877a.h>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6, rcv=PIN_C7, errors)
#include "lcdd.c"
#include "kbdb.c"
#include "24256.c"

main()
{
char k,a;
init_ext_eeprom();
lcd_init();
kbd_init();
lcd_putc("\fReady 05 !\n");

while (True)
{
k=kbd_getc();

if (k!=0)
{ lcd_putc('k');
lcd_putc(k);
if (k=='*')
lcd_putc('\f');
else
{
lcd_putc('y');
lcd_putc(k); <------ i can see the ouput from LCD here
write_ext_eeprom(1, 9);
a = read_ext_eeprom(1);
lcd_putc('p'); <---- but never reach the ouput "p" on the LCD
and the program stops
lcd_putc(a);
}
}
}
}

please help! thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 20, 2004 5:59 pm     Reply with quote

I think you should find the exact line of source code in the
24256.C file that is causing the program to lock-up.

If you have ICD2, you could use breakpoints to find
the line of code.

If you don't have ICD2 or another debugger, then you
could put a lcd_putc() statement between each line of
code in a suspected routine. Example:

Code:

   lcd_putc('A');
i2c_start();
   lcd_putc('B');
i2c_write(0xa0);
   lcd_putc('C');
i2c_write(address>>8);
   lcd_putc('D');
i2c_write(address);
   lcd_putc('E');

etc.


Then look at your LCD to find where the program stopped.
For example, if you see this: AB
Then it is stuck on this line: i2c_write(0xa0);

After you find the line of code that is causing the problem,
post the routine and show us the line.

---------------
Note: Make sure that you use the single quote marks around the
characters. Use this: 'A' Do not use double quotes: "A"
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Apr 20, 2004 6:24 pm     Reply with quote

I had exactly the same problem yesterday, my code got stuck on writing to 24256. It turned out that my pull-up resistor on the SCL line was not making proper connection. Make sure you have pull-ups on both SCL and SDA lines, and they are connected properly.
Mk
Guest







PostPosted: Tue Apr 20, 2004 11:51 pm     Reply with quote

Thanks the help!!!!
i found the problem! first of all, many thanks to PCM programmer and Haplo.

i did use PCM's method to debug my codes and the program returned the key word, and i tried the suggestion from Haplo to check my connections, finally, i found my ground bus on the breadboard didn't connect to power supply..MMMmmmmy GOD!!!!. how can i make such mistake#@#%!... it took me two days to find out. anyway, now i am so happy my fisrt eeprom program is working~ i can move on to next step....

thanks again!!!
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Apr 21, 2004 12:19 am     Reply with quote

Yeah, I've done this one too. Once I forgot to connect one ground row of my breadboard to the power supply. The two ground pins of PIC16F870 were making the only ground path between two rows. After powering up the board I noticed my VCC dropped from 5.0v to 4.6v immediately, and kept dropping slowly afterwards until it reached 4.0v where almost everything stopped working. I was impressed that the PIC didn't smoke.
Guest








PostPosted: Wed Apr 21, 2004 11:45 am     Reply with quote

i have the other question, now i try to locate a data from an eeprom address, if i do like below i can retrieve the data from the eeprom address:
write_ext_eeprom(1, 9);
a = read_ext_eeprom(1);

but if i assign a variable:
char k,a;
k=kbd_getc();
a = read_ext_eeprom(k);
lcd_putc(a);

from keypad input i enter: 1
but lcd didn't show 9, i found the eeprom address is "Long int" data type,
so i tried to convert "char" data type into "long int" data type by using:

long int j;
char a,k;

k=kbd_getc();
j=k;

a = read_ext_eeprom(j);
lcd_putc(a);

but this way didn't work either, so my question is how to convert a "char" data type into "long int" data type?

thanks!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 21, 2004 9:33 pm     Reply with quote

Quote:
From keypad input I enter: 1


Your assumption is that the keypad driver is returning
binary numbers: 1, 2, 3, 4, etc.

But it doesn't do that. It returns ASCII numbers.
'1', '2', '3', '4', etc.

The hex code for these numbers is:
0x31, 0x32, 0x33, 0x34, etc.

To convert an ASCII digit from '0' to '9' to binary,
you need to subtract the ASCII bias value of 0x30.
Then you get 0, 1, 2, 3, etc.

Here is the table in the CCS driver file, KBD.C, which
determines the values that are returned by the keypad
driver. You can see that they are all ASCII values.
Code:
char const KEYS[4][3] = {{'1','2','3'},
                         {'4','5','6'},
                         {'7','8','9'},
                         {'*','0','#'}};

The main idea to learn here, is to always be aware of
the format of the values returned by a device driver.
If it seems to return strange values, then look at the
source code for the device driver, to see what it's doing.
Mk
Guest







PostPosted: Wed Apr 21, 2004 11:25 pm     Reply with quote

thank you PCM programmer, my program is working again>>> Razz
MK
Guest







PostPosted: Wed Apr 21, 2004 11:57 pm     Reply with quote

can someone give me a direction or example, how to create a look up table and store in eeprom?

ex.

address ------------ Data 1(name) ------------ Data 2 (score)
-------------------------------------------------------------------------
0001----------------- Mike Corson ------------------ 62
0002 ---------------- John Greene ------------------ 95
- - -
- - -
9999---------------- Richard Campbell------------- 100


thanks!!
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