??? 05/15/09 06:57 Read: times |
#165365 - Dear stefan and david Responding to: ???'s previous message |
I know you guys are going the right way but i still have doubts asto what i should do. As stefan gave me the code, i used it ditto as it was given, but i can read only 80, 80, 80 in all the registers.
I will ask one more thing. as stefan pointed ourt that i have 15 pulses and i too have checked that i have 15 pulses instead of the 16 shown in the datasheet. BUT, in the datasheet, on page 8 in the last two lines, it is written that "The first data bit to be transmitted at the first falling edge after the last last bit of command is written". So this would mean that the adress will be transmitted on the first 8 low to high transformations and then we will recieve the data from the HT1380 in the ery next 8 high to low pulses. Now in the picture that i have attached, the first is what my old code looks like and the second picture is what my wave will look like if i use stefan's function. This is what's confusing me.....not that my loop is working ...it's still not..... pleasee give me your email so that i can send the IMAGE showing both the waveforms.... //******************************************************************* //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); } |