eepromda int16 yı in8 lik yere kaydetmek

Başlatan boraciner, 29 Temmuz 2009, 09:29:08

boraciner

merhaba , ben int16 lık address verisini int8 lik boşluğa koymak istiyorum.
anahtar 0 'da kaldığı sürece en son kaldığı yerden yazmaya devam etmesini,
1 e geçtiği zaman yazdığı verileri seri porttan göndermensini istiyorum fakat başaramadım. kodlarım aşağıda yazılı . Teşekkürler..
#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 
}