

//******************************************************************* 
//FUNCTION THAT SENDS ADDRESS OR DATA_IO AFTER CONVERTING IT TO BITS 
//******************************************************************* 
void convert_and_send(unsigned char hex_data1) 
{ 
bit sending_bit; 
unsigned char comparing_byte=0x01; 
unsigned char i; 
unsigned char storing_byte=0x00; 
SBUF=hex_data1; 
usec_wait(5); 

for(i=0;i<8;i++) 
{ 
storing_byte=(hex_data1&comparing_byte); 
if(storing_byte==0x00) 
sending_bit=0; 
else 
sending_bit=1; 
 
SCLK=0; 
DATA_IO = sending_bit; //Clock to DATA_IO delay is 250ns (max) 
comparing_byte=comparing_byte<<1; 
SCLK=1;	//data entered on rising edge !!!
SCLK=1;	//added zzzzzzzzz
} 

DATA_IO=1; //Making the pin of the MCU as an input pin		
SCLK=0; //**At this high to low transition, we would recieve the LSB of the data that we want to read as from the DATASHEET page 8 last 2 lines

serial_storage=0x00; 
usec_wait(2); 
} 

//************************************************************************************** 
//FUNCTION THAT RECEIVES DATA AND THEN CONVERTS IT TO CHARACTER AND PASSES TO ITS CALLER 
//************************************************************************************** 
unsigned char receive_convert(void) 
{ 

bit receiving_bit; 
unsigned char comparing_byte=0x00; 
unsigned char i=0; 
unsigned char received_data=0x00; 

for(i=0;i<8;i++) 
{ 
SCLK=0; 
SCLK=0; //added zzzz  DATA outputed on FALLING edge 

receiving_bit=DATA_IO;

if(receiving_bit==0) 
comparing_byte=0x00; 
else 
comparing_byte=0x80; //comparing byte is 10000000 as the bit is to be placesd in the MSB position 
received_data=received_data>>1; 
received_data=received_data|comparing_byte; 
SCLK=1;
SCLK=1;
} 
SCLK=0; // the SCLK is lowered once the loop is complete
SCLK=0;
DATA_IO=0; // the data pin is again made normal
return(received_data); 
} 
