📄 1602b_lcd.s
字号:
.module _1602B_LCD.c
.area text(rom, con, rel)
.dbfile E:\mcu\avr\test\1602_duoji\1602B_LCD.c
.dbfunc e LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 17
; #include <iom16v.h>
; #include <macros.h>
; #include "1602LCD.h"
;
; /**********************************************************
; **********************************************************/
; /**********************************************************
; 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 18
; delay_nms(15);
ldi R16,15
ldi R17,0
xcall _delay_nms
.dbline 20
;
; LCD_write_char(0x28,0); //4bit test
clr R18
clr R19
ldi R16,40
ldi R17,0
xcall _LCD_write_char
.dbline 21
; LCD_write_char(0x0f,0); //显示开,显示光标,产生闪烁
clr R18
clr R19
ldi R16,15
ldi R17,0
xcall _LCD_write_char
.dbline 22
; LCD_write_char(0x01,0); //显示清屏
clr R18
clr R19
ldi R16,1
ldi R17,0
xcall _LCD_write_char
.dbline 23
; LCD_write_char(0x06,0); //显示光标移动设置
clr R18
clr R19
ldi R16,6
ldi R17,0
xcall _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 27
; }
;
; void LCD_en_write(void) //EN端产生一个高电平脉冲,写LCD
; {
.dbline 28
; LCD_EN_PORT |= LCD_EN;
sbi 0x12,5
.dbline 29
; delay_nus(1);
ldi R16,1
ldi R17,0
xcall _delay_nus
.dbline 30
; LCD_EN_PORT &= ~LCD_EN;
cbi 0x12,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::
xcall push_gset4
movw R12,R18
movw R10,R16
.dbline -1
.dbline 45
; }
;
; /*-----------------------------------------------------------------------
; 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 48
; unsigned command_temp,data_temp;
;
; command_temp = command;
movw R20,R10
.dbline 49
; data_temp = data;
movw R22,R12
.dbline 51
;
; LCD_wait_Ready();
xcall _LCD_wait_Ready
.dbline 53
;
; LCD_RW_PORT &= ~LCD_RW; //RW=0
cbi 0x12,3
.dbline 55
;
; if (command == 0)
cpi R20,0
cpc R20,R21
brne L4
X0:
.dbline 56
; {
.dbline 57
; LCD_RS_PORT |= LCD_RS; //RS=1
sbi 0x12,4
.dbline 58
; LCD_DATA_PORT &= 0X0F;
in R24,0x18
andi R24,15
out 0x18,R24
.dbline 59
; LCD_DATA_PORT |= data_temp&0xf0; //send high 4bit
movw R24,R22
andi R24,240
andi R25,0
in R2,0x18
clr R3
or R2,R24
or R3,R25
out 0x18,R2
.dbline 60
; }
xjmp L5
L4:
.dbline 62
; else
; {
.dbline 63
; LCD_RS_PORT &= ~LCD_RS; //RS=0
cbi 0x12,4
.dbline 64
; LCD_DATA_PORT &= 0X0F;
in R24,0x18
andi R24,15
out 0x18,R24
.dbline 65
; LCD_DATA_PORT |= command_temp&0xf0;//send high 4bit
movw R24,R20
andi R24,240
andi R25,0
in R2,0x18
clr R3
or R2,R24
or R3,R25
out 0x18,R2
.dbline 66
; }
L5:
.dbline 67
; LCD_en_write();
xcall _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 72
;
; LCD_DATA_PORT &= 0X0F;
in R24,0x18
andi R24,15
out 0x18,R24
.dbline 73
; if (command==0)
tst R10
brne L6
tst R11
brne L6
X1:
.dbline 74
; LCD_DATA_PORT |= data_temp&0xf0;
movw R24,R22
andi R24,240
andi R25,0
in R2,0x18
clr R3
or R2,R24
or R3,R25
out 0x18,R2
xjmp L7
L6:
.dbline 76
; else
; LCD_DATA_PORT |= command_temp&0xf0;
movw R24,R20
andi R24,240
andi R25,0
in R2,0x18
clr R3
or R2,R24
or R3,R25
out 0x18,R2
L7:
.dbline 77
; LCD_en_write();
xcall _LCD_en_write
.dbline 79
;
; LCD_RW_PORT |= LCD_RW;
sbi 0x12,3
.dbline 81
;
; LCD_RS_PORT ^= LCD_RS;
ldi R24,16
in R2,0x12
eor R2,R24
out 0x12,R2
.dbline -2
L3:
xcall 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 85
; }
;
; void LCD_wait_Ready(void) //等待LCD空闲
; {
.dbline 86
; LCD_DATA_DDR &= ~0x80; //PD7 I/O口方向设置为输入
cbi 0x17,7
.dbline 88
;
; LCD_RW_PORT |= LCD_RW; //RW=1
sbi 0x12,3
.dbline 90
;
; LCD_RS_PORT &= ~LCD_RS; //RS=0
cbi 0x12,4
.dbline 92
;
; LCD_EN_PORT |= LCD_EN; //EN=1
sbi 0x12,5
L9:
.dbline 94
L10:
.dbline 94
;
; while (!( LCD_DATA_PIN&0x80 ) == 0); //RW=1,读PD7,为0表示空闲;
sbic 0x16,7
rjmp L12
ldi R16,1
ldi R17,0
xjmp L13
L12:
clr R16
clr R17
L13:
cpi R16,0
cpc R16,R17
breq L9
X2:
.dbline 96
;
; LCD_EN_PORT &= ~LCD_EN; //EN=0
cbi 0x12,5
.dbline 98
;
; LCD_DATA_DDR |= 0xf0;
in R24,0x17
ori R24,240
out 0x17,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::
xcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 112
; }
;
; /*-----------------------------------------------------------------------
; 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 114
; unsigned char address;
; if (y == 0) address = 0x80 + x;
tst R20
brne L15
.dbline 114
mov R20,R22
subi R20,128 ; addi 128
xjmp L16
L15:
.dbline 116
; else
; address = 0xc0 + x;
mov R20,R22
subi R20,64 ; addi 192
L16:
.dbline 117
; LCD_write_char( address, 0 );
clr R18
clr R19
mov R16,R20
clr R17
xcall _LCD_write_char
.dbline -2
L14:
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 129
; }
; /*-----------------------------------------------------------------------
; 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 130
; LCD_set_xy( X, Y );
mov R18,R10
mov R16,R22
xcall _LCD_set_xy
xjmp L19
L18:
.dbline 133
.dbline 134
movw R30,R20
ldd R18,z+0
clr R19
clr R16
clr R17
xcall _LCD_write_char
.dbline 135
subi R20,255 ; offset = 1
sbci R21,255
.dbline 136
L19:
.dbline 132
;
; while (*s)
movw R30,R20
ldd R2,z+0
tst R2
brne L18
.dbline -2
L17:
xcall 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 + -