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

📄 lcd.s

📁 AVR单片机C语言程序设计实例精粹
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module LCD.c
	.area text(rom, con, rel)
	.dbfile E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\字符型LCD显示应用设计\LCD.c
	.dbfunc e Set_RS _Set_RS fV
;             RS -> R16
	.even
_Set_RS::
	.dbline -1
	.dbline 37
; //******************************************************************************
; // File Name : LCD.c
; // Author    : Steaven
; // Created   : 2008-07-27
; // Modified  : 
; // Revision  : V0.0
; //******************************************************************************
; 
; //PIN DESCRIPTION
; //01  2   3  4   5   6   7   8   9   10  11  12  13  14  15  16
; //GND VCC V0 RS  RW  EN  D0  D1  D2  D3  D4  D5  D6  D7  BLA BLK
; //GND +5V V0 PB0 PB1 PB2 PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 GND +5V
; 
; #include "iom16v.h" 
; #include "DataType.h"
; #include "LCD.h"
; #include "macros.h" 
; 
; //local functions declaration
; void Set_RS(INT8U RS);
; void Set_RW(INT8U RW);
; void Set_EN(INT8U EN);
; void Set_Data(INT8U data);
; void LCD_Write_Command(INT8U command,INT8U status);
; void LCD_Write_Data(INT8U data,INT8U status);
; void Delay_ms(INT8U time);
; INT8U LCD_Read_BF(void);
; INT8U LCD_Read_Data(INT8U status);
; 
; //******************************************************************************
; // Function    : Set_RS
; // Input       : RS - RS Control Line Level
; // Output      : none
; // Description : LCD(1602) Low Level Interface Function
; //******************************************************************************
; void Set_RS(INT8U RS)
; {
	.dbline 38
; 	if(RS == 0)
	tst R16
	brne L2
	.dbline 39
; 	{
	.dbline 40
; 		PORTB &= ~0x01;
	cbi 0x18,0
	.dbline 41
; 	}
	xjmp L3
L2:
	.dbline 43
	.dbline 44
	sbi 0x18,0
	.dbline 45
L3:
	.dbline -2
	.dbline 46
; 	else
; 	{
; 		PORTB |= 0x01;
; 	}
; }
L1:
	.dbline 0 ; func end
	ret
	.dbsym r RS 16 c
	.dbend
	.dbfunc e Set_RW _Set_RW fV
;             RW -> R16
	.even
_Set_RW::
	.dbline -1
	.dbline 55
; 
; //******************************************************************************
; // Function    : Set_RW
; // Input       : RW - RW Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_RW(INT8U RW)
; {
	.dbline 56
; 	if(RW == 0)
	tst R16
	brne L5
	.dbline 57
; 	{
	.dbline 58
; 		PORTB &= ~0x02;
	cbi 0x18,1
	.dbline 59
; 	}
	xjmp L6
L5:
	.dbline 61
	.dbline 62
	sbi 0x18,1
	.dbline 63
L6:
	.dbline -2
	.dbline 64
; 	else
; 	{
; 		PORTB |= 0x02;
; 	}
; }
L4:
	.dbline 0 ; func end
	ret
	.dbsym r RW 16 c
	.dbend
	.dbfunc e Set_EN _Set_EN fV
;             EN -> R16
	.even
_Set_EN::
	.dbline -1
	.dbline 73
; 
; //******************************************************************************
; // Function    : Set_EN
; // Input       : RW - RW Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_EN(INT8U EN)
; {
	.dbline 74
; 	if(EN == 0)
	tst R16
	brne L8
	.dbline 75
; 	{
	.dbline 76
; 		PORTB &= ~0x04;
	cbi 0x18,2
	.dbline 77
; 	}
	xjmp L9
L8:
	.dbline 79
	.dbline 80
	sbi 0x18,2
	.dbline 81
L9:
	.dbline -2
	.dbline 82
; 	else
; 	{
; 		PORTB |= 0x04;
; 	}
; }
L7:
	.dbline 0 ; func end
	ret
	.dbsym r EN 16 c
	.dbend
	.dbfunc e Set_Data _Set_Data fV
;           data -> R16
	.even
_Set_Data::
	.dbline -1
	.dbline 91
