free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems
ajay i have tried like everything i can think of.. i even increased delay to 50ms n delays bw scl n sda transitions... i tried to write one byte at a time but still no success.. i will post some of my routines, plz c if u can find any anomaly.... it runs fine on proteus simulator.... can it be a possibilty that eeprom is faulty ????
CODE:
void stop(); void Ack(); void Nak(); void rstart(); unsignedchar arr[32];
main() { for(i=0;i<32;i++)arr[i]=97+i;
mem_rwmany(2,0xa0,0x00);// writes 2 pages to eeprom
mem_seqrdlcdwr(2,0xa0,0x00);// reads 2 pages n displays on lcd
}
void rstart()// high to low transition of data bus while clock is high {
scl=0;
sda=1;
scl=1;
sda=0;
scl=0; }
void stop()// low to high transition of data bus while clock is high {
scl=0;
sda=0;
scl=1;
sda=1;
scl=0; }
void Ack()// generates ack {
scl=0;
sda =0;// should be 0
scl =1;
scl =0;
sda=1;// has to be pulled high again.... }
void mem_rwmany(unsignedchar pages,unsignedchar d_add,unsignedchar m_add) // pagewrites 16 bytes to no of pages { unsignedchar i,page_count;
dev_addw=d_add;
mem_addw=m_add;
for(i=0;i<pages;i++,page_count++)// to write all pages*16 (max 2048) locations { if(page_count==16){ dev_addw+=2; page_count=0;}// after every 16*16=256 locations , dev_add inc by 2 to point to nxt block
mem_datawr();// write 16 bytes of arr as pagewrite to eeprom }
arr_count=0;
}
void mem_datawr()// starts the sequence of writing data to eeprom { char i;
rstart();
mem_write(dev_addw);// load dev_add into eeprom //if(sda!=0)lcddata('1');
mem_write(mem_addw); for(i=0;i<16;i++,mem_addw++) mem_write(arr[arr_count++]);// writes contents of arr[16] to eeprom using pagewrite
stop();
delay(3); }
void mem_write(unsignedchar value) { char j;
bitchar=value; for(j=0;j<8;j++) {
scl=0;// to clock in data
sda=msbc;
scl=1;
bitchar=bitchar<<1; }
scl=0;// to receive ack from eeprom
scl=1;
scl=0;
delay(3);
}
void mem_seqrdlcdwr(unsignedchar pages,unsignedchar d_add,unsignedchar m_add) // reads seq 32 bytes from eeprom n writes to LCD till no of pages... { char i,j,page_count=0;
mem_addr=m_add;// for read operation 1st set mem_add=0 so as to refer to 0000 mem location
dev_addr=d_add;// dev_add=A0 as 1st dummy write operation to be performed
matrix=0x0F;
for(i=0;i<(pages/2);i++,page_count++)// to read all (pages/2)*32 (max 64*32 = 2048) locations { if(on_button==0){lcdclr(); lcdstring("terminating read"); delay(50);break;}
lcdclr(); if(page_count==8){ dev_addr+=2; page_count=0;}// after every 8*32=256 locations , dev_add inc by 2 to point to nxt block
mem_seqdatard();// read 16 bytes of eeprom into arr_rd[32] as sequential read
for(j=0;j<32;j++){lcddata(arr[j]); arr[j]=0;}// output 32 bytes of arr_rd to LCD, to clr read array parallely
delay(100);
} }
void mem_seqdatard()// to read 32 bytes of data using random + seq read { unsignedchar i;
rstart();
mem_write(dev_addr);// load in dev add
mem_write(mem_addr);// load in mem add
rstart();
mem_write(dev_addr+1);// load in mem add +1 to indicate read operation from dat mem location
for(i=0;i<32;i++) {
arr[i]=mem_read();// read 32 bytes in arr_rd if(i<31)Ack();// ack till 31 bytes else Nak();// nak at the 32nd byte }
stop();
mem_addr+=32;// inc mem_add by 32 as 32 bytes have been read
delay(5);
}
unsignedchar mem_read()// reads a char from eeprom n returns it { char i;
bitchar=0;
scl=0;
for(i=0;i<8;i++) {
bitchar=bitchar<<1;
scl=1;// to clock out data at -ve transition
scl=0;
lsbc=sda;
i have included all other function declarations n other needed things... above code is most of the major code.... mem_write() is used to write one byte to eeprom mem_read() return one byte from eeprom
did you check the functions separately? are they working fine?
check on proteus if you have. see if there is any wrong transistion.
always write codes in small functional format. www.rickeyworld.info If you feel satisfied with the user's forum reply please click on the thank button.
ajay i have checked the codes one by one n then joined them 2gether... the program works perfect in proteus.. i get desired read write opertations to eeprom.. but it doesnt work in real life project.. i have a development kit uni51sdk.... it has 24c16 eeprom on board... i simulated the whole kit circuit on proteus n it works fine, but on the kit it doesnt.. somehow i think byte is not being written to eeprom..... plz help me, i dont know y it is not workin... it worked well on proteus...
solved the problem after a lot of debugging.. phewwww,,,, :mad !dance
first i tried to locate whr the problem, after lots of debuggin it apeared dat data was being written properly but not read properly though... but i cudnt find problem at first coz it was a weird one....
the problem was in mem_read() function... i dont how but earlier it worked well in proteus but not in real project... then i tried some changes in the function n then it worked in both proteus n real project..... earlier mem_read() was---
unsigned char mem_read() // reads a char from eeprom n returns it { char i; bitchar=0; scl=0;
for(i=0;i<8;i++) { bitchar=bitchar<<1; scl=1; // to clock out data at -ve transition scl=0; lsbc=sda;
}
return bitchar; }
i changed it to ----------------------------------
unsigned char mem_read() // reads a char from eeprom n returns it { char i; bitchar=0;
for(i=0;i<8;i++) { bitchar=bitchar<<1; scl=0; // to clock out data at -ve transition delay(1); scl=1; lsbc=sda;
}
return bitchar; }
and the program worked both in proteus n real project... i think it was due to clock transitions of scl... in data sheet it was written data is clocked out on the following edge of scl, so i started with scl=1; scl=0; in loop.. but when i changed it to scl=0; delay(1); scl=1; it worked !dance
atlast my eeprom interfacing is finished............ :-) :-)
thank u guys really for helping n being der for me... just 'thanked' all those who helped.... :bye :-) !dance
Good tweety bird. I am thinking to donate a project on 8051 with a interface of at24c256, ds1307 & smard card. I am in the middle of the project. I named it as "RF ID based attendence system" Never cry in front of others........... Don't give them the pleasure of knowing how much they hurt you.
Contact Ajay Bhargav by PM or email at contact@8051projects.net
Anonymous | 17 Mar : 12:46
anyone knows who can I get in contact with to get permission to use this http://www.8051projects.net/lcd-interfacing/lcd.png for my senior design report?
Correction... http://www.8051projects.net/lcd-interfacing/lcd-4-bit-programming.php That gave me headaches... Mismatched coding between the 4-bit and 8-bit sections.
8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems