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

📄 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_DI _Set_DI fV
;             RS -> R16
	.even
_Set_DI::
	.dbline -1
	.dbline 53
; //******************************************************************************
; // 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 "iom16v.h" 
; #include "DataType.h"
; #include "LCD.h"
; #include "macros.h" 
; 
; #define cLCD_X_MAX   64
; #define cLCD_Y_MAX  128
; 
; //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);
; void LCD_Command_DispOnOff(INT8U onoff);
; void LCD_Command_SetStartLine(INT8U startline);
; void LCD_Command_Set_X(INT8U x);
; void LCD_Command_Set_Y(INT8U y);
; void LCD_Command_WriteByte(INT8U data);
; void LCD_Reset(void);
; void LCD_Clear_Line(INT8U wStartLine,INT8U wEndLine);
; void LCD_Init(void);
; void WriteWord(INT8U const *disp,INT8U x,INT8U y);
; void WriteCharacter(const INT8U *disp,INT8U x,INT8U y,INT8U cs);
; void WritePIC(const INT8U *disp);
; void LCD_Write_Char(INT8U y,INT8U x,const INT8U *pdata);
; void LCD_Write_Dot(INT8U x,INT8U y);
; void LCD_Write_Data(INT8U x,INT8U y,INT8U data);	
; void LCD_Write_Picture(INT8U x1,INT8U y1,INT8U x2,INT8U y2,const INT8U *pdata);
; 
; //******************************************************************************
; // Function    : Set_RS
; // Input       : RS - RS Control Line Level
; // Output      : none
; // Description : LCD(1602) Low Level Interface Function
; //******************************************************************************
; void Set_DI(INT8U RS)
; {
	.dbline 54
; 	if(RS == 0)
	tst R16
	brne L2
	.dbline 55
; 	{
	.dbline 56
; 		PORTB &= ~0x01;
	cbi 0x18,0
	.dbline 57
; 	}
	xjmp L3
L2:
	.dbline 59
	.dbline 60
	sbi 0x18,0
	.dbline 61
L3:
	.dbline -2
	.dbline 62
; 	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 71
; 
; //******************************************************************************
; // Function    : Set_RW
; // Input       : RW - RW Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_RW(INT8U RW)
; {
	.dbline 72
; 	if(RW == 0)
	tst R16
	brne L5
	.dbline 73
; 	{
	.dbline 74
; 		PORTB &= ~0x02;
	cbi 0x18,1
	.dbline 75
; 	}
	xjmp L6
L5:
	.dbline 77
	.dbline 78
	sbi 0x18,1
	.dbline 79
L6:
	.dbline -2
	.dbline 80
; 	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 89
; 
; //******************************************************************************
; // Function    : Set_EN
; // Input       : RW - RW Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_EN(INT8U EN)
; {
	.dbline 90
; 	if(EN == 0)
	tst R16
	brne L8
	.dbline 91
; 	{
	.dbline 92
; 		PORTB &= ~0x04;
	cbi 0x18,2
	.dbline 93
; 	}
	xjmp L9
L8:
	.dbline 95
	.dbline 96
	sbi 0x18,2
	.dbline 97
L9:
	.dbline -2
	.dbline 98
; 	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 107
; 
; //******************************************************************************
; // Function    : Set_CS2
; // Input       : CS2 - CS2 Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_CS2(INT8U CS2)
; {
	.dbline 108
; 	if(CS2 == 0) 
	tst R16
	brne L11
	.dbline 109
; 	{
	.dbline 110
; 		PORTC &= ~0x20;
	cbi 0x15,5
	.dbline 111
; 	}
	xjmp L12
L11:
	.dbline 113
	.dbline 114
	sbi 0x15,5
	.dbline 115
L12:
	.dbline -2
	.dbline 116
;  	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 125
; 
; //******************************************************************************
; // Function    : Set_CS1
; // Input       : CS1 - CS1 Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_CS1(INT8U CS1)
; {
	.dbline 126
; 	if(CS1 == 0)
	tst R16
	brne L14
	.dbline 127
; 	{
	.dbline 128
; 		PORTC &= ~0x40;
	cbi 0x15,6
	.dbline 129
; 	}
	xjmp L15
L14:
	.dbline 131
	.dbline 132
	sbi 0x15,6
	.dbline 133
L15:
	.dbline -2
	.dbline 134
; 	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 144
; 
; 
; //******************************************************************************
; // Function    : Set_CS1
; // Input       : CS1 - CS1 Control Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_RST(INT8U RST)
; {
	.dbline 145
; 	if(RST == 0)
	tst R16
	brne L17
	.dbline 146
; 	{
	.dbline 147
; 		PORTC &= ~0x80;
	cbi 0x15,7
	.dbline 148
; 	}
	xjmp L18
L17:
	.dbline 150
	.dbline 151
	sbi 0x15,7
	.dbline 152
L18:
	.dbline -2
	.dbline 153
; 	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 162
;  
; //******************************************************************************
; // Function    : Set_Data
; // Input       : data - Data Line Level
; // Output      : none
; // Description : Low Level Interface Function
; //******************************************************************************
; void Set_Data(INT8U data)
; {
	.dbline 163
; 	PORTA  = data;
	out 0x1b,R16
	.dbline -2
	.dbline 164
; }
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 173
; 
; //******************************************************************************
; // 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 174
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 175
; 	Set_DI(0);
	clr R16
	xcall _Set_DI
	.dbline 176
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 177
; 	Set_Data(0x3E + onoff);
	mov R16,R20
	subi R16,194    ; addi 62
	xcall _Set_Data
	.dbline 178
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 179
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 180
; }
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 189
; 
; //******************************************************************************
; // 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 190
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 191
; 	Set_DI(0);																
	clr R16
	xcall _Set_DI
	.dbline 192
; 	Set_EN(0);																
	clr R16
	xcall _Set_EN
	.dbline 193
; 	Set_Data(0xC0 + startline);
	mov R16,R20
	subi R16,64    ; addi 192
	xcall _Set_Data
	.dbline 194
; 	Set_EN(1);																
	ldi R16,1
	xcall _Set_EN
	.dbline 195
; 	Set_EN(0);																
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 196
; }
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 205
; 
; //******************************************************************************
; // 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 206
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 207
; 	Set_DI(0);
	clr R16
	xcall _Set_DI
	.dbline 208
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 209
; 	Set_Data(0xB8 + x);
	mov R16,R20
	subi R16,72    ; addi 184
	xcall _Set_Data
	.dbline 210
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 211
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 212
; }
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 221
; 
; //******************************************************************************
; // 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 222
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 223
; 	Set_DI(0);
	clr R16
	xcall _Set_DI
	.dbline 224
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 225
; 	Set_Data(0x40 + column);
	mov R16,R20
	subi R16,192    ; addi 64
	xcall _Set_Data
	.dbline 226
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 227
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 228
; }
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 237
; 
; //******************************************************************************
; // 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 238
; 	Set_RW(0);
	clr R16
	xcall _Set_RW
	.dbline 239
; 	Set_DI(1);
	ldi R16,1
	xcall _Set_DI
	.dbline 240
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline 241
; 	Set_Data(data);
	mov R16,R20
	xcall _Set_Data
	.dbline 242
; 	Set_EN(1);
	ldi R16,1
	xcall _Set_EN
	.dbline 243
; 	Set_EN(0);
	clr R16
	xcall _Set_EN
	.dbline -2
	.dbline 244
; }
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 253
; 
; //******************************************************************************
; // Function    : LCD_Reset
; // Input       : none
; // Output      : none
; // Description : Command Level Function,Soft RESET LCD Module
; //******************************************************************************
; void LCD_Reset(void)
; {
	.dbline 254
; 	Set_RST(0);
	clr R16
	xcall _Set_RST
	.dbline 255
; 	Set_RST(1);
	ldi R16,1
	.dbline -2
	.dbline 256
; }
L25:
	.dbline 0 ; func end
	xjmp _Set_RST
	.dbend
	.dbfunc e LCD_Init _LCD_Init fV
	.even
_LCD_Init::
	.dbline -1
	.dbline 265
; 
; //******************************************************************************
; // Function    : LCD_Init
; // Input       : none
; // Output      : none
; // Description : Application Level Function,Init LCD
; //******************************************************************************
; void LCD_Init(void)
; {
	.dbline 266
; 	LCD_Reset();
	xcall _LCD_Reset
	.dbline 267
; 	LCD_Clear_Line(0,7);
	ldi R18,7
	clr R16
	xcall _LCD_Clear_Line
	.dbline 268
; 	LCD_Command_DispOnOff(1);
	ldi R16,1
	xcall _LCD_Command_DispOnOff

⌨️ 快捷键说明

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