; 
; //******************************************************************************
; // Function    : Set_RW
; // Input       : data - Data Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_Data(INT8U data)
; {
	.dbline 92
; 	PORTA  = data;
	out 0x1b,R16
	.dbline -2
	.dbline 93
; }
L10:
	.dbline 0 ; func end
	ret
	.dbsym r data 16 c
	.dbend
	.dbfunc e LCD_Read_BF _LCD_Read_BF fc
;         status -> R20
	.even
_LCD_Read_BF::
	xcall push_gset1
	.dbline -1
	.dbline 102
; 
; //******************************************************************************
; // Function    : LCD_Read_BF
; // Input       : none
; // Output      : 0 = LCD Controller is Free,0x80 = LCD Busy
; // Description : Read LCD Controller Status
; //******************************************************************************
; INT8U LCD_Read_BF(void)
; {
	.dbline 104
; 	INT8U status;
; 	DDRA = 0x00;
	clr R2
	out 0x1a,R2
	.dbline 105
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 106
; 	Set_RS(0);
	clr R16
	xcall _Set_RS
	.dbline 107
; 	Set_RW(1);
	ldi R16,1
	xcall _Set_RW
	.dbline 108
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 109
; 	NOP();
	nop
	.dbline 110
; 	status = PINA;
	in R20,0x19
	.dbline 111
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 112
; 	DDRA = 0xFF;
	ldi R24,255
	out 0x1a,R24
	.dbline 113
; 	return(status & 0x80);
	mov R16,R20
	andi R16,128
	.dbline -2
L11:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r status 20 c
	.dbend
	.dbfunc e LCD_Write_Command _LCD_Write_Command fV
;         status -> R22
;        command -> R20
	.even
_LCD_Write_Command::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 124
; }
; 
; //******************************************************************************
; // Function    : LCD_Write_Command
; // Input       : command - Command to be written to LCD
; //               status  - Detect LCD Status when 1 
; // Output      : none
; // Description : Write Command to LCD
; //******************************************************************************
; void LCD_Write_Command(INT8U command,INT8U status)
; {
	.dbline 125
; 	if(status == 1)
	cpi R22,1
	brne L13
	.dbline 126
; 	{
L15:
	.dbline 127
	.dbline 127
	.dbline 127
L16:
	.dbline 127
; 		while(LCD_Read_BF() != 0) {;}
	xcall _LCD_Read_BF
	tst R16
	brne L15
	.dbline 128
; 	}
L13:
	.dbline 129
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 130
; 	Set_RS(0);
	clr R16
	xcall _Set_RS
	.dbline 131
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 132
; 	Set_Data(command);
	mov R16,R20
	xcall _Set_Data
	.dbline 133
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 134
; 	NOP();
	nop
	.dbline 135
; 	NOP();
	nop
	.dbline 136
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 137
; }
L12:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r status 22 c
	.dbsym r command 20 c
	.dbend
	.dbfunc e LCD_Write_Data _LCD_Write_Data fV
;         status -> R22
;           data -> R20
	.even
_LCD_Write_Data::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 147
; 
; //******************************************************************************
; // Function    : LCD_Write_Data
; // Input       : data   - Data to be written to LCD
; //               status - Detect LCD Status when 1 
; // Output      : none
; // Description : Write Data to LCD
; //******************************************************************************
; void LCD_Write_Data(INT8U data,INT8U status)
; {
	.dbline 148
; 	if(status == 1)
	cpi R22,1
	brne L19
	.dbline 149
; 	{
L21:
	.dbline 150
	.dbline 150
	.dbline 150
L22:
	.dbline 150
; 		while(LCD_Read_BF() != 0) {;}
	xcall _LCD_Read_BF
	tst R16
	brne L21
	.dbline 151
; 	}
L19:
	.dbline 152
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 153
; 	Set_RS(1);
	ldi R16,1
	xcall _Set_RS
	.dbline 154
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 155
; 	Set_Data(data);
	mov R16,R20
	xcall _Set_Data
	.dbline 156
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 157
; 	NOP();
	nop
	.dbline 158
; 	NOP();
	nop
	.dbline 159
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 160

⌨️ 快捷键说明

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