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

📄 lcd1602pbpd.s

📁 一些LCD库 分享给大家了 哈哈~
💻 S
📖 第 1 页 / 共 5 页
字号:
	movw R30,R16
	std z+0,R2
; 	return I2C_CRR;
	ldi R16,1
L50:
	.dbline 0 ; func end
	ret
;         pRdDat -> R16,R17
	.even
_I2C_RcvAckDat::
; }
; /*--------------------------------------------------------------------
; 函数名称:I2C接收数据且产生应答
; 函数功能:
; 注意事项:
; 提示说明:
; 输    入:
; 返    回:
; --------------------------------------------------------------------*/
; bool I2C_RcvAckDat(uint8 *pRdDat)	
; {
; 	I2CRcvAckByte();					
	ldi R24,196
	out 0x36,R24
; 	I2CWaitAck();
L57:
L58:
	in R2,0x36
	sbrs R2,7
	rjmp L57
X20:
; 	if( I2CChkAck()!=I2C_MR_DATA_ACK )
	in R24,0x1
	andi R24,248
	cpi R24,80
	breq L60
X21:
; 		return I2C_ERR;
	clr R16
	xjmp L56
L60:
; 	*pRdDat=TWDR;
	in R2,0x3
	movw R30,R16
	std z+0,R2
; 	return I2C_CRR;
	ldi R16,1
L56:
	.dbline 0 ; func end
	ret
;            dat -> y+4
;        wordAdr -> R10
;         wrDAdr -> R12,R13
	.even
_I2C_Write::
	xcall push_xgset003C
	mov R10,R18
	movw R12,R16
; }
; /*--------------------------------------------------------------------
; 函数名称:I2C写器件,写一个数据
; 函数功能:
; 注意事项:
; 提示说明:
; 输    入:wrDAdr: write device-address 写器件地址
; 		 wordAdr: word address 字地址
; 		 dat: data 数据
; 返    回:
; --------------------------------------------------------------------*/
; bool I2C_Write(uint16 wrDAdr,uint8 wordAdr,uint8 dat)
; {
; 	if( I2C_Start()==I2C_ERR )
	xcall _I2C_Start
	tst R16
	brne L63
X22:
; 		return I2C_ERR;
	clr R16
	xjmp L62
L63:
; 
; 	if( I2C_SendWrDAdr_(wrDAdr)==I2C_ERR )
	movw R16,R12
	xcall _I2C_SendWrDAdr_
	tst R16
	brne L65
X23:
; 		return I2C_ERR;
	clr R16
	xjmp L62
L65:
; 
; 	if( I2C_SendDat(wordAdr)==I2C_ERR )
	mov R16,R10
	xcall _I2C_SendDat
	mov R10,R16
	tst R16
	brne L67
X24:
; 		return I2C_ERR;
	clr R16
	xjmp L62
L67:
; 
; 	if( I2C_SendDat(dat)==I2C_ERR )
	ldd R16,y+4
	xcall _I2C_SendDat
	mov R10,R16
	tst R16
	brne L69
X25:
; 		return I2C_ERR;
	clr R16
	xjmp L62
L69:
; 
; 	I2C_Stop();
	ldi R24,148
	out 0x36,R24
; 
; 	return I2C_CRR;
	ldi R16,1
L62:
	.dbline 0 ; func end
	xjmp pop_xgset003C
;         pRdDat -> y+6
;         rdDAdr -> y+4
;        wordAdr -> R10
;         wrDAdr -> R12,R13
	.even
_I2C_Read::
	xcall push_xgset003C
	mov R10,R18
	movw R12,R16
; }
; /*--------------------------------------------------------------------
; 函数名称:I2C写器件,写N个数据
; 函数功能:
; 注意事项:
; 提示说明:
; 输    入:wrDAdr: write device-address 写器件地址
; 		 wordAdr: word address 字地址
; 		 *pWrDat: p->write data 写入数据指针
; 		 num: number 写入数据个数
; 返    回:
; --------------------------------------------------------------------*/
; //bool I2C_Write_(uint16 wrDAdr,uint8 wordAdr,
; //				  uint8 *pWrDat,uint8 num)
; //{
; //
; //} 
; /*--------------------------------------------------------------------
; 函数名称:I2C读器件,读一个数据
; 函数功能:
; 注意事项:
; 提示说明:
; 输    入:wrDAdr: write device-address 写器件地址
; 		 wordAdr: word address 字地址
; 		 rdDAdr: read device-address 读器件地址
; 		 *pRdDat: p->read data 读取数据指针
; 返    回:
; --------------------------------------------------------------------*/
; bool I2C_Read(uint16 wrDAdr,uint8 wordAdr,
; 			  uint8 rdDAdr,uint8 *pRdDat)
; {
; 	if( I2C_Start()==I2C_ERR )
	xcall _I2C_Start
	tst R16
	brne L72
X26:
; 		return I2C_ERR;
	clr R16
	xjmp L71
L72:
; 
; 	if( I2C_SendWrDAdr_(wrDAdr)==I2C_ERR )
	movw R16,R12
	xcall _I2C_SendWrDAdr_
	tst R16
	brne L74
X27:
; 		return I2C_ERR;
	clr R16
	xjmp L71
L74:
; 
; 	if( I2C_SendDat(wordAdr)==I2C_ERR )
	mov R16,R10
	xcall _I2C_SendDat
	mov R10,R16
	tst R16
	brne L76
X28:
; 		return I2C_ERR;
	clr R16
	xjmp L71
L76:
; 
; 	if( I2C_Restart()==I2C_ERR )
	xcall _I2C_Restart
	mov R10,R16
	tst R16
	brne L78
X29:
; 		return I2C_ERR;
	clr R16
	xjmp L71
L78:
; 
; 	if( I2C_SendRdDAdr(rdDAdr)==I2C_ERR )
	ldd R16,y+4
	xcall _I2C_SendRdDAdr
	mov R10,R16
	tst R16
	brne L80
X30:
; 		return I2C_ERR;
	clr R16
	xjmp L71
L80:
; 
; 	if( I2C_RcvNAckDat(pRdDat)==I2C_ERR )
	ldd R16,y+6
	ldd R17,y+7
	xcall _I2C_RcvNAckDat
	mov R10,R16
	tst R16
	brne L82
X31:
; 		return I2C_ERR;
	clr R16
	xjmp L71
L82:
; 
; 	I2C_Stop();
	ldi R24,148
	out 0x36,R24
; 
; 	return I2C_CRR;
	ldi R16,1
L71:
	.dbline 0 ; func end
	xjmp pop_xgset003C
;              i -> R12
;            num -> y+10
;         pRdDat -> R10,R11
;         rdDAdr -> y+6
;        wordAdr -> R12
;         wrDAdr -> R14,R15
	.even
_I2C_Read_::
	xcall push_xgset00FC
	mov R12,R18
	movw R14,R16
	ldd R10,y+8
	ldd R11,y+9
; }
; /*--------------------------------------------------------------------
; 函数名称:I2C读器件,读N个数据
; 函数功能:
; 注意事项:
; 提示说明:
; 输    入:wrDAdr: write device-address 写器件地址
; 		 wordAdr: word address 字地址
; 		 rdDAdr: read device-address 读器件地址
; 		 *pRdDat: p->read data 读取数据指针
; 		 num: number 读取数据个数
; 返    回:
; --------------------------------------------------------------------*/
; bool I2C_Read_(uint16 wrDAdr,uint8 wordAdr,
; 			   uint8 rdDAdr,uint8 *pRdDat,uint8 num)
; {
;  	uint8 i;
; 	
; 	if( I2C_Start()==I2C_ERR )
	xcall _I2C_Start
	tst R16
	brne L85
X32:
; 		return I2C_ERR;
	clr R16
	xjmp L84
L85:
; 
; 	if( I2C_SendWrDAdr_(wrDAdr)==I2C_ERR )
	movw R16,R14
	xcall _I2C_SendWrDAdr_
	tst R16
	brne L87
X33:
; 		return I2C_ERR;
	clr R16
	xjmp L84
L87:
; 
; 	if( I2C_SendDat(wordAdr)==I2C_ERR )
	mov R16,R12
	xcall _I2C_SendDat
	mov R12,R16
	tst R16
	brne L89
X34:
; 		return I2C_ERR;
	clr R16
	xjmp L84
L89:
; 
; 	if( I2C_Restart()==I2C_ERR )
	xcall _I2C_Restart
	mov R12,R16
	tst R16
	brne L91
X35:
; 		return I2C_ERR;
	clr R16
	xjmp L84
L91:
; 
; 	if( I2C_SendRdDAdr(rdDAdr)==I2C_ERR )
	ldd R16,y+6
	xcall _I2C_SendRdDAdr
	mov R12,R16
	tst R16
	brne L93
X36:
; 		return I2C_ERR;
	clr R16
	xjmp L84
L93:
; 
; 	for(i=0;i<num-1;i++)
	clr R12
	xjmp L98
L95:
; 		if( I2C_RcvAckDat(pRdDat+i)==I2C_ERR )
	mov R16,R12
	clr R17
	add R16,R10
	adc R17,R11
	xcall _I2C_RcvAckDat
	mov R14,R16
	tst R16
	brne L99
X37:
; 			return I2C_ERR;
	clr R16
	xjmp L84
L99:
L96:
	inc R12
L98:
	ldd R24,y+10
	subi R24,1
	cp R12,R24
	brlo L95
X38:
; 	
; 	if( I2C_RcvNAckDat(pRdDat+i)==I2C_ERR )
	mov R16,R12
	clr R17
	add R16,R10
	adc R17,R11
	xcall _I2C_RcvNAckDat
	mov R10,R16
	tst R16
	brne L101
X39:
; 			return I2C_ERR;
	clr R16
	xjmp L84
L101:
; 
; 	I2C_Stop();
	ldi R24,148
	out 0x36,R24
; 	
; 	return I2C_CRR;
	ldi R16,1
L84:
	.dbline 0 ; func end
	xjmp pop_xgset00FC
;              j -> R20
;              t -> R16,R17
	.even
_delay50us::
	st -y,R20
; /*********************************************************************
; 	微 雪 电 子   WaveShare   http://www.waveShare.net            	
; 		                                                        
; 目    的:   建立AVR的硬件提取库,增加各类补丁,方便移植
; 					
; 目标系统:   基于AVR单片机
; 		                                                                
; 应用软件:   ICCAVR
; 		                                                                
; 版    本:   Version 1.0                                                          
; 		                                                                
; 圆版时间:   2005-06-25
; 	
; 开发人员:   SEE
; 
; 说    明:   若用于商业用途,请保留此段文字或注明代码来源
; 	
; 	深 圳 市 微 雪 电 子 有 限 公 司 保 留 所 有 的 版 权     
; *********************************************************************/
; 
; /*01010101010101010101010101010101010101010101010101010101010101010101
; ----------------------------------------------------------------------
; 版本更新记录:
; 
; ----------------------------------------------------------------------
; 入口参数说明:
; 
; ----------------------------------------------------------------------
; 待定参数说明:
; 
; ----------------------------------------------------------------------	
; 对外变量说明:
;     
; ----------------------------------------------------------------------
; 对外函数说明:
;    
; ----------------------------------------------------------------------
; 10101010101010101010101010101010101010101010101010101010101010101010*/
; 
; #ifndef Hardware_H
; #define Hardware_H
; 
; #include <math.h>
; #include <string.h>
; #include <stdio.h>
; #include <macros.h>
; #include <eeprom.h>
; //#include <wdt.h>
; 
; /* TWI configs */
; //如使用ATMEGA162(没有TWI接口)之类的MCU,在加载Hardware.H前,务必加“#define NO_INCLUDE_I2C_H 1”语句
; #if NO_INCLUDE_I2C_H
; ;
; #else
; #include "D:\ICC_H\I2C.H"	//i2c即AVR的"twi"
; #endif
; 
; /* hard configs */
; #ifndef flash
; 	#define flash	const
; #endif
; 
; #ifndef code
; 	#define code	const
; #endif
; 
; #ifndef NOP
; 	#define NOP()	asm("nop")
; #endif
; 
; /* io configs */
; #define sbi(io,bit)		(  io |=  (1<<bit) )	//example: sbi(PORTA,0);sbi(DDRA,0);
; #define cbi(io,bit)		(  io &= ~(1<<bit) )	//example: cbi(PORTA,0);cbi(DDRA,0);
; #define gbi(pin ,bit)	( pin &   (1<<bit) )	//example: gbi(PINA,0);
; 
; /* interrupt configs */
; #define DIS_INT  asm("sei")
; #define EN_INT   asm("cli")
; 
; /* wdt configs */
; #define WDT()    asm("wdr")
; 
; /* bit operation */
; //#ifndef BIT
; //#define BIT(x)	( 1<<(x) )
; //#endif
; 
; /* USART configs for 4 Mhz crystal */
; //#define BAUD9600			25
; //#define BAUD19000			12
; //#define UART_TRAN_ON()	UCR |=  0x08
; //#define UART_TRAN_OFF()	UCR &= ~0x08
; //#define UART_RCV_ON()		UCR |=  0x10
; //#define UART_RCV_OFF()	UCR &= ~0x10
; 
; /*--------------------------------------------------------------------
; 函数全称:50us 延时
; 函数功能:当然是 50us延时 啦
; 注意事项:基于7.3728M晶振,稍微有点误差
; 提示说明:调用delay50us(20),得到1ms延时
; 输    入:	
; 返    回:无 
; --------------------------------------------------------------------*/
; void delay50us(sint16 t)
; {
;     uint8 j;		
;     for(;t>0;t--)			
	xjmp L107
L104:
;         for(j=0;j<70;j++)	
	clr R20
	xjmp L111
L108:
;             ;
L109:
	inc R20
L111:
	cpi R20,70
	brlo L108
X40:
L105:
	subi R16,1
	sbci R17,0
L107:
	clr R2
	clr R3
	cp R2,R16
	cpc R3,R17
	brlt L104
X41:
L103:
	.dbline 0 ; func end
	ld R20,y+
	ret
;              i -> R20,R21
;              t -> R16,R17
	.even
_delay50ms::
	st -y,R20
	st -y,R21
; }
; /*--------------------------------------------------------------------
; 函数全称:50ms 延时
; 函数功能:当然是 50ms延时 啦
; 注意事项:基于7.3728M晶振,稍微有点误差
; 提示说明:调用delay50ms(20),得到1s延时 
; 输    入:
; 返    回:无
; --------------------------------------------------------------------*/
; void delay50ms(sint16 t)
; {
; 	uint16 i; 
; 	for(;t>0;t--)
	xjmp L116
L113:
; 		for(i=0;i<52642;i++)
	clr R20
	clr R21
	xjmp L120
L117:
; 			; 
L118:
	subi R20,255  ; offset = 1
	sbci R21,255
L120:
	ldi R24,162
	ldi R25,205
	ldi R26,0
	ldi R27,0
	movw R2,R20
	clr R4
	clr R5
	cp R2,R24
	cpc R3,R25
	cpc R4,R26
	cpc R5,R27
	brlt L117
X42:
L114:
	subi R16,1
	sbci R17,0
L116:
	clr R2
	clr R3
	cp R2,R16
	cpc R3,R17
	brlt L113
X43:
L112:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.area data(ram, con, rel)
_LCD1602Err::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.area text(rom, con, rel)
;        busySta -> R18
;    busyCounter -> R16,R17
	.even
_busy::
; /*********************************************************************
; 	微 雪 电 子   WaveShare   http://www.waveShare.net            	
; 	                                                        
; 目    的:   建立LCD1602的4位数据模式操作库
; 
; 目标系统:   基于AVR单片机
; 	                                                                
; 应用软件:   ICCAVR                                               
; 	                                                                
; 版    本:   Version 1.0
; 	                                                                
; 圆版时间:   2004-08-25
; 
; 开发人员:   SEE
; 
; 说    明:   若用于商业用途,请保留此段文字或注明代码来源
; 
; 	深 圳 市 微 雪 电 子 有 限 公 司 保 留 所 有 的 版 权 
; *********************************************************************/
; 
; /*01010101010101010101010101010101010101010101010101010101010101010101
; ----------------------------------------------------------------------
; 版本更新记录:
; 	版    本:   Version 1.1
; 	圆版时间:   2005-03-25
; 
; ----------------------------------------------------------------------
; 入口参数说明:
; 
; 	// control port
; 	//#define SET_RS  sbi(PORTB,5)
; 	//#define CLR_RS  cbi(PORTB,5)
; 	//#define OUT_RS  sbi(DDRB,5)
;     
; 	//#define SET_RW  sbi(PORTB,6)
; 	//#define CLR_RW  cbi(PORTB,6)
; 	//#define OUT_RW  sbi(DDRB,6)
;     
; 	//#define SET_E   sbi(PORTB,7)
; 	//#define CLR_E   cbi(PORTB,7)
; 	//#define OUT_E   sbi(DDRB,7)
;     
; 	// data port
; 	//#define SET_D4  sbi(PORTD,4)
; 	//#define CLR_D4  cbi(PORTD,4)
; 	//#define OUT_D4  sbi(DDRD,4)
;     
; 	//#define SET_D5  sbi(PORTD,5)
; 	//#define CLR_D5  cbi(PORTD,5)
; 	//#define OUT_D5  sbi(DDRD,5)
;     
; 	//#define SET_D6  sbi(PORTD,6)
; 	//#define CLR_D6  cbi(PORTD,6)
; 	//#define OUT_D6  sbi(DDRD,6)
;     
; 	//#define SET_D7  sbi(PORTD,7)
; 	//#define CLR_D7  cbi(PORTD,7)
; 	//#define OUT_D7  sbi(DDRD,7)
;     
; 	// busy port
; 	//#define GET_BF  gbi(PIND,7)
; 	//#define OUT_BF  sbi(DDRD,7)
; 	//#define IN_BF	  cbi(DDRD,7)
; 	
; ----------------------------------------------------------------------
; 接口定义:
; LCD1602				ATmega16
; 1.GND		--------	GND
; 2.VCC		--------	VCC
; 3.V0		--------	V0
; 4.RS		--------	由外部程序定义
; 5.R/W		--------	由外部程序定义
; 6.E		--------	由外部程序定义
; 7.D0		--------	NC
; 8.D1		--------	NC
; 9.D2		--------	NC
; 10.D3		--------	NC
; 11.D4		--------	由外部程序定义
; 12.D5		--------	由外部程序定义
; 13.D6		--------	由外部程序定义
; 14.D7		--------	由外部程序定义
; 15.LED+		--------	VCC
; 16.LED-		--------	GND
; 
; 说明:
; (1)使用ATmega16的7根IO口操作LCD1602
; (2)该程序的优点是:7根IO可任意定义,不需分布在固定的一组PORT口上
; (3)该程序的缺点是:IO定义的写法较为繁琐
; ----------------------------------------------------------------------
; 待定参数说明:
; 	//#define DELAY()		{_nop_();_nop_();_nop_();}
; 
; ----------------------------------------------------------------------	
; 对外变量说明:
; 

⌨️ 快捷键说明

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