|
|
View previous topic :: View next topic |
Author |
Message |
boraciner
Joined: 29 Jul 2009 Posts: 9
|
problem: storing int16 address data into eeprom (int8) ???? |
Posted: Wed Jul 29, 2009 1:01 am |
|
|
Hi! I need to store my address data at the "0" location of my external eeprom. If "anahtar" --> means switch is 0 then go on to store char data which is came from keyboard() function.
If anahtar=1 start send the stored characters via serial port.
Thanks. ??
my code is below: but It didn't worked ?? =((
Code: | #include "D:\ccs\dene.h"
#include "d:\ccs\keyboard.c"
#define EEPROM_SDA PIN_A2
#define EEPROM_SCL PIN_A3
#include "24256.c"
#use i2c(master, sda=PIN_A2, scl=PIN_A3)
unsigned char k;
long int i,j;
void EEPROM_write(int address,int16 data);
int16 EEPROM_read(int address);
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
Set_Tris_B(0b00111000);
init_ext_eeprom();
// TODO: USER CODE!!
delay_ms(500); //let the system to stabilize
i=2;
printf("Program Basliyor..");
for(;;)
{
if(!Anahtar){
i=EEPROM_read(0);
k=keyboard();
write_ext_eeprom(i,k);
i++;
EEPROM_write(0,i);
printf("%c",k);
}
else{
j=2;
i=EEPROM_read(0);
EEPROM_write(0,j);
for(j=2;j<=i;j++)
{
k=read_ext_eeprom(j);
printf("%c",k);
}
}
}}
void EEPROM_write(int address,int16 data) { //Sub to write a long value to the EEPROM
int i; //i is a loop counter; address is the eeprom offset address
for (i = 0; i < 2; i++) //Set up loop to write the two address with the data
write_ext_eeprom (i + address, *(&data +i)); //Write data to the eeprom using the address point to by &data + 1
}
int16 EEPROM_read(int address) { //Sub to read a int16 value from the EEPROM
int i; //i is a loop counter; address is the eeprom address that has the data to read
int16 data; //the value at the eeprom address
for (i = 0; i < 2; i++) //Set up loop to read the two address with the data
*(&data + 1) = read_ext_eeprom (i + address); //put the data from the eeprom in the address pointed to by &data
return(data); //Return the data to the calling sub
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 29, 2009 1:24 am |
|
|
There are routines to read and write an int16 to external eeprom
in this file:
Quote: | c:\program files\picc\drivers\external_eeprom.c |
For the 24LC256, you need to use a 16-bit address variable, so
define it before you include the file. Example:
Code: |
#define EEPROM_ADDRESS int16
#include <external_eeprom.c> |
Use those routines instead of yours. You will get better results. |
|
|
boraciner
Joined: 29 Jul 2009 Posts: 9
|
|
Posted: Wed Jul 29, 2009 1:40 am |
|
|
ok! Thanks a lot , I solved it 1-2 mins ago, by
dividing int16 to int8 and int8 then I wrote these 2 variable in 2 serial location.
When I want to come together these 2 variables, I read orderly than make it ;) !
Thanks a lot for your info. I didn't know that lib. |
|
|
|
|
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
|