1 24C02读写汇编程序,24C02 read / write process-德赢Vwin官网 网

24C02读写汇编程序,24C02 read / write process

电子说

1.3w人已加入

描述

24C02读写汇编程序,24C02 read / write process

关键字:24C02读写汇编程序

24C02读写汇编程序
 
;简洁的24C02读写汇编程序 
;--------------------------------------------
    I2C_SDA          EQU P1.6   ; PIN 5
    I2C_SCL          EQU P1.7   ; PIN 6
 
;=============================================
I2C_WRITE:  ;  WRITE 8 BYTES TO EEROM ; INPUT: A - A*8 = EEROM START ADDR 
            ;                                  R0 - RAN START ADDR
            ;                            USE: C, A, R0, R6, R7
 
      ACALL I2C_START
      ACALL OUT
      MOV R6, #8
WR_LP:MOV A, @R0
      ACALL OUT
      INC R0
      DJNZ R6, WR_LP
      AJMP I2C_STOP  
 
;==========================================
I2C_READ:   ;  READ 8 BYTES FROM EEROM ; INPUT: A - A*8 = EEROM START ADDR 
            ;                                   R0 - RAN START ADDR
            ;                            USE: C, A, R0, R6, R7
      
      ACALL I2C_START
      ACALL OUT
      MOV R6, #8
      MOV A, #0A1H; #RDCMD
      ACALL OUTS
BRDLP:
          MOV R7, #8
          SETB I2C_SDA
INLP:     CLR  I2C_SCL
          ACALL DELAY6
          SETB  I2C_SCL
          NOP
          MOV C, I2C_SDA
          RLC A
          DJNZ R7, INLP
          CLR   I2C_SCL
          MOV @R0, A
          INC R0
   DJNZ R6, ACKLP
;;;;----------------------------
I2C_STOP:
          CLR I2C_SDA
          ACALL DELAY5
          SETB I2C_SCL
          ACALL DELAY5
          SETB I2C_SDA
DELAY6:
          NOP
DELAY5:
          NOP
          RET
;;-----------------------------
I2C_START:
      SWAP A
      RR A
      MOV R6, A
      MOV A, #0A0H; #WTCMD
      ACALL OUTS
      MOV A, R6
      RET
;-------------------------------                  
ACKLP:
      CLR I2C_SDA 
      SETB I2C_SCL
      ACALL DELAY5
      CLR I2C_SCL
      AJMP BRDLP
;=======================
OUTS:
      SETB I2C_SDA  
      SETB I2C_SCL 
      ACALL DELAY5 
      CLR I2C_SDA  
      ACALL DELAY5 
      CLR I2C_SCL  
;========================
OUT:
      SETB C
      MOV R7, #9
OTLP: RLC A
      NOP
      MOV I2C_SDA, C
      NOP
      NOP
      SETB I2C_SCL
      ACALL DELAY5
      CLR  I2C_SCL
      DJNZ R7, OTLP
      RET
;========================
END
 
打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表德赢Vwin官网 网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 相关推荐

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分