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

📄 lcd.s

📁 AVR单片机 C语言程序设计经典实用
💻 S
📖 第 1 页 / 共 5 页
字号:
	.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_DI _Set_DI fV
;             RS -> R16
	.even
_Set_DI::
	.dbline -1
	.dbline 39
; //******************************************************************************
; // 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  17  18  19  20
; //GND VCC V0 RS  RW  EN  D0  D1  D2  D3  D4  D5  D6  D7  CS1 CS2 RST VEE BLA BLK
; //GND +5V V0 PB0 PB1 PB2 PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 PC6 PC5 PC7 VEE +5V GND
; 
; #include "app.h" 
; 
; //constant definition
; #define cLCD_X_MAX   64
; #define cLCD_Y_MAX  128
; 
; //variable defintion
; INT16U wDataBaseLength; //database length
; 
; //local functions declaration
; void Set_DI(INT8U RS);
; void Set_RW(INT8U RW);
; void Set_EN(INT8U EN);
; void Set_CS1(INT8U CS1);
; void Set_CS2(INT8U CS2);
; void Set_RST(INT8U RST);
; void Set_Data(INT8U data);
; 
; //******************************************************************************
; // Function    : Set_RS
; // Input       : RS - RS Control Line Level
; // Output      : none
; // Description : LCD(1602) Low Level Interface Function
; //******************************************************************************
; void Set_DI(INT8U RS)
; {
	.dbline 40
; 	if(RS == 0)
	tst R16
	brne L2
	.dbline 41
; 	{
	.dbline 42
; 		PORTB &= ~0x01;
	cbi 0x18,0
	.dbline 43
; 	}
	xjmp L3
L2:
	.dbline 45
	.dbline 46
	sbi 0x18,0
	.dbline 47
L3:
	.dbline -2
	.dbline 48
; 	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 57
; 
; //******************************************************************************
; // Function    : Set_RW
; // Input       : RW - RW Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_RW(INT8U RW)
; {
	.dbline 58
; 	if(RW == 0)
	tst R16
	brne L5
	.dbline 59
; 	{
	.dbline 60
; 		PORTB &= ~0x02;
	cbi 0x18,1
	.dbline 61
; 	}
	xjmp L6
L5:
	.dbline 63
	.dbline 64
	sbi 0x18,1
	.dbline 65
L6:
	.dbline -2
	.dbline 66
; 	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 75
; 
; //******************************************************************************
; // Function    : Set_EN
; // Input       : RW - RW Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_EN(INT8U EN)
; {
	.dbline 76
; 	if(EN == 0)
	tst R16
	brne L8
	.dbline 77
; 	{
	.dbline 78
; 		PORTB &= ~0x04;
	cbi 0x18,2
	.dbline 79
; 	}
	xjmp L9
L8:
	.dbline 81
	.dbline 82
	sbi 0x18,2
	.dbline 83
L9:
	.dbline -2
	.dbline 84
; 	else
; 	{
; 		PORTB |= 0x04;
; 	}
; }
L7:
	.dbline 0 ; func end
	ret
	.dbsym r EN 16 c
	.dbend
	.dbfunc e Set_CS2 _Set_CS2 fV
;            CS2 -> R16
	.even
_Set_CS2::
	.dbline -1
	.dbline 93
; 
; //******************************************************************************
; // Function    : Set_CS2
; // Input       : CS2 - CS2 Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_CS2(INT8U CS2)
; {
	.dbline 94
; 	if(CS2 == 0) 
	tst R16
	brne L11
	.dbline 95
; 	{
	.dbline 96
; 		PORTC &= ~0x20;
	cbi 0x15,5
	.dbline 97
; 	}
	xjmp L12
L11:
	.dbline 99
	.dbline 100
	sbi 0x15,5
	.dbline 101
L12:
	.dbline -2
	.dbline 102
;  	else
;  	{
;  		PORTC |= 0x20;
;  	}
; }
L10:
	.dbline 0 ; func end
	ret
	.dbsym r CS2 16 c
	.dbend
	.dbfunc e Set_CS1 _Set_CS1 fV
;            CS1 -> R16
	.even
_Set_CS1::
	.dbline -1
	.dbline 111
; 
; //******************************************************************************
; // Function    : Set_CS1
; // Input       : CS1 - CS1 Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_CS1(INT8U CS1)
; {
	.dbline 112
; 	if(CS1 == 0)
	tst R16
	brne L14
	.dbline 113
; 	{
	.dbline 114
; 		PORTC &= ~0x40;
	cbi 0x15,6
	.dbline 115
; 	}
	xjmp L15
L14:
	.dbline 117
	.dbline 118
	sbi 0x15,6
	.dbline 119
L15:
	.dbline -2
	.dbline 120
; 	else
; 	{
; 		PORTC |= 0x40;
; 	}
; }
L13:
	.dbline 0 ; func end
	ret
	.dbsym r CS1 16 c
	.dbend
	.dbfunc e Set_RST _Set_RST fV
;            RST -> R16
	.even
_Set_RST::
	.dbline -1
	.dbline 130
; 
; 
; //******************************************************************************
; // Function    : Set_CS1
; // Input       : CS1 - CS1 Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_RST(INT8U RST)
; {
	.dbline 131
; 	if(RST == 0)
	tst R16
	brne L17
	.dbline 132
; 	{
	.dbline 133
; 		PORTC &= ~0x80;
	cbi 0x15,7
	.dbline 134
; 	}
	xjmp L18
L17:
	.dbline 136
	.dbline 137
	sbi 0x15,7
	.dbline 138
L18:
	.dbline -2
	.dbline 139
; 	else
; 	{
; 		PORTC |= 0x80;
; 	}
; }
L16:
	.dbline 0 ; func end
	ret
	.dbsym r RST 16 c
	.dbend
	.dbfunc e Set_Data _Set_Data fV
;           data -> R16
	.even
_Set_Data::
	.dbline -1
	.dbline 148
;  
; //******************************************************************************
; // Function    : Set_Data
; // Input       : data - Data Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_Data(INT8U data)
; {
	.dbline 149
; 	PORTA  = data;
	out 0x1b,R16
	.dbline -2
	.dbline 150
; }
L19:
	.dbline 0 ; func end
	ret
	.dbsym r data 16 c
	.dbend
	.dbfunc e LCD_Command_DispOnOff _LCD_Command_DispOnOff fV
;          onoff -> R20
	.even
_LCD_Command_DispOnOff::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 159
; 
; //******************************************************************************
; // Function    : LCD_Command_DispOnOff
; // Input       : onoff = 1 -> LCD Display Enabled,else Disabled
; // Output      : none
; // Description : Command Level Function,Display ONOFF Control
; //******************************************************************************
; void LCD_Command_DispOnOff(INT8U onoff)
; {
	.dbline 160
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 161
; 	Set_DI(0);
	clr R16
	xcall _Set_DI
	.dbline 162
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 163
; 	Set_Data(0x3E + onoff);
	mov R16,R20
	subi R16,194    ; addi 62
	xcall _Set_Data
	.dbline 164
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 165
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 166
; }
L20:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r onoff 20 c
	.dbend
	.dbfunc e LCD_Command_SetStartLine _LCD_Command_SetStartLine fV
;      startline -> R20
	.even
_LCD_Command_SetStartLine::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 175
; 
; //******************************************************************************
; // Function    : LCD_Command_SetStartLine
; // Input       : startline - Display Start Line,See Specification
; // Output      : none
; // Description : Command Level Function,Set Display Start Line
; //******************************************************************************
; void LCD_Command_SetStartLine(INT8U startline)
; {
	.dbline 176
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 177
; 	Set_DI(0);																
	clr R16
	xcall _Set_DI
	.dbline 178
; 	Set_EN(0);																
	clr R16
	xcall _Set_EN
	.dbline 179
; 	Set_Data(0xC0 + startline);
	mov R16,R20
	subi R16,64    ; addi 192
	xcall _Set_Data
	.dbline 180
; 	Set_EN(1);																
	ldi R16,1
	xcall _Set_EN
	.dbline 181
; 	Set_EN(0);																
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 182
; }
L21:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r startline 20 c
	.dbend
	.dbfunc e LCD_Command_Set_X _LCD_Command_Set_X fV
;              x -> R20
	.even
_LCD_Command_Set_X::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 191
; 
; //******************************************************************************
; // Function    : LCD_Command_Set_X
; // Input       : x - Display Row,from 0 to 7 for 128*64 LCD
; // Output      : none
; // Description : Command Level Function,Set Operation X Address
; //******************************************************************************
; void LCD_Command_Set_X(INT8U x)
; {
	.dbline 192
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 193
; 	Set_DI(0);
	clr R16
	xcall _Set_DI
	.dbline 194
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 195
; 	Set_Data(0xB8 + x);
	mov R16,R20
	subi R16,72    ; addi 184
	xcall _Set_Data
	.dbline 196
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 197
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 198
; }
L22:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r x 20 c
	.dbend
	.dbfunc e LCD_Command_Set_Y _LCD_Command_Set_Y fV
;         column -> R20
	.even
_LCD_Command_Set_Y::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 207
; 
; //******************************************************************************
; // Function    : LCD_Command_Set_Y
; // Input       : y - Display Column,from 0 to 63 for 128*64 LCD
; // Output      : none
; // Description : Command Level Function,Set Operation Y Address
; //******************************************************************************
; void LCD_Command_Set_Y(INT8U column)
; {
	.dbline 208
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 209
; 	Set_DI(0);
	clr R16
	xcall _Set_DI
	.dbline 210
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 211
; 	Set_Data(0x40 + column);
	mov R16,R20
	subi R16,192    ; addi 64
	xcall _Set_Data
	.dbline 212
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 213
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 214
; }
L23:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r column 20 c
	.dbend
	.dbfunc e LCD_Command_WriteByte _LCD_Command_WriteByte fV
;           data -> R20
	.even
_LCD_Command_WriteByte::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 223
; 
; //******************************************************************************
; // Function    : LCD_Command_WriteByte
; // Input       : data - Display Data
; // Output      : none
; // Description : Command Level Function,Write Display Data to DDRAM
; //******************************************************************************
; void LCD_Command_WriteByte(INT8U data)
; {
	.dbline 224
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 225
; 	Set_DI(1);
	ldi R16,1
	xcall _Set_DI
	.dbline 226
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 227
; 	Set_Data(data);
	mov R16,R20
	xcall _Set_Data
	.dbline 228
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 229
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 230
; }
L24:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r data 20 c
	.dbend
	.dbfunc e LCD_Reset _LCD_Reset fV
	.even
_LCD_Reset::
	.dbline -1
	.dbline 239
; 
; //******************************************************************************
; // Function    : LCD_Reset
; // Input       : none
; // Output      : none
; // Description : Command Level Function,Soft RESET LCD Module
; //******************************************************************************
; void LCD_Reset(void)
; {
	.dbline 240
; 	Set_RST(0);
	clr R16
	xcall _Set_RST
	.dbline 241
; 	Set_RST(1);
	ldi R16,1
	.dbline -2
	.dbline 242
; }
L25:
	.dbline 0 ; func end
	xjmp _Set_RST
	.dbend
	.dbfunc e LCD_Init _LCD_Init fV
	.even
_LCD_Init::
	.dbline -1
	.dbline 251
; 
; //******************************************************************************
; // Function    : LCD_Init
; // Input       : none
; // Output      : none
; // Description : Application Level Function,Init LCD
; //******************************************************************************
; void LCD_Init(void)
; {
	.dbline 252
; 	LCD_Reset();
	xcall _LCD_Reset
	.dbline 253
; 	LCD_Clear_Line(0,7);
	ldi R18,7
	clr R16
	xcall _LCD_Clear_Line
	.dbline 254
; 	LCD_Command_DispOnOff(1);
	ldi R16,1
	xcall _LCD_Command_DispOnOff
	.dbline 255
; 	LCD_Command_SetStartLine(0);
	clr R16
	.dbline -2
	.dbline 256
; }
L26:
	.dbline 0 ; func end
	xjmp _LCD_Command_SetStartLine
	.dbend
	.dbfunc e LCD_Clear_Line _LCD_Clear_Line fV
;              i -> R20
;              j -> R10
;        endline -> R22
;      startline -> R10
	.even
_LCD_Clear_Line::
	xcall push_gset3
	mov R22,R18
	mov R10,R16
	.dbline -1
	.dbline 265
; 
; //******************************************************************************
; // Function    : LCD_Clear_Line
; // Input       : startline,endline - Line Range to be Cleare
; // Output      : none
; // Description : Command Level Function,Clear Screen Display
; //******************************************************************************
; void LCD_Clear_Line(INT8U startline,INT8U endline)
; {
	.dbline 267
; 	INT8U i,j;
; 	for(i = startline;i <= endline;i++)
	mov R20,R10
	xjmp L31
L28:
	.dbline 268
; 	{
	.dbline 269
; 		Set_CS1(1);
	ldi R16,1
	xcall _Set_CS1
	.dbline 270
; 		Set_CS2(1);
	ldi R16,1
	xcall _Set_CS2
	.dbline 271
; 		LCD_Command_Set_X(i);
	mov R16,R20
	xcall _LCD_Command_Set_X
	.dbline 272
; 		LCD_Command_Set_Y(0);
	clr R16
	xcall _LCD_Command_Set_Y
	.dbline 273
; 		for(j = 0;j < 64;j++)
	clr R10
	xjmp L35
L32:
	.dbline 274
	.dbline 275
	clr R16
	xcall _LCD_Command_WriteByte
	.dbline 276
L33:
	.dbline 273
	inc R10
L35:
	.dbline 273
	mov R24,R10

⌨️ 快捷键说明

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