📄 lcd.s
字号:
.module lcd.c
.area text(rom, con, rel)
.dbfile E:\尤虎\程序设计\AVR单片机\MAGE16\ADCAND~1\lcd.c
.dbfunc e delay _delay fV
; i -> R20,R21
; n -> R16,R17
.even
_delay::
xcall push_gset1
.dbline -1
.dbline 27
; #include <iom16v.h>
; #include <macros.h>
;
; #define uchar unsigned char
; #define uint unsigned int
;
; #define LCD_EN_PORT PORTA //数据寄存器,以下2个要设为同一个口
; #define LCD_EN_DDR DDRA //数据方向寄存器
; #define LCD_RS_PORT PORTA //以下2个要设为同一个口
; #define LCD_RS_DDR DDRA
; #define LCD_DATA_PORT PORTA //以下3个要设为同一个口
; #define LCD_DATA_DDR DDRA //一定要用高4位
; #define LCD_DATA_PIN PINA //端口输入引脚
; #define LCD_RS (1<<PA3) //0x04 portA3 out
; #define LCD_EN (1<<PA2) //0x08 portA2 out
; #define LCD_DATA ((1<<PA4)|(1<<PA5)|(1<<PA6)|(1<<PA7)) //0xf0 portA4/5/6/7 out
;
;
;
; void LCD_init(void);
; void LCD_en_write(void);
; void LCD_write_command(uchar command);
; void LCD_write_data(uchar data);
; void LCD_set_xy (uchar x, uchar y);
;
; void delay(uint n) //N ms延时函数
; {
xjmp L3
L2:
.dbline 30
clr R20
clr R21
xjmp L8
L5:
.dbline 30
L6:
.dbline 30
subi R20,255 ; offset = 1
sbci R21,255
L8:
.dbline 30
cpi R20,125
ldi R30,0
cpc R21,R30
brlo L5
L3:
.dbline 29
; uint i;
; while(n--)
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L2
tst R3
brne L2
X0:
.dbline -2
L1:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r n 16 i
.dbend
.dbfunc e LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 34
; for (i=0;i<125;i++);
; }
;
; void LCD_init(void) //液晶初始化
; {
.dbline 35
; LCD_DATA_DDR|=LCD_DATA; //数据口方向为输出
in R24,0x1a
ori R24,240
out 0x1a,R24
.dbline 36
; LCD_EN_DDR|=LCD_EN; //设置EN方向为输出
sbi 0x1a,2
.dbline 37
; LCD_RS_DDR|=LCD_RS; //设置RS方向为输出
sbi 0x1a,3
.dbline 38
; LCD_write_command(0x28);
ldi R16,40
xcall _LCD_write_command
.dbline 39
; LCD_en_write();
xcall _LCD_en_write
.dbline 40
; delay(40);
ldi R16,40
ldi R17,0
xcall _delay
.dbline 41
; LCD_write_command(0x28); //4位显示
ldi R16,40
xcall _LCD_write_command
.dbline 42
; LCD_write_command(0x0c); //显示开
ldi R16,12
xcall _LCD_write_command
.dbline 43
; LCD_write_command(0x01); //清屏
ldi R16,1
xcall _LCD_write_command
.dbline 44
; delay(2);
ldi R16,2
ldi R17,0
xcall _delay
.dbline -2
L9:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_en_write _LCD_en_write fV
.even
_LCD_en_write::
.dbline -1
.dbline 48
; }
;
; void LCD_en_write(void) //液晶使能
; {
.dbline 49
; LCD_EN_PORT|=LCD_EN;
sbi 0x1b,2
.dbline 50
; delay(1);
ldi R16,1
ldi R17,0
xcall _delay
.dbline 51
; LCD_EN_PORT&=~LCD_EN;
cbi 0x1b,2
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_write_command _LCD_write_command fV
; command -> R20
.even
_LCD_write_command::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 55
; }
;
; void LCD_write_command(uchar command) //写指令
; {
.dbline 56
; delay(16);
ldi R16,16
ldi R17,0
xcall _delay
.dbline 57
; LCD_RS_PORT&=~LCD_RS; //RS=0
cbi 0x1b,3
.dbline 58
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 59
; LCD_DATA_PORT|=command&0xf0; //写高四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 60
; LCD_en_write();
xcall _LCD_en_write
.dbline 61
; command=command<<4; //低四位移到高四位
mov R24,R20
andi R24,#0x0F
swap R24
mov R20,R24
.dbline 62
; LCD_DATA_PORT&=0x0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 63
; LCD_DATA_PORT|=command&0xf0; //写低四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 64
; LCD_en_write();
xcall _LCD_en_write
.dbline -2
L11:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r command 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 69
;
; }
;
; void LCD_write_data(uchar data) //写数据
; {
.dbline 70
; delay(16);
ldi R16,16
ldi R17,0
xcall _delay
.dbline 71
; LCD_RS_PORT|=LCD_RS; //RS=1
sbi 0x1b,3
.dbline 72
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 73
; LCD_DATA_PORT|=data&0xf0; //写高四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 74
; LCD_en_write();
xcall _LCD_en_write
.dbline 75
; data=data<<4; //低四位移到高四位
mov R24,R20
andi R24,#0x0F
swap R24
mov R20,R24
.dbline 76
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 77
; LCD_DATA_PORT|=data&0xf0; //写低四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 78
; LCD_en_write();
xcall _LCD_en_write
.dbline -2
L12:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e LCD_set_xy _LCD_set_xy fV
; address -> R20
; y -> R20
; x -> R22
.even
_LCD_set_xy::
xcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 83
; }
;
;
; void LCD_set_xy( uchar x, uchar y ) //写地址函数
; {
.dbline 85
; uchar address;
; if (y == 0) address = 0x80 + x;
tst R20
brne L14
.dbline 85
mov R20,R22
subi R20,128 ; addi 128
xjmp L15
L14:
.dbline 86
; else address = 0xc0 + x;
mov R20,R22
subi R20,64 ; addi 192
L15:
.dbline 87
; LCD_write_command( address);
mov R16,R20
xcall _LCD_write_command
.dbline -2
L13:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r address 20 c
.dbsym r y 20 c
.dbsym r x 22 c
.dbend
.dbfunc e LCD_write_string _LCD_write_string fV
; s -> R20,R21
; Y -> R10
; X -> R22
.even
_LCD_write_string::
xcall push_gset3
mov R10,R18
mov R22,R16
ldd R20,y+6
ldd R21,y+7
.dbline -1
.dbline 91
; }
;
; void LCD_write_string(uchar X,uchar Y,uchar *s) //列x=0~15,行y=0,1
; {
.dbline 92
; LCD_set_xy( X, Y ); //写地址
mov R18,R10
mov R16,R22
xcall _LCD_set_xy
xjmp L18
L17:
.dbline 94
.dbline 95
movw R30,R20
ldd R16,z+0
xcall _LCD_write_data
.dbline 96
subi R20,255 ; offset = 1
sbci R21,255
.dbline 97
L18:
.dbline 93
; while (*s) // 写显示字符
movw R30,R20
ldd R2,z+0
tst R2
brne L17
.dbline -2
L16:
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 102
; {
; LCD_write_data( *s );
; s ++;
; }
;
; }
;
; void LCD_write_char(uchar X,uchar Y,uchar data) //列x=0~15,行y=0,1
; {
.dbline 103
; LCD_set_xy( X, Y ); //写地址
mov R18,R22
mov R16,R20
xcall _LCD_set_xy
.dbline 104
; LCD_write_data( data);
ldd R16,y+4
xcall _LCD_write_data
.dbline -2
L20:
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 init_lcd _init_lcd fV
.even
_init_lcd::
.dbline -1
.dbline 109
;
; }
;
; void init_lcd(void)
; {
.dbline 110
; CLI(); //禁止所有中断
cli
.dbline 111
; LCD_init();
xcall _LCD_init
.dbline 112
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 113
; GICR = 0x00;
out 0x3b,R2
.dbline 114
; TIMSK = 0x00;
out 0x39,R2
.dbline 115
; SEI(); //重新开启所有中断
sei
.dbline -2
L21:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -