📄 lcd.s
字号:
.module lcd.c
.area text(rom, con, rel)
.dbfile C:\bak\YM200\lcd1602\lcd.c
.dbfunc e delay _delay fV
; dk -> R16,R17
.even
_delay::
.dbline -1
.dbline 19
; #include <iom16v.h>
; #include <macros.h>
; #define LCD_RS (1 << 4)
; #define LCD_RW (1 << 5)
; #define LCD_E (1 << 7)
; #define set_e() (PORTD |= LCD_E)
; #define set_rs() (PORTD |= LCD_RS)
; #define set_rw() (PORTD |= LCD_RW)
; #define clr_e() (PORTD &= ~LCD_E)
; #define clr_rs() (PORTD &= ~LCD_RS)
; #define clr_rw() (PORTD &= ~LCD_RW)
;
; /*-----------------------------------------------------------
; delay :短延时函数
; 输入参数 x :粗略延时,x越大,延时越长
; 输出参数 :无
; ------------------------------------------------------------*/
; void delay(unsigned int dk)
; {
L2:
.dbline 20
L3:
.dbline 20
; while(dk--);
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L2
tst R3
brne L2
X0:
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r dk 16 i
.dbend
.dbfunc e lcdwait _lcdwait fV
.even
_lcdwait::
.dbline -1
.dbline 29
; }
;
; /*------------------------------------------------------------
; lcdwait :液晶延时函数
; 输入参数 :无
; 输出参数 :无
; --------------------------------------------------------------*/
; void lcdwait(void)
; {
.dbline 30
; delay(600);
ldi R16,600
ldi R17,2
xcall _delay
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbend
.dbfunc e lcdpulse _lcdpulse fV
.even
_lcdpulse::
.dbline -1
.dbline 38
; }
; /*-----------------------------------------------------------
; lcdpulse :脉冲函数,把数据写入1602液晶
; 输入参数 :无
; 输出参数 :无
; ---------------------------------------------------------------*/
; void lcdpulse(void)
; {
.dbline 39
; set_e();
sbi 0x12,7
.dbline 40
; clr_e();
cbi 0x12,7
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e lcdsend _lcdsend fV
; data -> R20
.even
_lcdsend::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 49
; }
;
; /*----------------------------------------------------------------
; lcdsend :发送一字节数据函数
; 输入参数 data :要发送字节数据
; 输出参数 :无
; ------------------------------------------------------------------*/
; void lcdsend(unsigned char data)
; {
.dbline 50
; lcdwait();
xcall _lcdwait
.dbline 51
; PORTB=data;
out 0x18,R20
.dbline 52
; lcdpulse();
xcall _lcdpulse
.dbline -2
L7:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e wcom _wcom fV
; com -> R20
.even
_wcom::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 60
; }
; /*------------------------------------------------------------------
; wcom :写一字节控制字函数
; 输入参数 com :要写入控制字
; 输出参数 :无
; -----------------------------------------------------------------*/
; void wcom(unsigned char com)
; {
.dbline 61
; clr_rs();
cbi 0x12,4
.dbline 62
; clr_rw();
cbi 0x12,5
.dbline 63
; lcdsend(com);
mov R16,R20
xcall _lcdsend
.dbline 64
; lcdwait();
xcall _lcdwait
.dbline -2
L8:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r com 20 c
.dbend
.dbfunc e wdat _wdat fV
; dat -> R20
.even
_wdat::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 73
; }
;
; /*--------------------------------------------------------------
; wdat :显示一字节函数
; 输入参数 com :要显示字符ASCⅡ码
; 输出参数 :无
; ----------------------------------------------------------------*/
; void wdat(unsigned char dat)
; {
.dbline 74
; set_rs();
sbi 0x12,4
.dbline 75
; clr_rw();
cbi 0x12,5
.dbline 76
; lcdsend(dat);
mov R16,R20
xcall _lcdsend
.dbline 77
; lcdwait();
xcall _lcdwait
.dbline -2
L9:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r dat 20 c
.dbend
.dbfunc e LCM1602Reset _LCM1602Reset fV
.even
_LCM1602Reset::
.dbline -1
.dbline 85
; }
; /*------------------------------------------------------------------
; LCM1602Reset :LCM1602复位
; 输入参数 :无
; 输出参数 :无
; ------------------------------------------------------------------*/
; void LCM1602Reset(void)
; {
.dbline 86
; delay(65000);
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 87
; wcom(0x38);
ldi R16,56
xcall _wcom
.dbline 88
; delay(5000);
ldi R16,5000
ldi R17,19
xcall _delay
.dbline 89
; wcom(0x38);
ldi R16,56
xcall _wcom
.dbline 90
; delay(5000);
ldi R16,5000
ldi R17,19
xcall _delay
.dbline 91
; wcom(0x38);
ldi R16,56
xcall _wcom
.dbline 92
; delay(5000);
ldi R16,5000
ldi R17,19
xcall _delay
.dbline 93
; wcom(0x38);
ldi R16,56
xcall _wcom
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbend
.dbfunc e lcdinit _lcdinit fV
.even
_lcdinit::
.dbline -1
.dbline 102
; }
;
; /*------------------------------------------------------------------
; lcdinit :LCM1602初始化
; 输入参数 :无
; 输出参数 :无
; -------------------------------------------------------------------*/
; void lcdinit(void)
; {
.dbline 103
; wcom(0x01); //清屏
ldi R16,1
xcall _wcom
.dbline 104
; wcom(0x3c); //显示开关控制:8bit,2行显示,5x7
ldi R16,60
xcall _wcom
.dbline 105
; wcom(0x0c); //光标开,闪烁关
ldi R16,12
xcall _wcom
.dbline 106
; wcom(0x06); //输入方式,增量方式,不移动
ldi R16,6
xcall _wcom
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbend
.dbfunc e disp_string _disp_string fV
; data -> R20,R21
.even
_disp_string::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 115
; }
;
; /*-----------------------------------------------------------------
; disp_string :显示一字符串函数
; 输入参数 data :字符串指针
; 输出参数 :无
; ------------------------------------------------------------------*/
; void disp_string( unsigned char *data )
; {
xjmp L14
L13:
.dbline 116
.dbline 116
movw R30,R20
ldd R16,z+0
xcall _wdat
.dbline 116
subi R20,255 ; offset = 1
sbci R21,255
.dbline 116
L14:
.dbline 116
; while(*data!=0) {wdat(*data);data++;}
movw R30,R20
ldd R2,z+0
tst R2
brne L13
.dbline -2
L12:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 pc
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 128
; }
;
; //设置显示坐标:X 0~39,Y:0~1
; #define setxy(x,y) wcom(((x)|((y)<<6))|0x80)
;
; /*--------------------------------------------------------------
; main :主函数
; 输入参数 :无
; 输出参数 :无
; --------------------------------------------------------------*/
; void main()
; {
.dbline 129
; DDRD=0xff;
ldi R24,255
out 0x11,R24
.dbline 130
; DDRB=0xff;
out 0x17,R24
.dbline 131
; LCM1602Reset();
xcall _LCM1602Reset
.dbline 132
; lcdinit();
xcall _lcdinit
.dbline 133
; setxy(0,0);
ldi R16,128
xcall _wcom
.dbline 134
; disp_string("Easy Learning..");
ldi R16,<L17
ldi R17,>L17
xcall _disp_string
.dbline 135
; setxy(2,1);
ldi R16,194
xcall _wcom
.dbline 136
; disp_string("Avr Studio! ");
ldi R16,<L18
ldi R17,>L18
xcall _disp_string
xjmp L20
L19:
.dbline 139
.dbline 140
ldi R16,8
xcall _wcom
.dbline 141
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 142
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 143
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 144
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 145
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 146
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 147
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 148
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 150
ldi R16,12
xcall _wcom
.dbline 151
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 152
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 153
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 154
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 155
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 156
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 157
ldi R16,65000
ldi R17,253
xcall _delay
.dbline 158
L20:
.dbline 138
xjmp L19
X1:
.dbline -2
L16:
.dbline 0 ; func end
ret
.dbend
.area data(ram, con, rel)
.dbfile C:\bak\YM200\lcd1602\lcd.c
L18:
.blkb 13
.area idata
.byte 'A,'v,'r,32,'S,'t,'u,'d,'i,'o,33,32,0
.area data(ram, con, rel)
.dbfile C:\bak\YM200\lcd1602\lcd.c
L17:
.blkb 16
.area idata
.byte 'E,'a,'s,'y,32,'L,'e,'a,'r,'n,'i,'n,'g,46,46,0
.area data(ram, con, rel)
.dbfile C:\bak\YM200\lcd1602\lcd.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -