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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/30/06 16:00
Read: times


 
#119444 - formatted code with comments.
Responding to: ???'s previous message
This should help you to help me resolve the problem.



;_________________________________________________________________
;--------------I2C BYTE WRITE SUBROUTINE--------------------------
;_________________________________________________________________ 


WRITE_iic:
   MOV A,WTCMD ; device address with write command
   CALL OUTS

   MOV A,ADDRS;location where byte is to be stored(word address)
   CALL OUT

   MOV A,I2C_IN ;byte to be written is temporaryly stored here(equated to 30h)
   CALL OUT

   CALL STOP
   ;MOV A,#0H
      
   RET

;_________________________________________________________________
;--------------I2C BYTE READ SUBROUTINE---------------------------
;_________________________________________________________________ 


READ_iic: 
      MOV A,WTCMD
      CALL OUTS

      MOV A,ADDRS
      LCALL OUT

      MOV A,RDCMD ; device address with read command
      LCALL OUTS

      LCALL IN
	
      MOV I2C_OUT,A ;read byte is temporaryly stored here(equated to 31h)

      LCALL STOP
      MOV A,#0H

      RET

;_________________________________________________________________
;-------------BITWISE WRITE WITH START CONDITION------------------
;_________________________________________________________________ 


OUTS: 
       	  MOV B,#8
          SETB SDA
          SETB SCL
          NOP
          CLR SDA
          NOP
          CLR SCL

OSLOOP:
          RLC A
          MOV SDA,C
          SETB SCL
          NOP
          CLR SCL
          DJNZ B,OSLOOP ;redo till whole byte is trasfered
          SETB SDA
          NOP
          SETB SCL
          NOP
          CLR SCL
          RET
;_________________________________________________________________
;------------BITWISE WRITE WITHOUT START CONDITION----------------
;_________________________________________________________________ 


OUT:
     	  MOV B,#8
OLOOP:
      	  RLC A
          MOV SDA,C
          SETB SCL
          NOP
          CLR SCL
          DJNZ B,OLOOP
          SETB SDA
          NOP
          SETB SCL
          NOP
          CLR SCL
          RET
;_________________________________________________________________
;------------------BITWISE READ SUBROUTINE------------------------
;_________________________________________________________________ 



IN:
       MOV A,#0  ;clear accumulator
       MOV B,#8
       SETB SDA
INLOOP:
       CLR SCL
       NOP
       SETB SCL
       MOV C,SDA
       RLC A
       DJNZ B,INLOOP
       CLR SCL
       RET
;_________________________________________________________________
;---------------------I2C STOP CONDITION--------------------------
;_________________________________________________________________ 



STOP:
      CLR SDA
      NOP
      SETB SCL
      NOP
      SETB SDA
      LCALL L_DELAY
      RET

;_________________________________________________________________
;----------------DELAY FOR I2C STOP CONDITION---------------------
;_________________________________________________________________ 



L_DELAY:
       push 07
       push 06
       push 05
       mov r5,#02h
two_dely_200ms1:
       mov r6,#19h
one_dely_200ms1:
	mov r7,#40h
back_200ms1:
        djnz r7,back_200ms1
	djnz r6, one_dely_200ms1
	djnz r5,two_dely_200ms1
	pop 05
	pop 06
	pop 07
	RET

;_________________________________________________________________ 
;--------------------------MAIN CODE------------------------------ 
;_________________________________________________________________ 



brw_main: 
     mov sp,#64h 
     ;mov p1,#0ffh 
     mov ie,#00h 
     acall s9k_main ;set baud rate to 9600


;_________________________________________________________________ 
;--------------------FULL WRITE SUBROUTINE------------------------ 
;_________________________________________________________________ 



full_write: 
      setb ROLLOVER ;indicates memory write into 1st half 
      mov ADDRS,#00h 
      mov WTCMD,#10100000B ;page 0 address with write command

full_write_loop1: 
      acall rx_main 
      acall tx_main 

      mov I2C_IN,a 
      acall WRITE_iic 
      inc ADDRS 
      mov a,ADDRS 
      cjne a,#0ffh,full_write_loop2 

      jnb ROLLOVER,overload 
      mov WTCMD,#10100010B page 1 address with write command
      mov ADDRS,#00h 
      clr ROLLOVER ;indicates memory write into 2nd half 

      full_write_loop2: 
      mov a,I2C_IN 
      cjne a,#27,full_write_loop1 

      mov dptr,#disp_leadthrough_complete 
      acall disp_message 
      ;sjmp $ 
      sjmp full_read ;delete this n enable previous inst 


;_________________________________________________________________ 
;-----------------MEMORY OVERWRITE PREVENTION--------------------- 
;_________________________________________________________________ 



overload: 
    mov dptr,#disp_overload 
    acall disp_message 
    sjmp $ 


;_________________________________________________________________ 
;--------------------FULL READ SUBROUTINE------------------------ 
;_________________________________________________________________ 



full_read: 
   mov ADDRS,#00h 
   mov RDCMD,#10100001B ;page 0 address with read command

   mov dptr, #disp_executing_task 
   acall disp_message 

full_read_loop1: 
   acall READ_iic 
   mov a,I2C_OUT 
   lcall tx_main 
   inc ADDRS 

    mov a,ADDRS 
    cjne a,#0ffh,full_read_loop2 

    mov RDCMD,#10100011B ;page 1 address with read command
    mov ADDRS,#00h 

full_read_loop2: 
    mov a,I2C_OUT 
    cjne a,#27,full_read_loop1 

    mov dptr, #disp_finish_read 
    acall disp_message 


    SJMP FULL_WRITE 


end 





List of 22 messages in thread
TopicAuthorDate
eeprom word addressing            01/01/70 00:00      
   do not confuse bits and bytes            01/01/70 00:00      
      maximum seerial memory chip available?            01/01/70 00:00      
         yes, you do            01/01/70 00:00      
   code not working            01/01/70 00:00      
      How to post code            01/01/70 00:00      
      formatted code.            01/01/70 00:00      
         I searched for a comment stating "write            01/01/70 00:00      
         "write device address"-i2c subroutine            01/01/70 00:00      
            you reply with an uncommented sub            01/01/70 00:00      
            formatted code with comments.            01/01/70 00:00      
               ORL a,HighAddressBit;            01/01/70 00:00      
                  Solution            01/01/70 00:00      
                     You 'can' make the chips you use work fo            01/01/70 00:00      
                        Question still remains unanswred            01/01/70 00:00      
                           i told you how            01/01/70 00:00      
                           One more time            01/01/70 00:00      
                              code written for that but not working            01/01/70 00:00      
                                 rather than trying to figure your code o            01/01/70 00:00      
   Corrections please, urgent.            01/01/70 00:00      
   It is in the data sheet            01/01/70 00:00      
   datasheet            01/01/70 00:00      

Back to Subject List