PIC单片机读写I2C实例源程序一
; this route is used I2C EESROM write and
; read; addressing mode is indirect
START
BSF RB_C,SDA
NOP
MOVFW RB_C
TRIS RB
BSF RB,SCL
NOP
BTFSS RB,SDA
GOTO ^-1
BCF RB_C,SDA
NOP
MOVFW RB_C
TRIS RB
NOP
BCF RB,SDA
NOP
NOP
NOP
NOP
BCF RB,SCL
RETLW 0H
STOP
BCF RB_C,SDA
NOP
MOVFW RB_C
TRIS RB
BCF RB,SDA
NOP
NOP
NOP
BSF RB,SCL
NOP
NOP
NOP
NOP
BSF RB,SDA
RETLW 0
TX
MOVLW 08H
MOVWF LOP1
MOVFW RB_C
ANDLW 7FH
TRIS RB
TXLP
BCF RB,SCL
BTFSC F0,7
GOTO ^+3
BCF RB,SDA
GOTO ^+2
BSF RB,SDA
BCF 3,0
RLF F0
NOP
BSF RB,SCL
NOP
NOP
NOP
DECFSZ LOP1
GOTO TXLP
BCF RB,SCL
ACKG
BSF RB_C,SDA
NOP
MOVFW RB_C
TRIS RB
BSF RB,SCL
NOP
NOP
NOP
BTFSC RB,SDA
GOTO ACKG
NOP
BCF RB,SCL
RETLW 0
RX
MOVLW 08H
MOVWF LOP1
BSF RB_C,SDA
CLRF F0
MOVFW RB_C
TRIS RB
RXLP
BCF RB,SCL
BCF 3,0
RLF F0
NOP
BSF RB,SCL
NOP
NOP
BTFSC RB,SDA
BSF F0,0
DECFSZ LOP1
GOTO RXLP
BCF RB,SCL
BTFSC MARK1,LAST
RETLW 0
MOVFW RB_C
ANDLW 7FH
TRIS RB
BCF RB,SDA
NOP
NOP
NOP
BSF RB,SCL
NOP
BCF RB,SCL
RETLW 0
RD24XX
BCF MARK1,LAST
MOVLW 03H
MOVWF LOP2
CALL START
MOVLW SLAVE
MOVWF F0
CALL TX
MOVFW READ_ADD
MOVWF F0
CALL TX
CALL START
MOVLW SLAVE
MOVWF F0
BSF F0,0
CALL TX
RXN
INCF FSR
BTFSS MARK1,READ
BSF MARK1,LAST
CALL RX
BTFSC MARK1,LAST
GOTO STOP
DECF LOP2
MOVFW LOP2
XORLW 01H
BTFSS 3,2
GOTO RXN
BSF MARK1,LAST
GOTO RXN
WR24XX
MOVLW 03H
MOVWF LOP2
CALL START
MOVLW SLAVE
MOVWF F0
CALL TX
MOVFW WRITE_ADD
MOVWF F0
CALL TX
WRITN
INCF FSR
CALL TX
BTFSS MARK1,WRITE
GOTO ^+3
DECFSZ LOP2
GOTO WRITN
GOTO STOP
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)