Tuesday, May 31, 2016

8051 Program - i2c subroutines

;Ports Used for I2C Communication
sda equ P0.0
scl equ P0.1
;Start Condition for I2C Communication
startc:
clr scl
setb sda
nop
nop
setb scl
nop
nop
clr sda
ret
;Stop Condition For I2C Bus
stop:
nop
nop
clr sda
setb scl
nop
nop
setb sda
nop
nop
clr scl
ret
;Sending Data to slave on I2C bus
;with Acknowledgement
send:
mov r7,#08
back:
clr scl
nop
nop
nop
rlc a
mov sda,c
setb scl
nop
nop
nop
clr scl
nop
nop
nop
djnz r7,back
setb sda
setb scl
nop
nop
nop
nop
clr scl
nop
nop
nop
ret
;Receiving Data from slave on I2C bus
;with Acknowledgement
recv:
mov r7,#08
back2:
setb sda
setb scl
nop
nop
nop
mov c,sda
rlc a
clr scl
nop
nop
nop
djnz r7,back2
setb sda
clr scl
nop
nop
nop
clr sda
setb scl
nop
nop
nop
clr scl
nop
nop
nop
mov @r0,a
inc r0
ret



Related topics:
8051 Program - day of week calculation   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines   |   8051 Program - memory subroutines   |   8051 Projects   |   8051 Question Bank

List of topics: 8051

No comments:

Post a Comment