📄 lcd1602.s
字号:
.module lcd1602.c
.area text(rom, con, rel)
.dbfile E:\ICCAVR\project\AVRMEG~3\icc\017-LCD1602\lcd1602.c
.dbfunc e delay_us _delay_us fV
; n -> R16,R17
.even
_delay_us::
.dbline -1
.dbline 25
; /*
; LCD1602液晶屏驱动模块
; 1、可直接嵌入到项目中使用
; 2、晶振频率:1M
; 3、如晶振提高低层驱动延时要作相应修改
;
; AVR_AFA
; www.iccavr.com
; 程序编写过程中参照了peak的4线显示程序
; peak:AVR论坛技术版版主
; */
;
; #include <iom128v.h>
;
; #define RS_CLR PORTC &= ~(1 << PC2)
; #define RS_SET PORTC |= (1 << PC2)
;
; #define RW_CLR PORTC &= ~(1 << PC3)
; #define RW_SET PORTC |= (1 << PC3)
;
; #define EN_CLR PORTC &= ~(1 << PC4)
; #define EN_SET PORTC |= (1 << PC4)
;
; /*延时函数*/
; void delay_us(unsigned int n) {
.dbline 27
;
; if (n == 0) {
cpi R16,0
cpc R16,R17
brne L5
X0:
.dbline 27
.dbline 28
; return ;
xjmp L1
L4:
.dbline 30
L5:
.dbline 30
; }
; while (--n);
movw R24,R16
sbiw R24,1
movw R16,R24
cpi R16,0
cpc R16,R17
brne L4
X1:
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r n 16 i
.dbend
.dbfunc e delay_ms _delay_ms fV
; a -> R20
; b -> R22
; i -> R16
.even
_delay_ms::
xcall push_gset2
.dbline -1
.dbline 34
; }
;
; /*延时函数*/
; void delay_ms(unsigned char i) {
.dbline 37
ldi R20,1
xjmp L11
L8:
.dbline 37
;
; unsigned char a, b;
; for (a = 1; a < i; a++) {
.dbline 38
ldi R22,1
xjmp L15
L12:
.dbline 38
.dbline 39
.dbline 40
L13:
.dbline 38
inc R22
L15:
.dbline 38
tst R22
brne L12
.dbline 41
L9:
.dbline 37
inc R20
L11:
.dbline 37
cp R20,R16
brlo L8
.dbline -2
L7:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r a 20 c
.dbsym r b 22 c
.dbsym r i 16 c
.dbend
.dbfunc e LCD_write_com _LCD_write_com fV
; com -> R20
.even
_LCD_write_com::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 45
; for (b = 1; b; b++) {
; ;
; }
; }
; }
;
; /*显示屏命令写入函数*/
; void LCD_write_com(unsigned char com) {
.dbline 47
;
; RS_CLR;
cbi 0x15,2
.dbline 48
; RW_CLR;
cbi 0x15,3
.dbline 49
; EN_SET;
sbi 0x15,4
.dbline 50
; PORTA = com;
out 0x1b,R20
.dbline 51
; delay_us(5);
ldi R16,5
ldi R17,0
xcall _delay_us
.dbline 52
; EN_CLR;
cbi 0x15,4
.dbline -2
L16:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r com 20 c
.dbend
.dbfunc e LCD_write_data _LCD_write_data fV
; data -> R20
.even
_LCD_write_data::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 56
; }
;
; /*显示屏命令写入函数*/
; void LCD_write_data(unsigned char data) {
.dbline 58
;
; RS_SET;
sbi 0x15,2
.dbline 59
; RW_CLR;
cbi 0x15,3
.dbline 60
; EN_SET;
sbi 0x15,4
.dbline 61
; PORTA = data;
out 0x1b,R20
.dbline 62
; delay_us(5);
ldi R16,5
ldi R17,0
xcall _delay_us
.dbline 63
; EN_CLR;
cbi 0x15,4
.dbline -2
L17:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e LCD_clear _LCD_clear fV
.even
_LCD_clear::
.dbline -1
.dbline 67
; }
;
; /*显示屏清空显示*/
; void LCD_clear(void) {
.dbline 69
;
; LCD_write_com(0x01);
ldi R16,1
xcall _LCD_write_com
.dbline 70
; delay_ms(5);
ldi R16,5
xcall _delay_ms
.dbline -2
L18:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_write_str _LCD_write_str fV
; s -> R20,R21
; y -> R10
; x -> R22
.even
_LCD_write_str::
xcall push_gset3
mov R10,R18
mov R22,R16
ldd R20,y+6
ldd R21,y+7
.dbline -1
.dbline 74
; }
;
; /*显示屏字符串写入函数*/
; void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s) {
.dbline 76
;
; if (y == 0) {
tst R10
brne L20
.dbline 76
.dbline 77
; LCD_write_com(0x80 + x);
mov R16,R22
subi R16,128 ; addi 128
xcall _LCD_write_com
.dbline 78
; }
xjmp L23
L20:
.dbline 79
; else {
.dbline 80
; LCD_write_com(0xC0 + x);
mov R16,R22
subi R16,64 ; addi 192
xcall _LCD_write_com
.dbline 81
; }
xjmp L23
L22:
.dbline 83
.dbline 84
movw R30,R20
ldd R16,z+0
xcall _LCD_write_data
.dbline 85
subi R20,255 ; offset = 1
sbci R21,255
.dbline 86
L23:
.dbline 83
;
; while (*s) {
movw R30,R20
ldd R2,z+0
tst R2
brne L22
.dbline -2
L19:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r s 20 pc
.dbsym r y 10 c
.dbsym r x 22 c
.dbend
.dbfunc e LCD_write_char _LCD_write_char fV
; data -> y+4
; y -> R22
; x -> R20
.even
_LCD_write_char::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 90
; LCD_write_data( *s);
; s ++;
; }
; }
;
; /*显示屏单字符写入函数*/
; void LCD_write_char(unsigned char x,unsigned char y,unsigned char data) {
.dbline 92
;
; if (y == 0) {
tst R22
brne L26
.dbline 92
.dbline 93
; LCD_write_com(0x80 + x);
mov R16,R20
subi R16,128 ; addi 128
xcall _LCD_write_com
.dbline 94
; }
xjmp L27
L26:
.dbline 95
; else {
.dbline 96
; LCD_write_com(0xC0 + x);
mov R16,R20
subi R16,64 ; addi 192
xcall _LCD_write_com
.dbline 97
; }
L27:
.dbline 99
;
; LCD_write_data( data);
ldd R16,y+4
xcall _LCD_write_data
.dbline -2
L25:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l data 4 c
.dbsym r y 22 c
.dbsym r x 20 c
.dbend
.dbfunc e LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 103
; }
;
; /*显示屏初始化函数*/
; void LCD_init(void) {
.dbline 105
;
; DDRA = 0xFF; /*I/O口方向设置*/
ldi R24,255
out 0x1a,R24
.dbline 106
; DDRC = 0xFF;
out 0x14,R24
.dbline 107
; LCD_write_com(0x38); /*显示模式设置*/
ldi R16,56
xcall _LCD_write_com
.dbline 108
; delay_ms(5);
ldi R16,5
xcall _delay_ms
.dbline 109
; LCD_write_com(0x38);
ldi R16,56
xcall _LCD_write_com
.dbline 110
; delay_ms(5);
ldi R16,5
xcall _delay_ms
.dbline 111
; LCD_write_com(0x38);
ldi R16,56
xcall _LCD_write_com
.dbline 112
; delay_ms(5);
ldi R16,5
xcall _delay_ms
.dbline 113
; LCD_write_com(0x38);
ldi R16,56
xcall _LCD_write_com
.dbline 115
;
; LCD_write_com(0x08); /*显示关闭*/
ldi R16,8
xcall _LCD_write_com
.dbline 116
; LCD_write_com(0x01); /*显示清屏*/
ldi R16,1
xcall _LCD_write_com
.dbline 117
; LCD_write_com(0x06); /*显示光标移动设置*/
ldi R16,6
xcall _LCD_write_com
.dbline 118
; delay_ms(5);
ldi R16,5
xcall _delay_ms
.dbline 119
; LCD_write_com(0x0C); /*显示开及光标设置*/
ldi R16,12
xcall _LCD_write_com
.dbline -2
L28:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -