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

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

点击数:7966 次   录入时间:03-04 11:50:32   整理:http://www.55dianzi.com   PIC单片机
    decfsz temp2
    goto rnx
    incf f4,1
    bsf f3,5
;    bsf rc,sda
    MOVlw sda_out
    MOVwf trisc
    bcf f3,5
    bcf rc,scl
    decfsz temp4
    goto t_ackg
r_stop
    goto m_stop
t_ackg
    bcf rc,sda
    nop
    bsf rc,scl
    nop
    goto rnxtb
;-----------------------------
delay_1ms
    MOVlw .1
    MOVwf temp6
delay_publIC
    MOVlw .223
    MOVwf temp7
public_2
    clrwdt
    decfsz temp7,1
    goto public_2
    decfsz temp6,1
    goto delay_public
    return
;-----------------------------
;-----------------------------
;    the mainprogram area
;-----------------------------
main_program
    bsf f3,5
    MOVlw 0fh
    MOVwf 81h
    MOVlw sda_in
    MOVwf trisc
    bcf f3,5       ;bank 0
reset_delay
    MOVlw 20h
    MOVwf f4
next
    clrf f0
    incf f4,1
    MOVlw 80h        ;clr 20h--7fh ram
    clrz
    xorwf f4,w
    skpz
    goto next
;-----------------------
    clrf intcon
    bsf f3,5
    MOVlw 0fh
    MOVwf 81h
    bcf f3,5       ;bank 0
;
;---------------------------
read_eeprom_repair
    bcf rc,eneep
    call delay_1ms
;
    call ack_check
    MOVf address,0
    MOVwf 6eh
    incf f4
    call w_byte
    bsf sign,read_b
    call ack_check
    bcf sign,read_b
    MOVlw 20h
    MOVwf f4
    MOVlw .8
    MOVwf temp4
    call rd_bytes
    nop
    nop
    nop
    nop
    call delay_1ms
    bsf rc,eneep
;
write_eeprom_repair
    bcf rc,eneep
    call delay_1ms
;
    call ack_check
    MOVf address,0
    MOVwf 6eh
    incf f4
    call w_byte
    MOVlw 40h
    MOVwf f4
    MOVlw .8
    MOVwf temp4
write_option
    call w_byte
    incf f4,1
    decfsz temp4
    goto write_option
    call w_stop
    nop
    nop
    nop
    nop
    call delay_1ms
    bsf rc,eneep
;
loop
    goto loop
end


上一页  [1] [2] 


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