📄 lcd1602new.s
字号:
.module lcd1602new.c
.area lit(rom, con, rel)
_dis1::
.byte 'A,'V,'R,32,'D,'e,'m,'o,32,'B,'o,'a,'r,'d,0
.dbfile C:\DOCUME~1\shen\桌面\lcd1602new.c
.dbsym e dis1 _dis1 A[15:15]kc
_dis2::
.byte 57,56,'d,'i,'a,'n,64,49,54,51,46,'c,'o,'m,0
.dbsym e dis2 _dis2 A[15:15]kc
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\shen\桌面\lcd1602new.c
.dbfunc e delay _delay fV
; i -> R20,R21
; ms -> R16
.even
_delay::
xcall push_gset1
.dbline -1
.dbline 28
; #include <iom16v.h>
; #include <macros.h>
;
;
; #define Enableon PORTB |=BIT(3); //EN
; #define Enableoff PORTB &=~BIT(3);
;
; #define Dion PORTB |=BIT(5); //DI
; #define Dioff PORTB &=~BIT(5);
;
; #define RWon PORTB |=BIT(4); //RW
; #define RWoff PORTB &=~BIT(4);
;
;
;
;
; extern const unsigned char dis1[] = {"AVR Demo Board"};
; extern const unsigned char dis2[] = {"98dian@163.com"};
;
; /****************************************************************************
; 函数功能:延时子程序
; 作 者:沈建良
; 时 间:2006年4月25日
; 入口参数:ms
; 出口参数:
; ****************************************************************************/
; void delay(unsigned char ms)
; { // 延时子程序
xjmp L3
L2:
.dbline 31
; int i;
; while(ms--)
; {
.dbline 32
; for(i = 0; i< 250; i++)
clr R20
clr R21
L5:
.dbline 33
.dbline 34
nop
.dbline 35
nop
.dbline 36
nop
.dbline 37
nop
.dbline 38
L6:
.dbline 32
subi R20,255 ; offset = 1
sbci R21,255
.dbline 32
cpi R20,250
ldi R30,0
cpc R21,R30
brlt L5
.dbline 39
L3:
.dbline 30
mov R2,R16
clr R3
subi R16,1
tst R2
brne L2
.dbline -2
L1:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 I
.dbsym r ms 16 c
.dbend
.dbfunc e LCD_wait _LCD_wait fV
.even
_LCD_wait::
.dbline -1
.dbline 51
; {
; NOP();
; NOP();
; NOP();
; NOP();
; }
; }
; }
;
;
; /****************************************************************************
; 函数功能:测试LCD忙碌状态
; 作 者:沈建良
; 时 间:2006年4月25日
; 入口参数:
; 出口参数:result
; ****************************************************************************/
; void LCD_wait(void) //等待LCD空闲
; {
.dbline 52
; DDRC=0x00;
clr R2
out 0x14,R2
.dbline 53
; Dioff;//RS
cbi 0x18,5
.dbline 53
.dbline 54
; RWon;
sbi 0x18,4
.dbline 54
.dbline 55
; NOP();
nop
.dbline 56
; Enableon;
sbi 0x18,3
.dbline 56
L10:
.dbline 60
L11:
.dbline 60
; //DDRC=0x00; //input
; //delay(10);
; //while(PINC&0x80);
; while(PINC&0x80);
sbic 0x13,7
rjmp L10
.dbline 61
; Enableoff;
cbi 0x18,3
.dbline 61
.dbline 62
; DDRC=0xff; //output
ldi R24,255
out 0x14,R24
.dbline -2
L9:
.dbline 0 ; func end
ret
.dbend
.dbfunc e write_command _write_command fV
; cmd -> R20
.even
_write_command::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 74
; }
;
;
; /****************************************************************************
; 函数功能:写指令数据到LCD
; 作 者:沈建良
; 时 间:2006年4月25日
; 入口参数:cmd
; 出口参数:
; ****************************************************************************/
; void write_command(unsigned char cmd) //写指令使能
; {
.dbline 75
; LCD_wait();
xcall _LCD_wait
.dbline 77
; //delay(100);
; Dioff;
cbi 0x18,5
.dbline 77
.dbline 78
; RWoff;
cbi 0x18,4
.dbline 78
.dbline 79
; Enableoff;
cbi 0x18,3
.dbline 79
.dbline 80
; NOP();
nop
.dbline 82
; //delay(10);
; Enableon;//???
sbi 0x18,3
.dbline 82
.dbline 85
; //DDRC=0xff; //output
; //delay(10);
; PORTC=cmd;
out 0x15,R20
.dbline 89
; //delay(10);
; //Enableon;
; //delay(10);
; Enableoff;
cbi 0x18,3
.dbline 89
.dbline -2
L13:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r cmd 20 c
.dbend
.dbfunc e lcd_pos _lcd_pos fV
; pos -> R20
.even
_lcd_pos::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 100
; }
;
; /****************************************************************************
; 函数功能:设定显示位置
; 作 者:沈建良
; 时 间:2006年4月25日
; 入口参数:pos
; 出口参数:
; ****************************************************************************/
; void lcd_pos(unsigned char pos)
; { //设定显示位置
.dbline 101
; write_command(pos | 0x80);
mov R16,R20
ori R16,128
xcall _write_command
.dbline -2
L14:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r pos 20 c
.dbend
.dbfunc e write_data _write_data fV
; dat -> R20
.even
_write_data::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 112
; }
;
; /****************************************************************************
; 函数功能:写入显示数据到LCD
; 作 者:沈建良
; 时 间:2006年4月25日
; 入口参数:dat
; 出口参数:
; ****************************************************************************/
; void write_data(unsigned char dat)
; {
.dbline 113
; LCD_wait();
xcall _LCD_wait
.dbline 116
; //delay(100);
; //DDRC=0xff;
; Dion;
sbi 0x18,5
.dbline 116
.dbline 117
; RWoff;
cbi 0x18,4
.dbline 117
.dbline 118
; Enableoff;
cbi 0x18,3
.dbline 118
.dbline 120
; //delay(10);
; NOP();
nop
.dbline 121
; Enableon;
sbi 0x18,3
.dbline 121
.dbline 124
; //delay(10);
;
; PORTC=dat;
out 0x15,R20
.dbline 128
; //delay(10);
; //Enableon;
; //delay(10);
; Enableoff;
cbi 0x18,3
.dbline 128
.dbline -2
L15:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r dat 20 c
.dbend
.dbfunc e lcd_init _lcd_init fV
.even
_lcd_init::
.dbline -1
.dbline 139
; }
;
; /****************************************************************************
; 函数功能:LCD初始化
; 作 者:沈建良
; 时 间:2006年4月25日
; 入口参数:
; 出口参数:
; ****************************************************************************/
; void lcd_init(void)
; {
.dbline 140
; delay(15); //LCD初始化设定
ldi R16,15
xcall _delay
.dbline 141
; write_command(0x38); //
ldi R16,56
xcall _write_command
.dbline 142
; delay(100);
ldi R16,100
xcall _delay
.dbline 143
; write_command(0x01); //清除LCD的显示内容
ldi R16,1
xcall _write_command
.dbline 144
; write_command(0x06); //
ldi R16,6
xcall _write_command
.dbline 145
; write_command(0x0c); //
ldi R16,12
xcall _write_command
.dbline -2
L16:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
; i -> R20
.even
_main::
.dbline -1
.dbline 156
; }
;
; /****************************************************************************
; 函数功能:主程序
; 作 者:沈建良
; 时 间:2006年4月25日
; 入口参数:
; 出口参数:
; ****************************************************************************/
; void main(void)
; {
.dbline 158
; char i;
; DDRC=0xff;
ldi R24,255
out 0x14,R24
.dbline 159
; DDRB=0xff;
out 0x17,R24
.dbline 160
; lcd_init(); // 初始化LCD
xcall _lcd_init
.dbline 161
; delay(100);
ldi R16,100
xcall _delay
.dbline 162
; lcd_pos(1); // 设置显示位置为第一行的第5个字符
ldi R16,1
xcall _lcd_pos
.dbline 163
; i = 0;
clr R20
xjmp L19
X0:
.dbline 164
; while(1){
L21:
.dbline 167
.dbline 168
ldi R24,<_dis1
ldi R25,>_dis1
mov R30,R20
clr R31
add R30,R24
adc R31,R25
lpm R16,Z
xcall _write_data
.dbline 169
inc R20
.dbline 170
L22:
.dbline 166
;
; while(dis1[i] != '\0')
ldi R24,<_dis1
ldi R25,>_dis1
mov R30,R20
clr R31
add R30,R24
adc R31,R25
lpm R30,Z
tst R30
brne L21
.dbline 171
; { // 显示字符hificat.com
; write_data(dis1[i]);
; i++;
; }
; lcd_pos(0x41); // 设置显示位置为第二行第二个字符
ldi R16,65
xcall _lcd_pos
.dbline 172
; i = 0;
clr R20
xjmp L25
L24:
.dbline 174
.dbline 175
ldi R24,<_dis2
ldi R25,>_dis2
mov R30,R20
clr R31
add R30,R24
adc R31,R25
lpm R16,Z
xcall _write_data
.dbline 176
inc R20
.dbline 177
L25:
.dbline 173
ldi R24,<_dis2
ldi R25,>_dis2
mov R30,R20
clr R31
add R30,R24
adc R31,R25
lpm R30,Z
tst R30
brne L24
.dbline 178
L19:
.dbline 164
xjmp L22
X1:
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -