📄 lcd.s
字号:
.module lcd.c
.area text(rom, con, rel)
.dbfile F:\开发\C程序开发\AVR\motor\lcd.c
.dbfunc e delay _delay fV
; i -> R20,R21
; n -> R16,R17
.even
_delay::
xcall push_gset1
.dbline -1
.dbline 54
; //编译器:ICC-AVR
; //日期: 2007-4-13 20:29:57
; //目标芯片 : ATmega16
; //时钟: 8.0000Mhz
; //版本:VISION 2.0
; /*
; LCD引脚定义
; 1---GND
; 2---VCC
; 3---VO
; 4---RS
; 5---RW
; 6---EN
; 7到14--D0-D7
; 15--背景灯+
; 16--背景灯-
;
; 下面是AVR与LCD连接信息
; PA1 ->RS
; PA0 ->EN
; GND ->RW
; PA4 ->D4
; PA5 ->D5
; PA6 ->D6
; PA7 ->D7
; */
;
;
; #include "main.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<<PA1) //0x04 portA1 out
; #define LCD_EN (1<<PA0) //0x08 portA0 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 57
clr R20
clr R21
xjmp L8
L5:
.dbline 57
L6:
.dbline 57
subi R20,255 ; offset = 1
sbci R21,255
L8:
.dbline 57
cpi R20,125
ldi R30,0
cpc R21,R30
brlo L5
L3:
.dbline 56
; 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 61
; for (i=0;i<125;i++);
; }
;
; void LCD_init(void) //液晶初始化
; {
.dbline 62
; LCD_DATA_DDR|=LCD_DATA; //数据口方向为输出
in R24,0x1a
ori R24,240
out 0x1a,R24
.dbline 63
; LCD_EN_DDR|=LCD_EN; //设置EN方向为输出
sbi 0x1a,0
.dbline 64
; LCD_RS_DDR|=LCD_RS; //设置RS方向为输出
sbi 0x1a,1
.dbline 65
; LCD_write_command(0x28);
ldi R16,40
xcall _LCD_write_command
.dbline 66
; LCD_en_write();
xcall _LCD_en_write
.dbline 67
; delay(40);
ldi R16,40
ldi R17,0
xcall _delay
.dbline 68
; LCD_write_command(0x28); //4位显示
ldi R16,40
xcall _LCD_write_command
.dbline 69
; LCD_write_command(0x0c); //显示开
ldi R16,12
xcall _LCD_write_command
.dbline 70
; LCD_write_command(0x01); //清屏
ldi R16,1
xcall _LCD_write_command
.dbline 71
; 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 75
; }
;
; void LCD_en_write(void) //液晶使能
; {
.dbline 76
; LCD_EN_PORT|=LCD_EN;
sbi 0x1b,0
.dbline 77
; delay(1);
ldi R16,1
ldi R17,0
xcall _delay
.dbline 78
; LCD_EN_PORT&=~LCD_EN;
cbi 0x1b,0
.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 82
; }
;
; void LCD_write_command(uchar command) //写指令
; {
.dbline 83
; delay(16);
ldi R16,16
ldi R17,0
xcall _delay
.dbline 84
; LCD_RS_PORT&=~LCD_RS; //RS=0
cbi 0x1b,1
.dbline 85
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 86
; LCD_DATA_PORT|=command&0xf0; //写高四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 87
; LCD_en_write();
xcall _LCD_en_write
.dbline 88
; command=command<<4; //低四位移到高四位
mov R24,R20
andi R24,#0x0F
swap R24
mov R20,R24
.dbline 89
; LCD_DATA_PORT&=0x0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 90
; LCD_DATA_PORT|=command&0xf0; //写低四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 91
; 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 96
;
; }
;
; void LCD_write_data(uchar data) //写数据
; {
.dbline 97
; delay(16);
ldi R16,16
ldi R17,0
xcall _delay
.dbline 98
; LCD_RS_PORT|=LCD_RS; //RS=1
sbi 0x1b,1
.dbline 99
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 100
; LCD_DATA_PORT|=data&0xf0; //写高四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 101
; LCD_en_write();
xcall _LCD_en_write
.dbline 102
; data=data<<4; //低四位移到高四位
mov R24,R20
andi R24,#0x0F
swap R24
mov R20,R24
.dbline 103
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 104
; LCD_DATA_PORT|=data&0xf0; //写低四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 105
; 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 110
; }
;
;
; void LCD_set_xy( uchar x, uchar y ) //写地址函数
; {
.dbline 112
; uchar address;
; if (y == 0) address = 0x80 + x;
tst R20
brne L14
.dbline 112
mov R20,R22
subi R20,128 ; addi 128
xjmp L15
L14:
.dbline 113
; else address = 0xc0 + x;
mov R20,R22
subi R20,64 ; addi 192
L15:
.dbline 114
; 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 118
; }
;
; void LCD_write_string(uchar X,uchar Y,uchar *s) //列x=0~15,行y=0,1
; {
.dbline 119
; LCD_set_xy( X, Y ); //写地址
mov R18,R10
mov R16,R22
xcall _LCD_set_xy
xjmp L18
L17:
.dbline 121
.dbline 122
movw R30,R20
ldd R16,z+0
xcall _LCD_write_data
.dbline 123
subi R20,255 ; offset = 1
sbci R21,255
.dbline 124
L18:
.dbline 120
; 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 129
; {
; LCD_write_data( *s );
; s ++;
; }
;
; }
;
; void LCD_write_char(uchar X,uchar Y,uchar data) //列x=0~15,行y=0,1
; {
.dbline 130
; LCD_set_xy( X, Y ); //写地址
mov R18,R22
mov R16,R20
xcall _LCD_set_xy
.dbline 131
; 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_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 136
;
; }
;
; void init_devices(void)
; {
.dbline 137
; CLI(); //disable all interrupts
cli
.dbline 138
; LCD_init();
xcall _LCD_init
.dbline 139
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 140
; GICR = 0x00;
out 0x3b,R2
.dbline 141
; TIMSK = 0x00; // r interrupt sources
out 0x39,R2
.dbline 142
; SEI(); //re-enable interrupts
sei
.dbline -2
L21:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -