您当前的位置:五五电子网电子知识单片机-工控设备PIC单片机PIC单片机软件模拟IIC读写例程 正文
PIC单片机软件模拟IIC读写例程

PIC单片机软件模拟IIC读写例程

点击数:7966 次   录入时间:03-04 11:50:32   整理:http://www.55dianzi.com   PIC单片机
;I2C总线程序
;this is eeprom read & write programm
;the special store ram unit
w    equ 0
f0    equ 0
rtCC    equ 1
pc    equ 2
f2    equ 2
f3    equ 3
f4    equ 4
ra    equ 5
rb    equ 6
rc    equ 7
pclath    equ 0ah
iNTCon    equ 0bh
pir1    equ 0ch
tmr1l    equ 0eh
tmr1h    equ 0fh
t1con    equ 10h
tmr2    equ 11h
t2con    equ 12h
sspbuf    equ 13h
sspcon    equ 14h
ccpr1l    equ 15h
ccpr1h    equ 16h
ccpcon    equ 17h
adcon0    equ 1fh
;
;in the bank1
trISA    equ 85h
trisb    equ 86h
trisc    equ 87h
pcon    equ 8eh
pie1    equ 8ch
pr2    equ 92h
sspadd    equ 93h
sspstat equ 94h
adcon1    equ 9fh
;
;--------------------------------------------------------
;the genaral store ram unit
;
temp6     equ 76h
temp7     equ 77h
;
eepCTR     equ 6dh ;eeprom control words buffer
eepaddr  equ 6eh ;eeprom address buffer
eepdata  equ 6fh ;eeprom data buffer
;
;--------------------------------------------------------
;the bits of ram unit
scl    equ 3    ;rc
sda    equ 4    ;rc
;
pd    equ 3    ;status
to    equ 4    ;status
;
rbif    equ 0    ;intcon
intif    equ 1    ;intcon
rtif    equ 2    ;intcon
rbie    equ 3    ;intcon
intie    equ 4    ;intcon
rtie    equ 5    ;intcon
adie    equ 6    ;intcon
gie    equ 7    ;intcon
;
;----------------------------------------------------------
;The contact
sda_in    equ    10h
sda_out equ    00h
;
;----------------------------------------------------------
    org 000h
    goto main_program
;--------------------------------------------------------
;     the son-program area
;--------------------------------------------------------
    org 005h
;--------------------------------------------------------
make_s
    bsf rc,sda
    bsf f3,5
;    bsf rc,sda
    MOVlw sda_out
    MOVwf trisc
    bcf f3,5
    nop
ack_check
    bsf f3,5
;    bcf rc,sda
    MOVlw sda_in
    MOVwf trisc
    bcf f3,5
    nop
m_start
    bsf rc,scl
    nop
    btfss rc,sda
    goto make_s
m_start0
    bsf rc,scl
    bcf rc,sda
    bsf f3,5
;    bsf rc,sda
    MOVlw sda_out
    MOVwf trisc
    bcf f3,5
    MOVlw 10100000b
    btfsc sign,read_b
    MOVlw 10100001b
    MOVwf 6dh
    MOVlw 6dh
    MOVwf f4
w_byte
    bsf f3,5
;    bsf rc,sda
    MOVlw sda_out
    MOVwf trisc
    bcf f3,5
    MOVlw 08h
    MOVwf temp2
bit_loop
    nop
    rlf f0
    bcf rc,scl
    btfss f3,0
    goto ^+3
    bsf rc,sda
    goto ^+2
    bcf rc,sda
    nop
    bsf rc,scl
    decfsz temp2
    goto bit_loop
    nop
    bcf rc,scl
    bsf f3,5
;    bcf rc,sda
    MOVlw sda_in
    MOVwf trisc
    bcf f3,5
    bsf rc,scl
    nop
    btfsc rc,sda
    goto m_start0
    bcf rc,scl
    return
;
w_stop
m_stop
    bcf rc,sda
    bsf f3,5
;    bsf rc,sda
    MOVlw sda_out
    MOVwf trisc
    bcf f3,5
    nop
    bsf rc,scl
    nop
    bsf rc,sda
    nop
    bcf rc,scl
    return
;
rd_bytes
    nop
rnxtb
    bcf rc,scl
    bsf f3,5
;    bcf rc,sda
    MOVlw sda_in
    MOVwf trisc
    bcf f3,5
    MOVlw 08h
    MOVwf temp2
rnx
    bcf rc,scl
    nop
    bcf f3,0
    btfsc rc,sda
    bsf f3,0
    rlf f0
    bsf rc,scl
    nop

[1] [2]  下一页


本文关键字:单片机  软件  PIC单片机单片机-工控设备 - PIC单片机