⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 library.asm

📁 Library for the 8051 microcontroller. such as math routine, hexBCD, LCD, Keyboard, I2C, Remote, Ke
💻 ASM
字号:
;************************************************************************
;		I2C Protocol Library
;
;	Written by:	Ajay Bhargav
;	Email:		bhargav.ajay@gmail.com
;	URL:		http://www.rickeyworld.info
;	Description:	I2C Subroutines for I2C communication
;			these subroutines covers start, stop, send, recieve
;			etc. They can be used by anyone and can be changed
;			and distributed.
;
;	IMPORTANT:	Some I2C devices may be slow so you need to add one
;			or two nops where ever it required.
;
;	NOTE:		This library works ony with single master multi-slave 
;			configuration. If you find any problem mail me.
;************************************************************************


;************************************************************************
;		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
END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -