??? 04/04/07 06:37 Read: times Msg Score: +1 +1 Good Question |
#136550 - How To Write the Data to EEPROM (Seial) |
Hello Every body,
The situation is little bit confusing, (Because i am now stucked on IIC), well i am working with AT89C2051 and AT24C04 and as i am new to IIC so i am stucked badly, :-( Well i have readed Essential Reading about the IIC and the AT24C04, and i have codded a program, and the program is working just fine in Simulator, well i am using Keil-C51-V3 (eval ver), and i have anyalised that the waveforms of the SCK and SDA are just fine, but i dont know that why the MCu is not writing the Data to EEPROM, Well i Playing with Port-1 to ensure that data writtend successfully, :-) so i think that no need to worry, So any help will be Appritiatable, (Although i have nice experiance of posting in 8052 :-) ) Well here is the Link of the Image of the Wave form Caught from KEIL, ![]() (The Red Mark In wave Shows the Condition when Data Written Successfully) Well the problem is that i the Port-1 (P1) is not becomming 00h, and Held to FFh which is default, and according to me if the Data Writing is in success then P1 should become 00h, i think it is very straight forward ORG 0000H LJMP MAIN ORG 0030H SCK EQU P3.5 SDA EQU P3.4 TST EQU P3.7 DYTA EQU 30H ADDRE EQU 31H MAIN: SETB TST ;Setting TST button MOV P1,#0FFH ;Setting all bits of P1 to high CLR A ;Clearing the variables MOV R7,A ;Clearing the Counter R7 MOV ADDRE,A ;Moving Address 00h to ADDRE MOV DYTA,A ;Moving Data Location 30h to 00h MOV ADDRE,#00000000B ;Want to write the Byte to 00h of EEPROM MOV DYTA,#11110000B ;Wand to write F0h to 00h Location of EEPROM LCALL WRITE ;Calling the Write Routine MOV P1,#000H ;Clearing the P1 to confirm data written Succesfully AGAIN: JB TST,$ ;Wait until the TST button to Ground JNB TST,$ ;Wait untill button released MOV ADDRE,#00000000B ;Setting the Address 00h for reading LCALL READ ;Calling the Read Routine MOV A,DYTA ;Copy the DYTA to ACC MOV P1,A ;Mov the ACC to P1 SJMP AGAIN ;Do it again ;=============================================== ;==============SUBROUTINES====================== ;=============================================== WRITE: LCALL IIC_START ;IIC Start Routine MOV A,#10100000B ;Moving the Address of Slave to Acc with Write LCALL CLOCK_D ;Clock the Acc to SDA and SCK LCALL ACK ;Wait for Acknowledge MOV A,ADDRE ;Mov the Address LCALL CLOCK_D ;Clock the Address of EEPROM LCALL ACK ;Wait for Acknowledge MOV A,DYTA ;Mov the Data LCALL CLOCK_D ;Clock the Data LCALL ACK ;Wait for Acknowledge LCALL IIC_STOP ;IIC Stop Routine LCALL DELAY ;Simple Delay Routine RET READ: LCALL IIC_START ;IIC Start Routine MOV A,#10100000B ;Moving the Address of Slave to Acc with Write LCALL CLOCK_D ;Clock the Acc to SDA and SCK LCALL ACK ;Wait for Acknowledge MOV A,ADDRE ;Mov the Address LCALL CLOCK_D ;Clock the Address of EEPROM LCALL ACK ;Wait for Acknowledge LCALL IIC_START ;Again IIC Start Routine MOV A,#10100001B ;Moving the Address of Slave to Acc with Read LCALL CLOCK_D ;Clock the Acc to SDA and SCK LCALL ACK ;Wait for Acknowledge LCALL I2C_READ ;Read the Data with SDA and SCK LCALL NO_ACK ;No Acknowledge Condition LCALL IIC_STOP ;IIC Stop Routine RET NO_ACK: SETB SDA CLR SCK JNB SDA,$ SETB SCK RET ACK: SETB SDA SETB SCK JB SDA,$ ;Wait for Acknowledge CLR SCK RET I2C_READ: MOV R7,#8 GFD: SETB SDA SETB SCK MOV C,SDA RLC A CLR SCK DJNZ R7,GFD MOV DYTA,A RET RET CLOCK_D: RLC A MOV R7,#8 LOOP: MOV SDA,C SETB SCK CLR SCK RLC A DJNZ R7,LOOP RET DELAY: MOV R7,#8 DJNZ R7,$ RET IIC_STOP: CLR SDA SETB SCK SETB SCK SETB SDA RET IIC_START: SETB SCK SETB SDA CLR SDA CLR SCK RET DELAY_STOP: MOV TMOD,#00000001B MOV TH0,#0EEH MOV TL0,#00H SETB TR0 SAC: JNB TF0,SAC CLR TR0 CLR TF0 RET END |