Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/04/07 14:37
Read: times


 
#136596 - Even the NOPs and delay wont working
Responding to: ???'s previous message
Well sir i thought that it was the problem of timing but sir i have introduced some NOPs to my Code but still not working,,, well sir the new code with NOPs is it

			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
			NOP
			CLR SCK
			DJNZ R7,GFD
			MOV DYTA,A
			RET

			RET
CLOCK_D:	RLC A
			MOV R7,#8

LOOP:		MOV SDA,C
			SETB SCK
			NOP
			CLR SCK
			RLC A
			DJNZ R7,LOOP
			RET

IIC_STOP:	CLR SDA
			NOP
			SETB SCK
			NOP
			SETB SDA
			NOP
			RET

IIC_START:	SETB SCK
			NOP
			SETB SDA
			NOP
			CLR SDA	
			NOP
			CLR SCK
			RET
			
DELAY:		MOV R7,#250
AGN:		MOV R6,#250
HRE:		NOP
			NOP
			DJNZ R6,HRE
			DJNZ R7,AGN
			RET

DELAY_STOP:	MOV TMOD,#00000001B
			MOV TH0,#0EEH 
			MOV TL0,#00H
			SETB TR0
SAC:		JNB TF0,SAC
			CLR TR0
			CLR TF0
			RET

			END


List of 74 messages in thread
TopicAuthorDate
How To Write the Data to EEPROM (Seial)            01/01/70 00:00      
   Slow the i2c clock            01/01/70 00:00      
      Well i am using 12 MHz with 8051            01/01/70 00:00      
         Speed            01/01/70 00:00      
         this is upon you to determine            01/01/70 00:00      
   the poor developer's "logic analyzer"....            01/01/70 00:00      
   What happens in the real hardware?            01/01/70 00:00      
      writing IS broken - but in several ways            01/01/70 00:00      
         I I Sir, i will use spaces for next, :-)            01/01/70 00:00      
            delay for write plus the real error            01/01/70 00:00      
      Sir i'v used P1 to see that data is written or not            01/01/70 00:00      
         Order of magnitude!            01/01/70 00:00      
         is it 100kHz or 1000kHz?            01/01/70 00:00      
      I dont have osciloscop :-(            01/01/70 00:00      
   In real world the P1 is High,            01/01/70 00:00      
   Code Comments            01/01/70 00:00      
      again "I I SIR", well sir i have got your Point,            01/01/70 00:00      
         to Asif (and others)            01/01/70 00:00      
   I2C Part number ...            01/01/70 00:00      
   Even the NOPs and delay wont working            01/01/70 00:00      
   I have Codded this in C,But still not working :-(            01/01/70 00:00      
      not a good idea            01/01/70 00:00      
      Asif,s C Code for I2C            01/01/70 00:00      
         You missed the point            01/01/70 00:00      
            Point taken            01/01/70 00:00      
   are you sure they are IIC, not SMB            01/01/70 00:00      
      To be very Honest i dont know tha its IIC or SMB            01/01/70 00:00      
         try this            01/01/70 00:00      
   Have you looked here?            01/01/70 00:00      
      Working code...            01/01/70 00:00      
         advice to Asif            01/01/70 00:00      
            i know that i dont have to Copy Paste,, :-)            01/01/70 00:00      
               WoW i have EEPROM Programmer,            01/01/70 00:00      
                  is it working at all?            01/01/70 00:00      
            What about the A0, A1... pins on the 24C04            01/01/70 00:00      
   Well sir Here are Comparision of C and ASM(My Way)            01/01/70 00:00      
      I few I2C questions            01/01/70 00:00      
         it is not uncommon to list IIC addresses this way,            01/01/70 00:00      
            I was askin for schematics...            01/01/70 00:00      
               Here is the Schematics,            01/01/70 00:00      
                  Pardon??            01/01/70 00:00      
                     Well sir it means this ckt is Dummy            01/01/70 00:00      
                        OK            01/01/70 00:00      
                           Well i am straight forward programmer :-)            01/01/70 00:00      
                           Well the Hardware Circuit is Exactly same as it.            01/01/70 00:00      
                              Not at all!            01/01/70 00:00      
                     Recheck it Sir i have added labels, :-)            01/01/70 00:00      
                        but            01/01/70 00:00      
                        and blinkey?            01/01/70 00:00      
                           It really worked :-) MCu is stucked at ACK            01/01/70 00:00      
                              Stuck at ACK            01/01/70 00:00      
                              Stuck in no ACK            01/01/70 00:00      
                                 Sorry i havent understood, forgive my dumbness            01/01/70 00:00      
                                    Stuck in ACK (Reminds me of work)            01/01/70 00:00      
                                    Still Stuck?            01/01/70 00:00      
                                       Sir i am gonna use the Acknowledge polling tech:-)            01/01/70 00:00      
                                          one note            01/01/70 00:00      
                                             Nice note:-) but it Clocking was wrong,            01/01/70 00:00      
                                       Sir i am gonna use the Acknowledge polling tech:-)            01/01/70 00:00      
   Here is working Code, :-)            01/01/70 00:00      
      for your benefit and others            01/01/70 00:00      
         Havent Gotten your Idea ?            01/01/70 00:00      
            The idea is            01/01/70 00:00      
               WoW i have Gotten the IDEA , thanks            01/01/70 00:00      
   The Problem Solved Successfully,Thanks everybody            01/01/70 00:00      
      You have the code working now            01/01/70 00:00      
         Thanks David            01/01/70 00:00      
         Partially agree            01/01/70 00:00      
            100% agreed            01/01/70 00:00      
            I was rying to help !!            01/01/70 00:00      
               true and untrue            01/01/70 00:00      
                  C Loops are not Perfect, agreed            01/01/70 00:00      
                  C timing loops            01/01/70 00:00      
                     then don't call it C            01/01/70 00:00      

Back to Subject List