⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i2cr.txt

📁 I2C protocal read program
💻 TXT
字号:
;------------------------------------------------
; I2C Bus Byte Write sample program
; Master 80c51
; Assembler  2500 A.D. 4.03a
; slave  Atmel A24c16
; by Eddie W.Y. Liang  25-Sep-98
;------------------------------------------------
SCL    .REG 90H.0 ;P1.0
SDA    .REG 90H.1 ;P1.1
ACK    .REG 22H.0 ;0=ACK 1=Not ACK

A24C16W .EQU  10100000B  ;1010-->device address
                         ;bit3 to bit1-->page address
                         ;bit0 -->0=Write
A24C16R .EQU  10100001B  ;1010-->device address
                         ;bit3 to bit1-->page address
                         ;bit0 -->1=Read
BIT_COUNT  .EQU 21H      ;bit counter address

DELAY_2 .MACRO
         NOP
         NOP
        .MACEND

DELAY_3 .MACRO
         NOP
         NOP
         NOP
        .MACEND

DELAY_4 .MACRO
         NOP
         NOP
         NOP
         NOP
        .MACEND

       .ORG 0000H
        SETB ACK
        ACALL START

        MOV A,#A24C16W ;
        ACALL SEND_MSG ;send 24c16 device address and write
                       ;actually, it's not "write". it is "dummy".

        DELAY_4

        MOV A,#00000000B
        ACALL SEND_MSG  ;send 24c16 data address

        SETB SDA
        SETB SCL
        DELAY_4

        ACALL START

        MOV A,#A24C16R ;
        ACALL SEND_MSG ;send 24c16 device address and read
        DELAY_4
        SETB SDA

        ACALL READ_MSG  ;send 24c16 data address

        ACALL STOP

        RET


READ_MSG
        MOV BIT_COUNT,#8
RM_LOOP
        SETB SCL
        DELAY_3
        MOV C,SDA
        RLC A
        CLR SCL
        DELAY_3
        DJNZ BIT_COUNT,RM_LOOP

        DELAY_2
        SETB SDA
        DELAY_3
        SETB SCL
        DELAY_4
        CLR SCL
        DELAY_3
        RET

SEND_MSG    ;YOU HAVE TO PUT  MESSAGE INTO A REGISTER

        MOV BIT_COUNT,#8
SM_LOOP
        RLC  A
        MOV SDA,C ;send 1 bit
        SETB SCL
        DELAY_3

        CLR SCL
        DELAY_3
        DJNZ BIT_COUNT,SM_LOOP

        SETB SDA

        SETB SCL
        DELAY_3
        JNB SDA,NO_ACK     ; if SDA =0 then Ack=0  acknowledge enable
        CLR ACK

NO_ACK:

        CLR SCL
        DELAY_3
        DELAY_4
        CLR SDA
        DELAY_4
        RET


START:
        SETB SDA
        SETB SCL
        DELAY_2
        CLR  SDA
        DELAY_3
        CLR  SCL
        DELAY_3
        RET


STOP:
        CLR SDA
        SETB SCL
        DELAY_4
        SETB SDA
        DELAY_3
        RET

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -