📄 lcd.s
字号:
.module LCD.c
.area text(rom, con, rel)
.dbfile D:\NEW\AVR_PWM\LCD.c
.dbfunc e LCD_INIT _LCD_INIT fV
.even
_LCD_INIT::
.dbline -1
.dbline 52
; // ************************************************
; // *** 采用4位数据线的1602液晶驱动程序 ***
; // *** LCD.C ***
; // ************************************************
; #define ENABLE_BIT_DEFINITIONS
; #define LCD_C
; #include "includes.h"
; // ***** Define I/O pins ***** //
; #define BIT7 0x80
; #define BIT6 0x40
; #define BIT5 0x20
; #define BIT4 0x10
; #define BIT3 0x08
; #define BIT2 0x04
; #define BIT1 0x02
; #define BIT0 0x01
; // *** Set port for LCD Data Bus 8 bit mode *** //
; #define LCD_OP_PORT PORTB
; #define LCD_IP_PORT PINB
; #define LCD_DIR_PORT DDRB
; // *** Set LCD Enable Port and Bit values *** //
; //#define LCD_EN LCD_OP_PORT.2
; // *** Set LCD Register Select Port and Bit values *** //
; //#define LCD_RS LCD_OP_PORT.0
; // *** Set LCD Read/Write Port and Bit values *** //
; //#define LCD_RW LCD_OP_PORT.1
; /****************************************************************/
;
; #define LCD_EN (1 << 2) //引脚定义
; #define LCD_RS (1 << 0)
; #define LCD_RW (1 << 1)
;
; #define lcd_set_e() (LCD_OP_PORT |= LCD_EN) //置位与清零
; #define lcd_set_rs() (LCD_OP_PORT |= LCD_RS)
; #define lcd_set_rw() (LCD_OP_PORT |= LCD_RW)
; #define lcd_clear_e() (LCD_OP_PORT &= ~LCD_EN)
; #define lcd_clear_rs() (LCD_OP_PORT &= ~LCD_RS)
; #define lcd_clear_rw() (LCD_OP_PORT &= ~LCD_RW)
; /****************************************************************/
;
; #define LCD_ON 0x0C
; #define LCD_CURS_ON 0x0D
; #define LCD_OFF 0x08
; #define LCD_HOME 0x02
; #define LCD_CLEAR 0x01
; #define LCD_NEW_LINE 0xC0
; #define LCD_FUNCTION_SET 0x28
; #define LCD_MODE_SET 0x06
;
;
; void LCD_INIT(void)
; {
.dbline 53
; LCD_DIR_PORT = 0xff; // LCD port output
ldi R24,255
out 0x17,R24
.dbline 54
; LCD_OP_PORT = 0x30; // Load high-data to port
ldi R24,48
out 0x18,R24
.dbline 55
; lcd_clear_rw(); // Set LCD to write
cbi 0x18,1
.dbline 56
; lcd_clear_rs(); // Set LCD to command
cbi 0x18,0
.dbline 57
; lcd_set_e(); // Write data to LCD
sbi 0x18,2
.dbline 58
; asm("nop");
nop
.dbline 59
; asm("nop");
nop
.dbline 60
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline 61
; delay_nus(40);
ldi R16,40
ldi R17,0
xcall _delay_nus
.dbline 62
; lcd_clear_rw() ; // Set LCD to write
cbi 0x18,1
.dbline 63
; lcd_clear_rs(); // Set LCD to command
cbi 0x18,0
.dbline 64
; lcd_set_e(); // Write data to LCD
sbi 0x18,2
.dbline 65
; asm("nop");
nop
.dbline 66
; asm("nop");
nop
.dbline 67
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline 68
; delay_nus(40);
ldi R16,40
ldi R17,0
xcall _delay_nus
.dbline 69
; lcd_set_e(); // Write data to LCD
sbi 0x18,2
.dbline 70
; asm("nop");
nop
.dbline 71
; asm("nop");
nop
.dbline 72
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline 73
; delay_nus(40);
ldi R16,40
ldi R17,0
xcall _delay_nus
.dbline 74
; LCD_OP_PORT = 0x20;
ldi R24,32
out 0x18,R24
.dbline 75
; lcd_set_e(); // Write data to LCD
sbi 0x18,2
.dbline 76
; asm("nop");
nop
.dbline 77
; asm("nop");
nop
.dbline 78
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline 79
; delay_nus(40);
ldi R16,40
ldi R17,0
.dbline -2
.dbline 80
; }
L1:
.dbline 0 ; func end
xjmp _delay_nus
.dbend
.dbfunc e LCD_Busy _LCD_Busy fV
; low -> R20
; high -> R22
; temp -> R10
.even
_LCD_Busy::
xcall push_gset3
.dbline -1
.dbline 85
; //*****************************************************//
; // This routine will return the busy flag from the LCD //
; //*****************************************************//
; void LCD_Busy ( void )
; {
.dbline 88
; unsigned char temp,high;
; unsigned char low;
; LCD_DIR_PORT = 0x0f; // Make I/O Port input
ldi R24,15
out 0x17,R24
L3:
.dbline 90
; do
; {
.dbline 91
; temp=LCD_OP_PORT;
in R10,0x18
.dbline 92
; temp=temp&BIT3;
mov R24,R10
andi R24,8
mov R10,R24
.dbline 93
; LCD_OP_PORT=temp;
out 0x18,R24
.dbline 94
; lcd_set_rw(); // Set LCD to READ
sbi 0x18,1
.dbline 95
; lcd_clear_rs();
cbi 0x18,0
.dbline 96
; lcd_set_e();
sbi 0x18,2
.dbline 97
; delay_nus(3);
ldi R16,3
ldi R17,0
xcall _delay_nus
.dbline 98
; high = LCD_IP_PORT; // read the high nibble.
in R22,0x16
.dbline 99
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline 100
; lcd_set_e();
sbi 0x18,2
.dbline 101
; asm("nop");
nop
.dbline 102
; asm("nop");
nop
.dbline 103
; low = LCD_IP_PORT; // read the low nibble.
in R20,0x16
.dbline 104
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline 105
L4:
.dbline 105
; } while(high & 0x80);
sbrc R22,7
rjmp L3
.dbline 106
; delay_nus(20);
ldi R16,20
ldi R17,0
xcall _delay_nus
.dbline -2
.dbline 107
; }
L2:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r low 20 c
.dbsym r high 22 c
.dbsym r temp 10 c
.dbend
.dbfunc e LCD_WriteControl _LCD_WriteControl fV
; temp -> R20
; CMD -> R22
.even
_LCD_WriteControl::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 112
; // ********************************************** //
; // *** Write a control instruction to the LCD *** //
; // ********************************************** //
; void LCD_WriteControl (unsigned char CMD)
; {
.dbline 114
; char temp;
; LCD_Busy(); // Test if LCD busy
xcall _LCD_Busy
.dbline 115
; LCD_DIR_PORT = 0xff; // LCD port output
ldi R24,255
out 0x17,R24
.dbline 116
; temp=LCD_OP_PORT;
in R20,0x18
.dbline 117
; temp=temp&BIT3;
andi R20,8
.dbline 118
; LCD_OP_PORT =(CMD & 0xf0)|temp; // Load high-data to port
mov R24,R22
andi R24,240
or R24,R20
out 0x18,R24
.dbline 119
; lcd_clear_rw(); // Set LCD to write
cbi 0x18,1
.dbline 120
; lcd_clear_rs(); // Set LCD to command
cbi 0x18,0
.dbline 121
; lcd_set_e(); // Write data to LCD
sbi 0x18,2
.dbline 122
; asm("nop");
nop
.dbline 123
; asm("nop");
nop
.dbline 124
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline 125
; LCD_OP_PORT =(CMD<<4)|temp; // Load low-data to port
mov R24,R22
andi R24,#0x0F
swap R24
or R24,R20
out 0x18,R24
.dbline 126
; lcd_clear_rw(); // Set LCD to write
cbi 0x18,1
.dbline 127
; lcd_clear_rs(); // Set LCD to command
cbi 0x18,0
.dbline 128
; lcd_set_e(); // Write data to LCD
sbi 0x18,2
.dbline 129
; asm("nop");
nop
.dbline 130
; asm("nop");
nop
.dbline 131
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline -2
.dbline 132
; }
L6:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r CMD 22 c
.dbend
.dbfunc e LCD_WriteData _LCD_WriteData fV
; temp -> R20
; Data -> R22
.even
_LCD_WriteData::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 137
; // ***************************************** //
; // *** Write one byte of data to the LCD *** //
; // ***************************************** //
; void LCD_WriteData (unsigned char Data)
; {
.dbline 139
; char temp;
; LCD_Busy(); // Test if LCD Busy
xcall _LCD_Busy
.dbline 140
; LCD_DIR_PORT = 0xFF; // LCD port output
ldi R24,255
out 0x17,R24
.dbline 141
; temp=LCD_OP_PORT;
in R20,0x18
.dbline 142
; temp=temp&BIT3;
andi R20,8
.dbline 143
; LCD_OP_PORT =(Data & 0xf0)|temp; // Load high-data to port
mov R24,R22
andi R24,240
or R24,R20
out 0x18,R24
.dbline 144
; lcd_clear_rw() ; // Set LCD to write
cbi 0x18,1
.dbline 145
; lcd_set_rs(); // Set LCD to data
sbi 0x18,0
.dbline 146
; lcd_set_e(); // Write data to LCD
sbi 0x18,2
.dbline 147
; asm("nop");
nop
.dbline 148
; asm("nop");
nop
.dbline 149
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline 150
; LCD_OP_PORT = (Data << 4)|temp; // Load low-data to port
mov R24,R22
andi R24,#0x0F
swap R24
or R24,R20
out 0x18,R24
.dbline 151
; lcd_clear_rw() ; // Set LCD to write
cbi 0x18,1
.dbline 152
; lcd_set_rs(); // Set LCD to data
sbi 0x18,0
.dbline 153
; lcd_set_e(); // Write data to LCD
sbi 0x18,2
.dbline 154
; asm("nop");
nop
.dbline 155
; asm("nop");
nop
.dbline 156
; lcd_clear_e(); // Disable LCD
cbi 0x18,2
.dbline -2
.dbline 157
; }
L7:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r Data 22 c
.dbend
.dbfunc e Init_LCD _Init_LCD fV
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -