📄 1602b_lcd.s
字号:
.module _1602B_LCD.c
.area text(rom, con, rel)
.dbfile D:\hujie\1602B_LCD.c
.dbfunc e LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 20
; // 1602B_LCD.c
; //
;
; /**********************************************************
; /* TC1602B LCD DISPLAY
; /* LCD_write函数功能:当command=0时,向LCD写入数据,否则向LCD写
; 入命令
; /* LCD第一行显示寄存器地址:0X80-0X8F
; /* LCD第二行显示寄存器地址:0XC0-0XCF
; /* 光标命令:
; /* LCD_write_char(0x0e,0); //光标开
; /* LCD_write_char(0x0d,0); //光标所在字符闪烁
; /* LCD_write_char(0x0c,0); //光标关
; **********************************************************/
; #include <io8515v.h>
; #include <macros.h>
; #include "1602LCD.h"
;
; void LCD_init(void)
; {
.dbline 21
; LCD_CTRL_DDR|=LCD_RS | LCD_EN | LCD_RW;
in R24,0x17
ori R24,14
out 0x17,R24
.dbline 22
; LCD_DATA_DDR|=LCD_DATA;
in R24,0x17
ori R24,240
out 0x17,R24
.dbline 23
; delay_nms(100);
ldi R16,100
ldi R17,0
rcall _delay_nms
.dbline 24
; LCD_write_char(0x28,0); //功能设置
clr R18
clr R19
ldi R16,40
ldi R17,0
rcall _LCD_write_char
.dbline 25
; delay_nus(100);
ldi R16,100
ldi R17,0
rcall _delay_nus
.dbline 26
; LCD_write_char(0x06,0); //显示光标移动设置
clr R18
clr R19
ldi R16,6
ldi R17,0
rcall _LCD_write_char
.dbline 27
; delay_nus(100);
ldi R16,100
ldi R17,0
rcall _delay_nus
.dbline 28
; LCD_write_char(0x01,0); //显示清屏
clr R18
clr R19
ldi R16,1
ldi R17,0
rcall _LCD_write_char
.dbline 29
; delay_nms(2);
ldi R16,2
ldi R17,0
rcall _delay_nms
.dbline 30
; LCD_write_char(0x0C,0); //显示开
clr R18
clr R19
ldi R16,12
ldi R17,0
rcall _LCD_write_char
.dbline 31
; delay_nus(100);
ldi R16,100
ldi R17,0
.dbline -2
.dbline 32
; }
L1:
.dbline 0 ; func end
rjmp _delay_nus
.dbend
.dbfunc e LCD_en_write _LCD_en_write fV
.even
_LCD_en_write::
.dbline -1
.dbline 35
;
; void LCD_en_write(void) //EN端产生一个高电平脉冲,写LCD
; {
.dbline 36
; LCD_EN_PORT |= LCD_EN;
sbi 0x18,3
.dbline 37
; delay_nus(5);
ldi R16,5
ldi R17,0
rcall _delay_nus
.dbline 38
; LCD_EN_PORT &= ~LCD_EN;
cbi 0x18,3
.dbline -2
.dbline 39
; }
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_write_char _LCD_write_char fV
; data_temp -> R22,R23
; command_temp -> R20,R21
; data -> R12,R13
; command -> R10,R11
.even
_LCD_write_char::
rcall push_gset4
mov R12,R18
mov R13,R19
mov R10,R16
mov R11,R17
.dbline -1
.dbline 49
;
; /****************************************************************
; /* LCD_write_char : 英文字符串显示函数
; /* 输入参数:*s :英文字符串指针?
; X、Y : 显示字符串的位置,X:0-15,Y:0-1
; LCD第一行显示寄存器地址:0X80-0X8F
; LCD第一行显示寄存器地址:0XC0-0XCF
; *****************************************************************/
; void LCD_write_char(unsigned command,unsigned data)
; {
.dbline 52
; unsigned command_temp,data_temp;
;
; command_temp = command;
mov R20,R10
mov R21,R11
.dbline 53
; data_temp = data;
mov R22,R12
mov R23,R13
.dbline 54
; LCD_wait_Ready();
rcall _LCD_wait_Ready
.dbline 55
; LCD_RW_PORT &= ~LCD_RW; //RW=0
cbi 0x18,2
.dbline 56
; if (command == 0)
cpi R20,0
cpc R20,R21
brne L4
X0:
.dbline 57
; {
.dbline 58
; LCD_RS_PORT |= LCD_RS; //RS=1
sbi 0x18,1
.dbline 59
; LCD_DATA_PORT &= 0X0F;
in R24,0x18
andi R24,15
out 0x18,R24
.dbline 60
; LCD_DATA_PORT |= data_temp&0xf0; //send high 4bit
mov R24,R22
mov R25,R23
andi R24,240
andi R25,0
in R2,0x18
clr R3
or R2,R24
or R3,R25
out 0x18,R2
.dbline 61
; }
rjmp L5
L4:
.dbline 63
; else
; {
.dbline 64
; LCD_RS_PORT &= ~LCD_RS; //RS=0
cbi 0x18,1
.dbline 65
; LCD_DATA_PORT &= 0X0F;
in R24,0x18
andi R24,15
out 0x18,R24
.dbline 66
; LCD_DATA_PORT |= command_temp&0xf0;//send high 4bit
mov R24,R20
mov R25,R21
andi R24,240
andi R25,0
in R2,0x18
clr R3
or R2,R24
or R3,R25
out 0x18,R2
.dbline 67
; }
L5:
.dbline 68
; LCD_en_write();
rcall _LCD_en_write
.dbline 69
; command_temp=command_temp << 4; //send low 4bit
lsl R20
rol R21
lsl R20
rol R21
lsl R20
rol R21
lsl R20
rol R21
.dbline 70
; data_temp=data_temp << 4;
lsl R22
rol R23
lsl R22
rol R23
lsl R22
rol R23
lsl R22
rol R23
.dbline 71
; LCD_DATA_PORT &= 0X0F;
in R24,0x18
andi R24,15
out 0x18,R24
.dbline 72
; if (command==0)
tst R10
brne L6
tst R11
brne L6
X1:
.dbline 73
; LCD_DATA_PORT |= data_temp&0xf0;
mov R24,R22
mov R25,R23
andi R24,240
andi R25,0
in R2,0x18
clr R3
or R2,R24
or R3,R25
out 0x18,R2
rjmp L7
L6:
.dbline 75
; else
; LCD_DATA_PORT |= command_temp&0xf0;
mov R24,R20
mov R25,R21
andi R24,240
andi R25,0
in R2,0x18
clr R3
or R2,R24
or R3,R25
out 0x18,R2
L7:
.dbline 76
; LCD_en_write();
rcall _LCD_en_write
.dbline 77
; LCD_RW_PORT |= LCD_RW;
sbi 0x18,2
.dbline 78
; LCD_RS_PORT ^= LCD_RS;
ldi R24,2
in R2,0x18
eor R2,R24
out 0x18,R2
.dbline -2
.dbline 79
; }
L3:
rcall pop_gset4
.dbline 0 ; func end
ret
.dbsym r data_temp 22 i
.dbsym r command_temp 20 i
.dbsym r data 12 i
.dbsym r command 10 i
.dbend
.dbfunc e LCD_wait_Ready _LCD_wait_Ready fV
.even
_LCD_wait_Ready::
.dbline -1
.dbline 82
;
; void LCD_wait_Ready(void) //等待LCD空闲
; {
.dbline 83
; LCD_DATA_DDR &= ~0x80; //PB7 I/O口方向设置为输入
cbi 0x17,7
.dbline 84
; LCD_RW_PORT |= LCD_RW; //RW=1
sbi 0x18,2
.dbline 85
; LCD_RS_PORT &= ~LCD_RS; //RS=0
cbi 0x18,1
.dbline 86
; LCD_EN_PORT |= LCD_EN; //EN=1
sbi 0x18,3
L9:
.dbline 87
L10:
.dbline 87
; while (!( LCD_DATA_PIN&0x80 ) == 0); //RW=1,读PD7,为0表示空闲;
sbic 0x16,7
rjmp L12
ldi R16,1
ldi R17,0
rjmp L13
L12:
clr R16
clr R17
L13:
cpi R16,0
cpc R16,R17
breq L9
X2:
.dbline 88
; LCD_EN_PORT &= ~LCD_EN; //EN=0
cbi 0x18,3
.dbline 89
; LCD_DATA_DDR |= 0xf0;
in R24,0x17
ori R24,240
out 0x17,R24
.dbline -2
.dbline 90
; }
L8:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_set_xy _LCD_set_xy fV
; address -> R20
; y -> R20
; x -> R22
.even
_LCD_set_xy::
rcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 99
;
; /**********************************************************
; /* LCD_set_xy : 设置LCD显示的起始位置
; /* 输入参数:x、y : 显示字符串的位置,X:0-15,Y:0-1
; LCD第一行显示寄存器地址:0X80-0X8F
; LCD第一行显示寄存器地址:0XC0-0XCF
; ***********************************************************/
; void LCD_set_xy( unsigned char x, unsigned char y )
; {
.dbline 101
; unsigned char address;
; if (y == 0) address = 0x80 + x;
tst R20
brne L15
.dbline 101
mov R20,R22
subi R20,128 ; addi 128
rjmp L16
L15:
.dbline 103
; else
; address = 0xC0 + x;
mov R20,R22
subi R20,64 ; addi 192
L16:
.dbline 104
; LCD_write_char( address, 0 );
clr R18
clr R19
mov R16,R20
clr R17
rcall _LCD_write_char
.dbline -2
.dbline 105
; }
L14:
rcall 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::
rcall push_gset3
mov R10,R18
mov R22,R16
ldd R20,y+6
ldd R21,y+7
.dbline -1
.dbline 112
; /**********************************************************
; /* LCD_write_string : 英文字符串显示函数
; /* 输入参数:*s :英文字符串指针;
; /* X、Y : 显示字符串的位置
; ***********************************************************/
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
; {
.dbline 113
; LCD_set_xy( X, Y );
mov R18,R10
mov R16,R22
rcall _LCD_set_xy
rjmp L19
L18:
.dbline 115
.dbline 116
mov R30,R20
mov R31,R21
ldd R18,z+0
clr R19
clr R16
clr R17
rcall _LCD_write_char
.dbline 117
subi R20,255 ; offset = 1
sbci R21,255
.dbline 118
L19:
.dbline 114
; while (*s)
mov R30,R20
mov R31,R21
ldd R2,z+0
tst R2
brne L18
.dbline -2
.dbline 119
; {
; LCD_write_char( 0, *s );
; s ++;
; }
; }
L17:
rcall 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 _LCD_write fV
; data -> y+4
; Y -> R22
; X -> R20
.even
_LCD_write::
rcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 126
; /**********************************************************
; /* LCD_write : 英文字符显示函数
; /* 输入参数:data :英文字符
; /* X、Y : 显示字符的位置
; ***********************************************************/
; void LCD_write(unsigned char X, unsigned char Y,unsigned data)
; {
.dbline 127
; LCD_set_xy( X, Y );
mov R18,R22
mov R16,R20
rcall _LCD_set_xy
.dbline 128
; LCD_write_char(0, data);
ldd R18,y+4
ldd R19,y+5
clr R16
clr R17
rcall _LCD_write_char
.dbline -2
.dbline 129
; }
L21:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l data 4 i
.dbsym r Y 22 c
.dbsym r X 20 c
.dbend
.dbfunc e LCD_clr _LCD_clr fV
.even
_LCD_clr::
.dbline -1
.dbline 134
; /**********************************************************
; /* LCD_clr : 清屏函数
; ***********************************************************/
; void LCD_clr(void)
; {
.dbline 135
; LCD_write_char(0x01,0);
clr R18
clr R19
ldi R16,1
ldi R17,0
rcall _LCD_write_char
.dbline 136
; delay_nms(2);
ldi R16,2
ldi R17,0
.dbline -2
.dbline 137
; }
L22:
.dbline 0 ; func end
rjmp _delay_nms
.dbend
.dbfunc e LCD_display _LCD_display fV
; temp -> R10
; i -> R12
; data -> y+18
; data_length -> R14
; y -> y+14
; x -> y+12
.even
_LCD_display::
rcall push_arg4
rcall push_gset5
sbiw R28,2
ldd R14,y+16
.dbline -1
.dbline 147
; /**********************************************************
; /* LCD_display
; /* 在LCD具体位置开始,显示一段长度不超过5的数值,如54321
; /* x——列值
; /* y——行值
; /* data_length——数值长度<11
; /* data ——数值内容
; ***********************************************************/
; void LCD_display(unsigned char x,unsigned char y,unsigned char data_length,unsigned long int data)
; {
.dbline 149
; unsigned char i,temp;
; for(i=0;i<data_length;i++)
clr R12
rjmp L27
L24:
.dbline 150
.dbline 151
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
mov R30,R28
mov R31,R29
ldd R2,z+18
ldd R3,z+19
ldd R4,z+20
ldd R5,z+21
st -y,R23
st -y,R22
st -y,R21
st -y,R20
mov R16,R2
mov R17,R3
mov R18,R4
mov R19,R5
rcall mod32u
mov R10,R16
.dbline 152
mov R24,R10
clr R25
adiw R24,48
std y+1,R25
std y+0,R24
ldd R18,y+14
mov R16,R14
ldd R0,y+12
add R16,R0
sub R16,R12
subi R16,1
rcall _LCD_write
.dbline 153
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
mov R30,R28
mov R31,R29
ldd R2,z+18
ldd R3,z+19
ldd R4,z+20
ldd R5,z+21
st -y,R23
st -y,R22
st -y,R21
st -y,R20
mov R16,R2
mov R17,R3
mov R18,R4
mov R19,R5
rcall div32u
mov R30,R28
mov R31,R29
std z+18,R16
std z+19,R17
std z+20,R18
std z+21,R19
.dbline 154
L25:
.dbline 149
inc R12
L27:
.dbline 149
cp R12,R14
brsh X3
rjmp L24
X3:
.dbline -2
.dbline 155
; {
; temp=data%10;
; LCD_write(data_length+x-i-1,y,'0'+temp);
; data=data/10;
; }
; }
L23:
adiw R28,2
rcall pop_gset5
adiw R28,4
.dbline 0 ; func end
ret
.dbsym r temp 10 c
.dbsym r i 12 c
.dbsym l data 18 l
.dbsym r data_length 14 c
.dbsym l y 14 c
.dbsym l x 12 c
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -