kaiyun官方注册
您所在的位置: 首页> 嵌入式技术> 解决方案> PIC单片机读写I2C实例源程序一

PIC单片机读写I2C实例源程序一

2009-01-16
关键词: I2C 单片机

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

本站内容除特别声明的原创文章之外,转载内容只为传递更多信息,并不代表本网站赞同其观点。转载的所有的文章、图片、音/视频文件等资料的版权归版权所有权人所有。本站采用的非本站原创文章及图片等内容无法一一联系确认版权者。如涉及作品内容、版权和其它问题,请及时通过电子邮件或电话通知我们,以便迅速采取适当措施,避免给双方造成不必要的经济损失。联系电话:010-82306116;邮箱:aet@chinaaet.com。
Baidu
map