📄 lcd.s
字号:
.module LCD.c
.area text(rom, con, rel)
.dbfile D:\ICCAVR~1\模块化~1\src\LCD.c
.dbfunc e LCD_INIT _LCD_INIT fV
.even
_LCD_INIT::
.dbline -1
.dbline 52
; // ************************************************
; // *** LCD_4BIT Driver V1.1 ***
; // *** LCD.C ***
; // ************************************************
; #include "common.h"
;
; #define LCD_C
; // ***** 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 PORTD
; #define LCD_IP_PORT PIND
; #define LCD_DIR_PORT DDRD
; // *** 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 0x11,R24
.dbline 54
; LCD_OP_PORT = 0x30; // Load high-data to port
ldi R24,48
out 0x12,R24
.dbline 55
; lcd_clear_rw(); // Set LCD to write
cbi 0x12,1
.dbline 56
; lcd_clear_rs(); // Set LCD to command
cbi 0x12,0
.dbline 57
; lcd_set_e(); // Write data to LCD
sbi 0x12,2
.dbline 58
; asm("nop");
nop
.dbline 59
; asm("nop");
nop
.dbline 60
; lcd_clear_e(); // Disable LCD
cbi 0x12,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 0x12,1
.dbline 63
; lcd_clear_rs(); // Set LCD to command
cbi 0x12,0
.dbline 64
; lcd_set_e(); // Write data to LCD
sbi 0x12,2
.dbline 65
; asm("nop");
nop
.dbline 66
; asm("nop");
nop
.dbline 67
; lcd_clear_e(); // Disable LCD
cbi 0x12,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 0x12,2
.dbline 70
; asm("nop");
nop
.dbline 71
; asm("nop");
nop
.dbline 72
; lcd_clear_e(); // Disable LCD
cbi 0x12,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 0x12,R24
.dbline 75
; lcd_set_e(); // Write data to LCD
sbi 0x12,2
.dbline 76
; asm("nop");
nop
.dbline 77
; asm("nop");
nop
.dbline 78
; lcd_clear_e(); // Disable LCD
cbi 0x12,2
.dbline 79
; delay_nus(40);
ldi R16,40
ldi R17,0
xcall _delay_nus
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_Busy _LCD_Busy fV
; low -> R12
; high -> R10
; temp -> R20
.even
_LCD_Busy::
xcall push_xgset303C
.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 0x11,R24
L3:
.dbline 90
; do
; {
.dbline 91
; temp=LCD_OP_PORT;
in R20,0x12
.dbline 92
; temp=temp&BIT3;
andi R20,8
.dbline 93
; LCD_OP_PORT=temp;
out 0x12,R20
.dbline 94
; lcd_set_rw(); // Set LCD to READ
sbi 0x12,1
.dbline 95
; lcd_clear_rs();
cbi 0x12,0
.dbline 96
; lcd_set_e();
sbi 0x12,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 R10,0x10
.dbline 99
; lcd_clear_e(); // Disable LCD
cbi 0x12,2
.dbline 100
; lcd_set_e();
sbi 0x12,2
.dbline 101
; asm("nop");
nop
.dbline 102
; asm("nop");
nop
.dbline 103
; low = LCD_IP_PORT; // read the low nibble.
in R12,0x10
.dbline 104
; lcd_clear_e(); // Disable LCD
cbi 0x12,2
.dbline 105
; } while(high & 0x80);
L4:
.dbline 105
sbrc R10,7
rjmp L3
X0:
.dbline 106
; delay_nus(20);
ldi R16,20
ldi R17,0
xcall _delay_nus
.dbline -2
L2:
.dbline 0 ; func end
xjmp pop_xgset303C
.dbsym r low 12 c
.dbsym r high 10 c
.dbsym r temp 20 c
.dbend
.dbfunc e LCD_WriteControl _LCD_WriteControl fV
; temp -> R20
; CMD -> R22
.even
_LCD_WriteControl::
st -y,R20
st -y,R22
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 0x11,R24
.dbline 116
; temp=LCD_OP_PORT;
in R20,0x12
.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 0x12,R24
.dbline 119
; lcd_clear_rw(); // Set LCD to write
cbi 0x12,1
.dbline 120
; lcd_clear_rs(); // Set LCD to command
cbi 0x12,0
.dbline 121
; lcd_set_e(); // Write data to LCD
sbi 0x12,2
.dbline 122
; asm("nop");
nop
.dbline 123
; asm("nop");
nop
.dbline 124
; lcd_clear_e(); // Disable LCD
cbi 0x12,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 0x12,R24
.dbline 126
; lcd_clear_rw(); // Set LCD to write
cbi 0x12,1
.dbline 127
; lcd_clear_rs(); // Set LCD to command
cbi 0x12,0
.dbline 128
; lcd_set_e(); // Write data to LCD
sbi 0x12,2
.dbline 129
; asm("nop");
nop
.dbline 130
; asm("nop");
nop
.dbline 131
; lcd_clear_e(); // Disable LCD
cbi 0x12,2
.dbline -2
L6:
.dbline 0 ; func end
ld R22,y+
ld R20,y+
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::
st -y,R20
st -y,R22
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 0x11,R24
.dbline 141
; temp=LCD_OP_PORT;
in R20,0x12
.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 0x12,R24
.dbline 144
; lcd_clear_rw() ; // Set LCD to write
cbi 0x12,1
.dbline 145
; lcd_set_rs(); // Set LCD to data
sbi 0x12,0
.dbline 146
; lcd_set_e(); // Write data to LCD
sbi 0x12,2
.dbline 147
; asm("nop");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -