📄 1602b_lcd.s
字号:
.module _1602B_LCD.c
.area text(rom, con, rel)
.dbfile D:\test6\1602B_LCD.c
.dbfunc e LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 21
; #include <iom8v.h>
; #include <macros.h>
; #include "1602LCD.h"
;
; /**********************************************************
; 光标命令
; LCD_write_char(0x0e,0); //光标开
; LCD_write_char(0x0d,0); //光标所在字符闪烁
; LCD_write_char(0x0c,0); //光标关
; **********************************************************/
; /**********************************************************
; TC1602B LCD DISPLAY
; 建立时间:2003年11月9号
; 修改日期:2003年11月14号
; LCD_write函数功能:当command=0时,向LCD写入数据,否则向LCD写
; 入命令
; LCD第一行显示寄存器地址:0X80-0X8F
; LCD第二行显示寄存器地址:0XC0-0XCF
; **********************************************************/
; void LCD_init(void)
; {
.dbline 22
; delay_nms(15);
ldi R16,15
ldi R17,0
rcall _delay_nms
.dbline 24
;
; LCD_write_char(0x28,0); //4bit test
clr R18
clr R19
ldi R16,40
ldi R17,0
rcall _LCD_write_char
.dbline 25
; LCD_write_char(0x0c,0); //显示开
clr R18
clr R19
ldi R16,12
ldi R17,0
rcall _LCD_write_char
.dbline 26
; LCD_write_char(0x01,0); //显示清屏
clr R18
clr R19
ldi R16,1
ldi R17,0
rcall _LCD_write_char
.dbline 27
; LCD_write_char(0x06,0); //显示光标移动设置
clr R18
clr R19
ldi R16,6
ldi R17,0
rcall _LCD_write_char
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_en_write _LCD_en_write fV
.even
_LCD_en_write::
.dbline -1
.dbline 31
; }
;
; void LCD_en_write(void) //EN端产生一个高电平脉冲,写LCD
; {
.dbline 32
; LCD_EN_PORT |= LCD_EN;
sbi 0x15,5
.dbline 33
; delay_nus(1);
ldi R16,1
ldi R17,0
rcall _delay_nus
.dbline 34
; LCD_EN_PORT &= ~LCD_EN;
cbi 0x15,5
.dbline -2
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
movw R12,R18
movw R10,R16
.dbline -1
.dbline 49
; }
;
; /*-----------------------------------------------------------------------
; LCD_write_char : 英文字符串显示函数
;
; 输入参数:*s :英文字符串指针;
; X、Y : 显示字符串的位置,X:0-15,Y:0-1
; LCD第一行显示寄存器地址:0X80-0X8F
; LCD第一行显示寄存器地址:0XC0-0XCF
;
; 编写日期 :2003-11-19
; 最后修改日期 :2004-8-19
; -----------------------------------------------------------------------*/
; void LCD_write_char(unsigned command,unsigned data)
; {
.dbline 52
; unsigned command_temp,data_temp;
;
; command_temp = command;
movw R20,R10
.dbline 53
; data_temp = data;
movw R22,R12
.dbline 55
;
; LCD_wait_Ready();
rcall _LCD_wait_Ready
.dbline 57
;
; LCD_RW_PORT &= ~LCD_RW; //RW=0
cbi 0x12,3
.dbline 59
;
; if (command == 0)
cpi R20,0
cpc R20,R21
brne L4
X0:
.dbline 60
; {
.dbline 61
; LCD_RS_PORT |= LCD_RS; //RS=1
sbi 0x15,4
.dbline 62
; LCD_DATA_PORT &= 0X0F;
in R24,0x12
andi R24,15
out 0x12,R24
.dbline 63
; LCD_DATA_PORT |= data_temp&0xf0; //send high 4bit
movw R24,R22
andi R24,240
andi R25,0
in R2,0x12
clr R3
or R2,R24
or R3,R25
out 0x12,R2
.dbline 64
; }
rjmp L5
L4:
.dbline 66
; else
; {
.dbline 67
; LCD_RS_PORT &= ~LCD_RS; //RS=0
cbi 0x15,4
.dbline 68
; LCD_DATA_PORT &= 0X0F;
in R24,0x12
andi R24,15
out 0x12,R24
.dbline 69
; LCD_DATA_PORT |= command_temp&0xf0;//send high 4bit
movw R24,R20
andi R24,240
andi R25,0
in R2,0x12
clr R3
or R2,R24
or R3,R25
out 0x12,R2
.dbline 70
; }
L5:
.dbline 71
; LCD_en_write();
rcall _LCD_en_write
.dbline 73
;
; 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 74
; data_temp=data_temp << 4;
lsl R22
rol R23
lsl R22
rol R23
lsl R22
rol R23
lsl R22
rol R23
.dbline 76
;
; LCD_DATA_PORT &= 0X0F;
in R24,0x12
andi R24,15
out 0x12,R24
.dbline 77
; if (command==0)
tst R10
brne L6
tst R11
brne L6
X1:
.dbline 78
; LCD_DATA_PORT |= data_temp&0xf0;
movw R24,R22
andi R24,240
andi R25,0
in R2,0x12
clr R3
or R2,R24
or R3,R25
out 0x12,R2
rjmp L7
L6:
.dbline 80
; else
; LCD_DATA_PORT |= command_temp&0xf0;
movw R24,R20
andi R24,240
andi R25,0
in R2,0x12
clr R3
or R2,R24
or R3,R25
out 0x12,R2
L7:
.dbline 81
; LCD_en_write();
rcall _LCD_en_write
.dbline 83
;
; LCD_RW_PORT |= LCD_RW;
sbi 0x12,3
.dbline 85
;
; LCD_RS_PORT ^= LCD_RS;
ldi R24,16
in R2,0x15
eor R2,R24
out 0x15,R2
.dbline -2
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 89
; }
;
; void LCD_wait_Ready(void) //等待LCD空闲
; {
.dbline 90
; LCD_DATA_DDR &= ~0x80; //PD7 I/O口方向设置为输入
cbi 0x11,7
.dbline 92
;
; LCD_RW_PORT |= LCD_RW; //RW=1
sbi 0x12,3
.dbline 94
;
; LCD_RS_PORT &= ~LCD_RS; //RS=0
cbi 0x15,4
.dbline 96
;
; LCD_EN_PORT |= LCD_EN; //EN=1
sbi 0x15,5
L9:
.dbline 98
L10:
.dbline 98
;
; while (!( LCD_DATA_PIN&0x80 ) == 0); //RW=1,读PD7,为0表示空闲;
sbic 0x10,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 100
;
; LCD_EN_PORT &= ~LCD_EN; //EN=0
cbi 0x15,5
.dbline 102
;
; LCD_DATA_DDR |= 0xf0;
in R24,0x11
ori R24,240
out 0x11,R24
.dbline -2
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 116
; }
;
; /*-----------------------------------------------------------------------
; LCD_set_xy : 设置LCD显示的起始位置
;
; 输入参数:x、y : 显示字符串的位置,X:0-15,Y:0-1
; LCD第一行显示寄存器地址:0X80-0X8F
; LCD第一行显示寄存器地址:0XC0-0XCF
;
; 编写日期 :2004-8-19
; 最后修改日期 :2004-8-19
; -----------------------------------------------------------------------*/
; void LCD_set_xy( unsigned char x, unsigned char y )
; {
.dbline 118
; unsigned char address;
; if (y == 0) address = 0x80 + x;
tst R20
brne L15
.dbline 118
mov R20,R22
subi R20,128 ; addi 128
rjmp L16
L15:
.dbline 120
; else
; address = 0xc0 + x;
mov R20,R22
subi R20,64 ; addi 192
L16:
.dbline 121
; LCD_write_char( address, 0 );
clr R18
clr R19
mov R16,R20
clr R17
rcall _LCD_write_char
.dbline -2
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 133
; }
; /*-----------------------------------------------------------------------
; LCD_write_string : 英文字符串显示函数
;
; 输入参数:*s :英文字符串指针;
; X、Y : 显示字符串的位置
;
; 编写日期 :2004-8-19
; 最后修改日期 :2004-8-19
; -----------------------------------------------------------------------*/
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
; {
.dbline 134
; LCD_set_xy( X, Y );
mov R18,R10
mov R16,R22
rcall _LCD_set_xy
rjmp L19
L18:
.dbline 137
.dbline 138
movw R30,R20
ldd R18,z+0
clr R19
clr R16
clr R17
rcall _LCD_write_char
.dbline 139
subi R20,255 ; offset = 1
sbci R21,255
.dbline 140
L19:
.dbline 136
;
; while (*s)
movw R30,R20
ldd R2,z+0
tst R2
brne L18
.dbline -2
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -