Forum Replies Created
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
PICATAParticipant
The P3 value only showing the value which is in 0x00 word address (irrespective of word data)
I changed
unsigned char word_add[] = {0x00, 0x01};to
unsigned char word_add[] = {0x01, 0x00};
but the result same, data stored in 0x00 is showing only
I also checked it for 0x02, 0x08 address.
what was the problem? Please help me out.
PICATAParticipant<code>//Program to interface Serial EEPROM AT24C02 with 8051 microcontroller (AT89C51)#include <mcs51/at89x51.h>#define _nop_()__asmnop__endasm;#define SDA P2_4 //Pin 25#define SCL P2_3 //Pin 24// device_address 0xAE //device address/1010 xxx 0// device_address_read 0xAF //device address/1010 xxx 1// word_address 0x00 //word_address 0x00/00000 000//data_1 P3//data_2 P1__bit ack;void delaySeconds(unsigned char asec){unsigned char il,ms;int s=0;for(il=0;il<asec;il++){for(s=0;s<1000;s++){for(ms=0;ms<250;ms++){}}}}void aknowledge() //acknowledge condition{SCL=1;_nop_();_nop_();SCL=0;}void start() //start condition{SDA=1;SCL=1;_nop_(); //No operation_nop_();SDA=0;SCL=0;}void stop() //stop condition{SDA=0;SCL=1;_nop_();_nop_();SDA=1;SCL=0;}void send_byte(unsigned char value) //send byte serially{unsigned int ii;unsigned char send;send=value;for(ii=0;ii<8;ii++){SDA=send/128; //extracting MSBsend=send<<1; //shiftng leftSCL=1;_nop_();_nop_();SCL=0;}ack=SDA; //reading acknowledgeSDA=0;}unsigned char read_byte() //reading from EEPROM serially{unsigned int ii;unsigned char reead;SDA=1;reead=0;for(ii=0;ii<8;ii++){reead=reead<<1;SCL=1;_nop_();_nop_();if(SDA==1)reead++;SCL=0;}SDA=0;return reead; //Returns 8 bit data here}void save(unsigned char device_address_s, unsigned char word_address_s, unsigned char data_1_s) //save in EEPROM{start();send_byte(device_address_s); //device address/1010 xxx 0aknowledge();send_byte(word_address_s); //word_address 0x00 00000 000aknowledge();send_byte(data_1_s); //send dataaknowledge();stop();_nop_();_nop_();aknowledge();}unsigned char Read(unsigned char device_address_r, unsigned char device_address_read_r, unsigned char word_address_r){unsigned char data_1_r;start();send_byte(device_address_r);aknowledge();send_byte(word_address_r);aknowledge();start();send_byte(device_address_read_r); //device addressaknowledge();data_1_r=read_byte();aknowledge();stop();_nop_();_nop_();aknowledge();return data_1_r;}void main(){unsigned char dev_add_w, dev_add_r;unsigned char word_add[] = {0x00, 0x01};unsigned char data_store[] = {0x0CC, 0xAA};unsigned char data_chk[] = {0x00, 0x00};dev_add_w = 0xAE;dev_add_r = 0xAF;while(1){save(dev_add_w, word_add[0], data_store[0]);data_chk[0] = Read(dev_add_w, dev_add_r, word_add[0]);if (data_chk[0] == data_store[0]){P3 = data_chk[0];}delaySeconds(2);data_chk[0] = 0;save(dev_add_w, word_add[1], data_store[1]);data_chk[1] = Read(dev_add_w, dev_add_r, word_add[1]);if (data_chk[1] == data_store[1]){P3 = data_chk[1];}delaySeconds(2);data_chk[1] = 0;}}</code>compiled in MIDE 51At first i’m trying to do that for 11 numbers, but for debugging i reduced it to just this. the problem I’m facing is: most of the time the 7segment LED not displaying any thing, (sometime it shows properly, though very few times) all connections connectivity are OK.is the code OK? can you help me by running the code into your system?
Sorry for late reply, my exams are going onThank you very much
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)