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

Write & Read 24LC256

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







Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 8:20 am     Reply with quote

Hello everyone.
this is my first attempt to write & read to a serial emprom
using <24256.c>
the program works ok if i am storing bytes but ican't get my head around how to store 16 bits of data
could anyone be kind enough in giving a helping hand?

Sorry i am still learning C .I have always being a Picbasic man
and now i have finally decided to pack it in with picbasic and concentrate on learning Pic C

Thanks in Advance

Isaac



// This program is used to store twenty 16bits values
// into a 24lc256 eprom .then read the data stored and display them
// on an lcd

#if defined(__PCM__)
#include <16F877.H>
#device ADC=10
#include <stdlib.h>
#include <stdio.h>


#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)

#byte port_b=6
#byte port_c=7
#byte port_d=8

#include <lcd.c>
#include <24256.C>


main()
{

int address;
int16 Data_in,Data_out;


init_ext_eeprom();
lcd_init(); // initiate lcd
delay_ms(1000); // Delay 1 sec for lcd startup
Data_in = 1000; // initial value of Data_in

for (address=0;address < 20; address++)
{
printf(lcd_putc,"\f Storing \n");
printf(lcd_putc," Data:");
printf(lcd_putc," \%lu ",Data_in); // see data to be stored
write_ext_eeprom(address,Data_in ); // store data_in
delay_ms(500);
Data_in = Data_in +1000;
}
/////////////////////////////////////////////////////////////////////////
// In the for loop above i can see that Data_in is correct as this
// is displayed as 1000,2000, etc to 20,000
// its the storing part thats the problem
/////////////////////////////////////////////////////////////////////////

delay_ms(1000);

for (address=0;address<20;address++)
{
Data_out = read_ext_eeprom(address); // Raed Eprom data into Data-out
printf(lcd_putc,"\f Reading \n");
printf(lcd_putc," Addr: \%u",address);
printf(lcd_putc," \%lu ",Data_out);
delay_ms(1000);
}

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517220
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

Re: Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 9:54 am     Reply with quote

:=Hello everyone.
:=this is my first attempt to write & read to a serial emprom
:=using <24256.c>
:=the program works ok if i am storing bytes but ican't get my head around how to store 16 bits of data
:=could anyone be kind enough in giving a helping hand?
:=
:=Sorry i am still learning C .I have always being a Picbasic man
:=and now i have finally decided to pack it in with picbasic and concentrate on learning Pic C
:=
:=Thanks in Advance
:=
:=Isaac
:=
:=
:=
:=// This program is used to store twenty 16bits values
:=// into a 24lc256 eprom .then read the data stored and display them
:=// on an lcd
:=
:=#if defined(__PCM__)
:=#include <16F877.H>
:=#device ADC=10
:=#include <stdlib.h>
:=#include <stdio.h>
:=
:=
:=#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
:=#use delay(clock=20000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
:=
:=#byte port_b=6
:=#byte port_c=7
:=#byte port_d=8
:=
:=#include <lcd.c>
:=#include <24256.C>
:=
:=
:=main()
:={
:=
:= int address;
:= int16 Data_in,Data_out;
:=
:=
:= init_ext_eeprom();
:= lcd_init(); // initiate lcd
:= delay_ms(1000); // Delay 1 sec for lcd startup
:= Data_in = 1000; // initial value of Data_in
:=
:= for (address=0;address < 20; address++)
:= {
:= printf(lcd_putc,"\f Storing \n");
:= printf(lcd_putc," Data:");
:= printf(lcd_putc," \%lu ",Data_in); // see data to be stored
:= write_ext_eeprom(address,Data_in ); // store data_in
:= delay_ms(500);
:= Data_in = Data_in +1000;
:= }
:= /////////////////////////////////////////////////////////////////////////
:= // In the for loop above i can see that Data_in is correct as this
:= // is displayed as 1000,2000, etc to 20,000
:= // its the storing part thats the problem
:= /////////////////////////////////////////////////////////////////////////
:=
:= delay_ms(1000);
:=
:= for (address=0;address<20;address++)
:= {
:= Data_out = read_ext_eeprom(address); // Raed Eprom data into Data-out
:= printf(lcd_putc,"\f Reading \n");
:= printf(lcd_putc," Addr: \%u",address);
:= printf(lcd_putc," \%lu ",Data_out);
:= delay_ms(1000);
:= }
:=
:=}

Look in the manual under MAKE8(..) it will extract the 8 bit bytes out of the 16bit variable. Make16 will assemble two 8 bit bytes into a long for you. There are number of other ways to do this but they may be a bit too technical for you at this stage.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517221
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

Re: Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 10:16 am     Reply with quote

<font face="Courier New" size=-1>the 'make8' function as suggested is not a standard C function. The goal is to store 2 8bit numbers. There are a number of ways of doing this. Here is one solution. Note the casts are not realy needed but put there for completeness.

Mark

:=Hello everyone.
:=this is my first attempt to write & read to a serial emprom
:=using <24256.c>
:=the program works ok if i am storing bytes but ican't get my head around how to store 16 bits of data
:=could anyone be kind enough in giving a helping hand?
:=
:=Sorry i am still learning C .I have always being a Picbasic man
:=and now i have finally decided to pack it in with picbasic and concentrate on learning Pic C
:=
:=Thanks in Advance
:=
:=Isaac
:=
:=
:=
:=// This program is used to store twenty 16bits values
:=// into a 24lc256 eprom .then read the data stored and display them
:=// on an lcd
:=
:=#if defined(__PCM__)
:=#include <16F877.H>
:=#device ADC=10
:=#include <stdlib.h>
:=#include <stdio.h>
:=
:=
:=#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
:=#use delay(clock=20000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
:=
:=#byte port_b=6
:=#byte port_c=7
:=#byte port_d=8
:=
:=#include <lcd.c>
:=#include <24256.C>
:=
:=
:=main()
:={
:=
:= int address;
:= int16 Data_in,Data_out;
:=
:=
:= init_ext_eeprom();
:= lcd_init(); // initiate lcd
:= delay_ms(1000); // Delay 1 sec for lcd startup
:= Data_in = 1000; // initial value of Data_in
:=
for (address=0;address < 40; address+=2)
:= {
:= printf(lcd_putc,"\f Storing \n");
:= printf(lcd_putc," Data:");
:= printf(lcd_putc," \%lu ",Data_in); // see data to be stored
write_ext_eeprom(address,(int8)Data_in ); // store data_in
write_ext_eeprom(address+1,(int8)(Data_in>>8)); //
:= delay_ms(500);
:= Data_in = Data_in +1000;
:= }
:= /////////////////////////////////////////////////////////////////////////
:= // In the for loop above i can see that Data_in is correct as this
:= // is displayed as 1000,2000, etc to 20,000
:= // its the storing part thats the problem
:= /////////////////////////////////////////////////////////////////////////
:=
:= delay_ms(1000);
:=
:= for (address=0;address<20;address++)
:= {
:= Data_out = read_ext_eeprom(address); // Raed Eprom data into Data-out
:= printf(lcd_putc,"\f Reading \n");
:= printf(lcd_putc," Addr: \%u",address);
:= printf(lcd_putc," \%lu ",Data_out);
:= delay_ms(1000);
:= }
:=
:=} ___________________________
This message was ported from CCS's old forum
Original Post ID: 144517225
ISAAC AIYANYO
Guest







Re: Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 10:51 am     Reply with quote

Thank you very much Mark & Douglas
for your support i am going to experiment with your suggestions
But there one thing i want to get my head round
With this way of storing data when i do want to read my eprom i would have to read 2 address at a time then combine the data
with say make16 before displaying on lcd
Is this right ?
i thought that ccs had in-built functions for those but i am wrong

Isaac
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517227
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

Re: Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 10:54 am     Reply with quote

:=<font face="Courier New" size=-1>the 'make8' function as suggested is not a standard C function. The goal is to store 2 8bit numbers. There are a number of ways of doing this. Here is one solution. Note the casts are not realy needed but put there for completeness.
:=
:=Mark
:=
:=:=Hello everyone.
:=:=this is my first attempt to write & read to a serial emprom
:=:=using <24256.c>
:=:=the program works ok if i am storing bytes but ican't get my head around how to store 16 bits of data
:=:=could anyone be kind enough in giving a helping hand?
:=:=
:=:=Sorry i am still learning C .I have always being a Picbasic man
:=:=and now i have finally decided to pack it in with picbasic and concentrate on learning Pic C
:=:=
:=:=Thanks in Advance
:=:=
:=:=Isaac
:=:=
:=:=
:=:=
:=:=// This program is used to store twenty 16bits values
:=:=// into a 24lc256 eprom .then read the data stored and display them
:=:=// on an lcd
:=:=
:=:=#if defined(__PCM__)
:=:=#include <16F877.H>
:=:=#device ADC=10
:=:=#include <stdlib.h>
:=:=#include <stdio.h>
:=:=
:=:=
:=:=#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
:=:=#use delay(clock=20000000)
:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
:=:=
:=:=#byte port_b=6
:=:=#byte port_c=7
:=:=#byte port_d=8
:=:=
:=:=#include <lcd.c>
:=:=#include <24256.C>
:=:=
:=:=
:=:=main()
:=:={
:=:=
:=:= int address;
:=:= int16 Data_in,Data_out;
:=:=
:=:=
:=:= init_ext_eeprom();
:=:= lcd_init(); // initiate lcd
:=:= delay_ms(1000); // Delay 1 sec for lcd startup
:=:= Data_in = 1000; // initial value of Data_in
:=:=
:= for (address=0;address < 40; address+=2)
:=:= {
:=:= printf(lcd_putc,"\f Storing \n");
:=:= printf(lcd_putc," Data:");
:=:= printf(lcd_putc," \%lu ",Data_in); // see data to be stored
:= write_ext_eeprom(address,(int8)Data_in ); // store data_in
:= write_ext_eeprom(address+1,(int8)(Data_in>>8)); //
:=:= delay_ms(500);
:=:= Data_in = Data_in +1000;
:=:= }
:=:= /////////////////////////////////////////////////////////////////////////
:=:= // In the for loop above i can see that Data_in is correct as this
:=:= // is displayed as 1000,2000, etc to 20,000
:=:= // its the storing part thats the problem
:=:= /////////////////////////////////////////////////////////////////////////
:=:=
:=:= delay_ms(1000);
:=:=
:=:= for (address=0;address<20;address++)
:=:= {
:=:= Data_out = read_ext_eeprom(address); // Raed Eprom data into Data-out
:=:= printf(lcd_putc,"\f Reading \n");
:=:= printf(lcd_putc," Addr: \%u",address);
:=:= printf(lcd_putc," \%lu ",Data_out);
:=:= delay_ms(1000);
:=:= }
:=:=
:=:=}
Oops Mark I didn't realize that only standard C is acceptable on this board. Now if Printf(lcd_putc,"....) isn't standard C and delay_ms etc and #byte portx=n isn't aren't you now conflicted unless you suggest alternatives to those also.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517228
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

Re: Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 11:36 am     Reply with quote

:=Thank you very much Mark & Douglas
:= for your support i am going to experiment with your suggestions
:= But there one thing i want to get my head round
:= With this way of storing data when i do want to read my eprom i would have to read 2 address at a time then combine the data
:= with say make16 before displaying on lcd
:= Is this right ?
:= i thought that ccs had in-built functions for those but i am wrong
:=
:=Isaac
The simple answer is yes. The eeprom is a byte at time process.
You have your data in 16bit format so you need to break it down
via ( I'm almost scared to mention it ) the CCS built in function MAKE8 and stuff it in the eeprom on retrieveal you need to assemble back into 16 bits via MAKE16. Also, you could modify the eeprom read write routines to accept and return 16 bit values or you could take a pristine view and rip out every helpful CCS function to gain portablity through out the universe.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517230
ISAAC AIYANYO
Guest







Re: Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 11:53 am     Reply with quote

Guys PLLLLLLLLLEASE !!
Don't fallout over this as i would be the loser here
You both know your stuff and both of you are only trying to help.
There are more than one way to skin a cat

Isaac
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517233
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

Re: Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 1:39 pm     Reply with quote

Nope smarta$$! Note that was in his code already. He said that he was learning C and I wanted to make it clear that the suggestion wasn't a standard C function. My suggestion also makes it a little clearer how the data is stored.

:=:=<font face="Courier New" size=-1>the 'make8' function as suggested is not a standard C function. The goal is to store 2 8bit numbers. There are a number of ways of doing this. Here is one solution. Note the casts are not realy needed but put there for completeness.
:=:=
:=:=Mark
:=:=
:=:=:=Hello everyone.
:=:=:=this is my first attempt to write & read to a serial emprom
:=:=:=using <24256.c>
:=:=:=the program works ok if i am storing bytes but ican't get my head around how to store 16 bits of data
:=:=:=could anyone be kind enough in giving a helping hand?
:=:=:=
:=:=:=Sorry i am still learning C .I have always being a Picbasic man
:=:=:=and now i have finally decided to pack it in with picbasic and concentrate on learning Pic C
:=:=:=
:=:=:=Thanks in Advance
:=:=:=
:=:=:=Isaac
:=:=:=
:=:=:=
:=:=:=
:=:=:=// This program is used to store twenty 16bits values
:=:=:=// into a 24lc256 eprom .then read the data stored and display them
:=:=:=// on an lcd
:=:=:=
:=:=:=#if defined(__PCM__)
:=:=:=#include <16F877.H>
:=:=:=#device ADC=10
:=:=:=#include <stdlib.h>
:=:=:=#include <stdio.h>
:=:=:=
:=:=:=
:=:=:=#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
:=:=:=#use delay(clock=20000000)
:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
:=:=:=
:=:=:=#byte port_b=6
:=:=:=#byte port_c=7
:=:=:=#byte port_d=8
:=:=:=
:=:=:=#include <lcd.c>
:=:=:=#include <24256.C>
:=:=:=
:=:=:=
:=:=:=main()
:=:=:={
:=:=:=
:=:=:= int address;
:=:=:= int16 Data_in,Data_out;
:=:=:=
:=:=:=
:=:=:= init_ext_eeprom();
:=:=:= lcd_init(); // initiate lcd
:=:=:= delay_ms(1000); // Delay 1 sec for lcd startup
:=:=:= Data_in = 1000; // initial value of Data_in
:=:=:=
:=:= for (address=0;address < 40; address+=2)
:=:=:= {
:=:=:= printf(lcd_putc,"\f Storing \n");
:=:=:= printf(lcd_putc," Data:");
:=:=:= printf(lcd_putc," \%lu ",Data_in); // see data to be stored
:=:= write_ext_eeprom(address,(int8)Data_in ); // store data_in
:=:= write_ext_eeprom(address+1,(int8)(Data_in>>8)); //
:=:=:= delay_ms(500);
:=:=:= Data_in = Data_in +1000;
:=:=:= }
:=:=:= /////////////////////////////////////////////////////////////////////////
:=:=:= // In the for loop above i can see that Data_in is correct as this
:=:=:= // is displayed as 1000,2000, etc to 20,000
:=:=:= // its the storing part thats the problem
:=:=:= /////////////////////////////////////////////////////////////////////////
:=:=:=
:=:=:= delay_ms(1000);
:=:=:=
:=:=:= for (address=0;address<20;address++)
:=:=:= {
:=:=:= Data_out = read_ext_eeprom(address); // Raed Eprom data into Data-out
:=:=:= printf(lcd_putc,"\f Reading \n");
:=:=:= printf(lcd_putc," Addr: \%u",address);
:=:=:= printf(lcd_putc," \%lu ",Data_out);
:=:=:= delay_ms(1000);
:=:=:= }
:=:=:=
:=:=:=} :=
:=Oops Mark I didn't realize that only standard C is acceptable on this board. Now if Printf(lcd_putc,"....) isn't standard C and delay_ms etc and #byte portx=n isn't aren't you now conflicted unless you suggest alternatives to those also.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517238
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

Re: Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 1:42 pm     Reply with quote

This one works on Mars :)

UINT16 Read_SEEPROM16bits(
UINT16 address) // EEPROM address to write data
{
union
{
struct
{
UINT8 lowbyte;
UINT8 highbyte;
};
UINT16 word;
}data;

// Get the data from the eeprom
data.lowbyte = Read_SEEPROM(address);
address++;
data.highbyte = Read_SEEPROM(address);

return (data.word);
}


:=:=Thank you very much Mark & Douglas
:=:= for your support i am going to experiment with your suggestions
:=:= But there one thing i want to get my head round
:=:= With this way of storing data when i do want to read my eprom i would have to read 2 address at a time then combine the data
:=:= with say make16 before displaying on lcd
:=:= Is this right ?
:=:= i thought that ccs had in-built functions for those but i am wrong
:=:=
:=:=Isaac
:=The simple answer is yes. The eeprom is a byte at time process.
:=You have your data in 16bit format so you need to break it down
:=via ( I'm almost scared to mention it ) the CCS built in function MAKE8 and stuff it in the eeprom on retrieveal you need to assemble back into 16 bits via MAKE16. Also, you could modify the eeprom read write routines to accept and return 16 bit values or you could take a pristine view and rip out every helpful CCS function to gain portablity through out the universe.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517239
R.J.Hamlett
Guest







Re: Write & Read 24LC256
PostPosted: Mon Aug 25, 2003 3:01 pm     Reply with quote

:=Hello everyone.
:=this is my first attempt to write & read to a serial emprom
:=using <24256.c>
:=the program works ok if i am storing bytes but ican't get my head around how to store 16 bits of data
:=could anyone be kind enough in giving a helping hand?
:=
:=Sorry i am still learning C .I have always being a Picbasic man
:=and now i have finally decided to pack it in with picbasic and concentrate on learning Pic C
:=
:=Thanks in Advance
:=
:=Isaac
One method, which is very efficient (in terms of the code it produces), and doesn't use any 'non standard' 'C', is to use a union.

If you make a declaration:

union data {
int16 word;
int8 b[2];
}

Then declare the data you want to send as:

union data Data_Out;

Then:

Data_Out.word will refer to the 'whole' 16bit value, while Data_Out.b[0], and Data_Out.b[1], will refer to the individual bytes. This has the advantage of producing really nice small code, and being portable to any C.
Remember your 'address' in the code you give will have to move forward by two for each 'word'.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517241
ISAAC AIYANYO
Guest







Re: Write & Read 24LC256
PostPosted: Tue Aug 26, 2003 11:54 am     Reply with quote

Thanks for your reply R.J
i have being trying to figure out how union works and i am begining to understand but slowly
i used the union as below for my data

:=If you make a declaration:
union data_type
{
int16 word;
int8 split[2];
} Data_in;

Data_in.word =1000; // And the data i wish to send to eprom
// is this ok so far ?

Now would i have to implement my own write ext_eprom routine
or can i use the 24256.c ?
This is how i am doing the storing is this right?

//To store Data i used

for (address=0;address < 40; address+2)

{

write_ext_eeprom(address,Data_in.word );
delay_ms(500);
Data_in.word = (Data_in.word+1000);
}
//With address already declared as int16 address;

Thanks for the Help
Isaac
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517280
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

Re: Write & Read 24LC256
PostPosted: Tue Aug 26, 2003 1:29 pm     Reply with quote

Not quite right. See the corrections
:=
:= union data_type
:= {
:= int16 word;
int8 lowbyte;
int8 highbyte;
:= } Data_in;
:=
:= Data_in.word =1000; // And the data i wish to send to eprom
:= // is this ok so far ?
:=
:= Now would i have to implement my own write ext_eprom routine
:= or can i use the 24256.c ?
:= This is how i am doing the storing is this right?
:=
:= //To store Data i used
:=
:=for (address=0;address < 40; address+2)
:=
:= {
:=
write_ext_eeprom(address,Data_in.lowbyte );
write_ext_eeprom(address+1,Data_in.highbyte );
:= delay_ms(500);
:= Data_in.word = (Data_in.word+1000);
:= }
:=//With address already declared as int16 address;
:=
:= Thanks for the Help
:= Isaac
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517284
R.J.Hamlett
Guest







Re: Write & Read 24LC256
PostPosted: Tue Aug 26, 2003 3:11 pm     Reply with quote

:=
:=Thanks for your reply R.J
:=i have being trying to figure out how union works and i am begining to understand but slowly
:=i used the union as below for my data
:=
:=:=If you make a declaration:
:= union data_type
:= {
:= int16 word;
:= int8 split[2];
:= } Data_in;
:=
:= Data_in.word =1000; // And the data i wish to send to eprom
:= // is this ok so far ?
Yes. Personally, I'd put 1000l for the constant value. Though the current compiler now does seem to handle 'long' constants OK, it is safer to flag everything that is above 255 as a 'long' to make really sure... :-)

:= Now would i have to implement my own write ext_eprom routine
:= or can i use the 24256.c ?
:= This is how i am doing the storing is this right?
:=
:= //To store Data i used
:=
:=for (address=0;address < 40; address+2)
:=
:= {
:=
:= write_ext_eeprom(address,Data_in.word );
Change to:

write_ext_eeprom(address,Date_in.split[0]);
write_ext_eeprom(address+1,Data_in.split[1];

The union, allows you to 'split' the 16bit word, into the two 8 bit values needed to go to the EEPROM. :-)
You still have to send both halves.

:= delay_ms(500);
:= Data_in.word = (Data_in.word+1000);
:= }
:=//With address already declared as int16 address;
:=
:= Thanks for the Help
:= Isaac

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517288
ISAAC AIYANYO
Guest







Re: Write & Read 24LC256
PostPosted: Wed Aug 27, 2003 8:33 am     Reply with quote

Guys
Thanks for all the support you have given so far.
but i still need your help with the program
my program seems to crash after the lcd displays storing data
am i doing something wrong with the unions

Isaac


// This program is used to store twenty 16bits values
// into a 24lc256 eprom .then read the data stored and display them
// on an lcd

#if defined(__PCM__)
#include <16F877.H>
#device ADC=10
#include <stdlib.h>
#include <stdio.h>


#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)

#byte port_b=6
#byte port_c=7
#byte port_d=8

#include <INPUT.C>
#include <lcd.c>
#include <24256.C>


main()
{



int16 address;

union data_type
{
int16 word;
int8 split[2];
} Data_in;


union eprom

{
int16 full_part;
int8 low_part;
int8 high_part;
} data_out;





Data_in.word=500;

init_ext_eeprom();
lcd_init();
delay_ms(1000);

printf(lcd_putc,"\f Storing \n ");
printf(lcd_putc, " Data " );
delay_ms(30);

// my program doesn't get past this point
// i used the lcd as a debug and "Storing data is continously displayed
// on the screen

for (address=0;address < 40; address+2) //To Write Data to the eprom

{
write_ext_eeprom(address,(Data_in.split[0]));
write_ext_eeprom(address+1,(Data_in.split[1]));
delay_ms(500);
Data_in.word = (Data_in.word+2000);
}
//The program never gets here//

printf(lcd_putc,"\f Storage \n ");
printf(lcd_putc," Completed...." );
delay_ms(1000); // Allow time to see that data had being
// stored


for (address=0;address < 40; address+2) //To Read Data from the eprom

{
data_out.low_part =READ_EXT_EEPROM( address );
data_out.high_part =READ_EXT_EEPROM( address+1 );
delay_ms(500);
data_out.full_part=data_out.high_part,data_out.low_part;
printf(lcd_putc,"address: \%lu ",address);
printf(lcd_putc," \%lu ",data_out.full_part);

}

}

___________________________
This message was ported from CCS's old forum
Original Post ID: 144517319
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