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

📄 i2cw.txt

📁 I2C protocal write 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

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

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

        ACALL STOP

        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  ; SCL High for 4 cycles
        CLR SCL  ;
        DELAY_3                 ; SCL Low for 5 cycles
        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    ; go back original status before send_msg
        CLR SDA
        DELAY_2
        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 + -