📄 lcd.s
字号:
.module lcd.c
.area text(rom, con, rel)
.dbfile F:\我的设计\delphi\uartdispy\mcu\lcd.c
.dbfunc e LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 22
; /*********************************Copyright (c)*********************************
; **
; ** 文 件 名: LCD.c
; ** 最后修改日期: 2005年06月8日
; ** 描 述: 1602液晶驱动函数
; ** 版 本: V1.0
; ** 主 控 芯 片:M16 晶振频率:8 MHZ
; *******************************************************************************/
; #include <iom16v.h>
; #include <macros.h>
; #include "function.h"
; #include "define.h"
; #include "defineLCD.h"
; /******************************************************************************
;
;
; 函数定义
;
; ******************************************************************************/
;
; void LCD_init(void) //液晶初始化
; {
.dbline 23
; delay_nms(15);
ldi R16,15
ldi R17,0
xcall _delay_nms
.dbline 24
; LCD_write_char(0x28,0); //4位显示
clr R18
clr R19
ldi R16,40
ldi R17,0
xcall _LCD_write_char
.dbline 25
; LCD_write_char(0x0c,0); //显示开
clr R18
clr R19
ldi R16,12
ldi R17,0
xcall _LCD_write_char
.dbline 26
; LCD_write_char(0x01,0); //清屏
clr R18
clr R19
ldi R16,1
ldi R17,0
xcall _LCD_write_char
.dbline -2
L1:
.dbline 0 ; func end
ret
.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 31
; }
;
;
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
; {
.dbline 32
; LCD_set_xy( X, Y ); //写地址
mov R18,R10
mov R16,R22
xcall _LCD_set_xy
xjmp L4
L3:
.dbline 35
.dbline 36
movw R30,R20
ldd R18,z+0
clr R19
clr R16
clr R17
xcall _LCD_write_char
.dbline 37
subi R20,255 ; offset = 1
sbci R21,255
.dbline 38
L4:
.dbline 34
;
; while (*s) // 写显示字符
movw R30,R20
ldd R2,z+0
tst R2
brne L3
.dbline -2
L2:
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_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 43
; {
; LCD_write_char( 0, *s );
; s ++;
; }
; }
;
;
; void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数
; {
.dbline 45
; unsigned char address;
; if (y == 0) address = 0x80 + x;
tst R20
brne L7
.dbline 45
mov R20,R22
subi R20,128 ; addi 128
xjmp L8
L7:
.dbline 47
; else
; address = 0xc0 + x;
mov R20,R22
subi R20,64 ; addi 192
L8:
.dbline 48
; LCD_write_char( address, 0 );
clr R18
clr R19
mov R16,R20
clr R17
xcall _LCD_write_char
.dbline -2
L6:
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_en_write _LCD_en_write fV
.even
_LCD_en_write::
.dbline -1
.dbline 52
; }
;
; void LCD_en_write(void) //液晶使能
; {
.dbline 53
; LCD_EN_PORT|=LCD_EN;
sbi 0x15,7
.dbline 54
; delay_nus(1);
ldi R16,1
ldi R17,0
xcall _delay_nus
.dbline 55
; LCD_EN_PORT&=~LCD_EN;
cbi 0x15,7
.dbline -2
L9:
.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 59
; }
;
; void LCD_write_char(unsigned command,unsigned data) // 写数据
; {
.dbline 61
; unsigned command_temp,data_temp;
; command_temp=command;
movw R20,R10
.dbline 62
; data_temp=data;
movw R22,R12
.dbline 63
; delay_nus(16);
ldi R16,16
ldi R17,0
xcall _delay_nus
.dbline 64
; if(command==0)
cpi R20,0
cpc R20,R21
brne L11
X0:
.dbline 65
; {
.dbline 66
; LCD_RS_PORT|=LCD_RS; //RS=1
sbi 0x15,6
.dbline 67
; LCD_DATA_PORT&=0X0f;
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 68
; LCD_DATA_PORT|=data_temp&0xf0; //写高四位
movw R24,R22
andi R24,240
andi R25,0
in R2,0x1b
clr R3
or R2,R24
or R3,R25
out 0x1b,R2
.dbline 69
; LCD_en_write();
xcall _LCD_en_write
.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,0x1b
andi R24,15
out 0x1b,R24
.dbline 72
; LCD_DATA_PORT|=data_temp&0xf0; //写低四位
movw R24,R22
andi R24,240
andi R25,0
in R2,0x1b
clr R3
or R2,R24
or R3,R25
out 0x1b,R2
.dbline 73
; LCD_en_write();
xcall _LCD_en_write
.dbline 74
; }
xjmp L12
L11:
.dbline 76
.dbline 77
cbi 0x15,6
.dbline 78
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 79
movw R24,R20
andi R24,240
andi R25,0
in R2,0x1b
clr R3
or R2,R24
or R3,R25
out 0x1b,R2
.dbline 80
xcall _LCD_en_write
.dbline 81
lsl R20
rol R21
lsl R20
rol R21
lsl R20
rol R21
lsl R20
rol R21
.dbline 82
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 83
movw R24,R20
andi R24,240
andi R25,0
in R2,0x1b
clr R3
or R2,R24
or R3,R25
out 0x1b,R2
.dbline 84
xcall _LCD_en_write
.dbline 85
L12:
.dbline -2
L10:
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -