📄 lcd1602.s
字号:
.module lcd1602.c
.area text(rom, con, rel)
.dbfile D:\练习\LCD显示1602/lcd1602.h
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 29
; //ICC-AVR application builder : 2007-4-21 20:12:02
; // Target : M16
; // Crystal: 8.0000Mhz
;
; #include <iom16v.h>
; #include <macros.h>
; #include "lcd1602.h"
;
; /*unsigned char TempBuffer[10];
; void IntToStr(unsigned int t, unsigned char *str, unsigned char n)
; {
; unsigned char a[5];
; char i, j;
; a[0]=(t/10000)%10; //取得整数值到数组
; a[1]=(t/1000)%10;
; a[2]=(t/100)%10;
; a[3]=(t/10)%10;
; a[4]=(t/1)%10;
;
; for(i=0; i<5; i++) //转成ASCII码
; a[i]=a[i]+'0';
; for(i=0; a[i]=='0' && i<=3; i++);
; for(j=5-n; j<i; j++) //填充空格
; { *str='a'; str++; }
; for(; i<5; i++)
; { *str=a[i]; str++; } //加入有效的数字
; *str='\0';
; } */
;
.dbline 30
; unsigned char second[2],minute[2],hour[2];
clr R2
out 0x1b,R2
.dbline 31
; unsigned char Year[4],Month[2],Day[2];
out 0x1a,R2
.dbline 32
; unsigned char sec=0,min=5,hou=18;
out 0x18,R2
.dbline 33
; unsigned int year=2007;
out 0x17,R2
.dbline 34
; unsigned char month=4,day=23;
ldi R24,16
out 0x15,R24
.dbline 35
; unsigned char flash_flag=0,time_set=0;
ldi R24,28
out 0x14,R24
.dbline 36
;
out 0x12,R2
.dbline 37
;
out 0x11,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e watchdog_init _watchdog_init fV
.even
_watchdog_init::
.dbline -1
.dbline 44
; void IntToStr(unsigned char t, unsigned char *str)
; {
; unsigned char a[2];
; char i;
;
; a[0]=(t/10)%10; //取得整数值到数组
; a[1]=(t/1)%10;
.dbline 45
; for(i=0; i<2; i++) //转成ASCII码
wdr
.dbline 46
; a[i]=a[i]+'0';
ldi R24,15
out 0x21,R24
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e timer1_init _timer1_init fV
.even
_timer1_init::
.dbline -1
.dbline 54
; for(i=0;i<2;i++)
; {
; *str=a[i];
; str++;
; }
; *str='\0';
; }
; //**************************************************************
.dbline 55
; void IntToStr1(unsigned int t, unsigned char *str)
clr R2
out 0x2e,R2
.dbline 56
; {
ldi R24,194
out 0x2d,R24
.dbline 57
; unsigned char a[4];
ldi R24,247
out 0x2c,R24
.dbline 66
; char i, j;
; a[0]=(t/1000)%10; //取得整数值到数组
; a[1]=(t/100)%10;
; a[2]=(t/10)%10;
; a[3]=(t/1)%10;
; for(i=0; i<4; i++) //转成ASCII码
; a[i]=a[i]+'0';
; for(i=0;i<4;i++)
; {
out 0x2f,R2
.dbline 67
; *str=a[i];
ldi R24,4
out 0x2e,R24
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 72
; str++;
; }
; *str='\0';
; }
;
.dbline 74
; //主函数
; void main(void)
cli
.dbline 75
; {
xcall _port_init
.dbline 76
; /*unsigned char sec=0,min=5,hou=18;
xcall _watchdog_init
.dbline 77
; unsigned int year=2007;
xcall _timer1_init
.dbline 79
; unsigned char month=4,day=23;*/
;
clr R2
out 0x35,R2
.dbline 80
; init_devices();
ldi R24,192
out 0x3b,R24
.dbline 81
; lcd_init();
ldi R24,4
out 0x39,R24
.dbline 82
; GotoXY(0,0);
sei
.dbline -2
L4:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay_us _delay_us fV
; time -> R16,R17
.even
_delay_us::
.dbline -1
.dbline 88
; Print("Date:");
; GotoXY(0,1);
; asm("nop");
; Print("Time: ");
; //********************************************************
; GotoXY(13,0);//显示':'
.dbline 89
; Print(":");
wdr
xjmp L7
L6:
.dbline 91
.dbline 92
nop
.dbline 92
nop
.dbline 92
nop
.dbline 92
nop
.dbline 92
nop
.dbline 92
nop
.dbline 92
nop
.dbline 92
nop
.dbline 93
L7:
.dbline 90
; GotoXY(10,0);
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L6
tst R3
brne L6
X0:
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbsym r time 16 I
.dbend
.dbfunc e delay_ms _delay_ms fV
; time -> R20,R21
.even
_delay_ms::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 96
; Print(":");
; //循环函数********************************************************
; while(1)
; {
; //********************************************************
; WDR();
xjmp L11
L10:
.dbline 98
.dbline 99
ldi R16,1000
ldi R17,3
xcall _delay_us
.dbline 100
L11:
.dbline 97
; IntToStr(sec,&second[0]);//把两位的秒位转换成两个一位的数字才能显示;
movw R2,R20
subi R20,1
sbci R21,0
tst R2
brne L10
tst R3
brne L10
X1:
.dbline -2
L9:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r time 20 I
.dbend
.dbfunc e lcd_read_code _lcd_read_code fc
; code -> R20
.even
_lcd_read_code::
xcall push_gset1
.dbline -1
.dbline 106
; GotoXY(12,1);
; if(time_set!=1)
; {
; Print(&second[0]);
; }
; else if(time_set==1)//当时间设定选定秒位时,秒位开始闪烁;
; {
; if((flash_flag)%2==0)
; {
.dbline 108
; Print(&second[0]);
; }
clr R2
out 0x1a,R2
.dbline 109
; else
cbi 0x15,2
.dbline 110
; {
sbi 0x15,3
.dbline 111
; Print(" ");
sbi 0x15,4
.dbline 112
; }
ldi R16,1
ldi R17,0
xcall _delay_ms
.dbline 113
; }
in R20,0x19
.dbline 114
; //********************************************************
cbi 0x15,4
.dbline 115
; if((flash_flag%2)==0)
cbi 0x15,3
.dbline 116
; {
ldi R24,255
out 0x1a,R24
.dbline 117
; GotoXY(11,1);//显示':'
mov R16,R20
.dbline -2
L13:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r code 20 c
.dbend
.dbfunc e judgebusy _judgebusy fV
.even
_judgebusy::
.dbline -1
.dbline 123
; Print(":");
; GotoXY(8,1);
; Print(":");
; }
; else
; {
L15:
.dbline 127
.dbline 131
L16:
.dbline 126
; GotoXY(11,1);//显示' ';实现':'闪烁效果
; Print(" ");
; GotoXY(8,1);
xcall _lcd_read_code
mov R2,R16
clr R3
sbrc R2,7
rjmp L15
.dbline -2
L14:
.dbline 0 ; func end
ret
.dbend
.dbfunc e lcd_write_data _lcd_write_data fV
; data -> R20
.even
_lcd_write_data::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 136
; Print(" ");
; }
; //********************************************************
; IntToStr(min,&minute[0]);//转换分位,显示
; GotoXY(9,1);
; if(time_set!=2)//按下时间设定键,第2下为分设置
; {
; Print(&minute[0]);
; }
; else if(time_set==2)
.dbline 137
; {
wdr
.dbline 138
; if((flash_flag)%2==0)
ldi R24,255
out 0x1a,R24
.dbline 139
; {
sbi 0x15,2
.dbline 140
; Print(&minute[0]);
ldi R16,1
ldi R17,0
xcall _delay_us
.dbline 141
; }
cbi 0x15,3
.dbline 142
; else
ldi R16,1
ldi R17,0
xcall _delay_us
.dbline 143
; {
sbi 0x15,4
.dbline 145
; Print(" ");
; }
ldi R16,1
ldi R17,0
xcall _delay_ms
.dbline 146
; }
out 0x1b,R20
.dbline 147
; //********************************************************
cbi 0x15,4
.dbline 148
; IntToStr(hou,&hour[0]);//转换小时位,显示
ldi R16,1
ldi R17,0
xcall _delay_us
.dbline 150
; GotoXY(6,1);
; if(time_set!=3)//按下时间设定键,第3下为小时设置
sbi 0x15,3
.dbline 151
; {
clr R2
out 0x1a,R2
.dbline 152
; Print(&hour[0]);
wdr
.dbline -2
L18:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e lcd_write_code _lcd_write_code fV
; code -> R20
.even
_lcd_write_code::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 157
; }
; else if(time_set==3)
; {
; if((flash_flag)%2==0)
; {
.dbline 158
; Print(&hour[0]);
wdr
.dbline 159
; }
ldi R24,255
out 0x1a,R24
.dbline 160
; else
cbi 0x15,2
.dbline 161
; {
ldi R16,1
ldi R17,0
xcall _delay_us
.dbline 162
; Print(" ");
cbi 0x15,3
.dbline 163
; }
ldi R16,1
ldi R17,0
xcall _delay_us
.dbline 164
; }
sbi 0x15,4
.dbline 166
; //********************************************************
; IntToStr(day,&Day[0]);//转换日位,显示
ldi R16,1
ldi R17,0
xcall _delay_ms
.dbline 168
; GotoXY(14,0);
; if(time_set!=4)//按下时间设定键,第4下为日设置
out 0x1b,R20
.dbline 169
; {
cbi 0x15,4
.dbline 170
; Print(&Day[0]);
ldi R16,1
ldi R17,0
xcall _delay_us
.dbline 172
; }
; else if(time_set==4)
sbi 0x15,3
.dbline 173
; {
clr R2
out 0x1a,R2
.dbline 174
; if((flash_flag)%2==0)
wdr
.dbline -2
L19:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r code 20 c
.dbend
.dbfunc e Print _Print fV
; str -> R20,R21
.even
_Print::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 179
; {
; Print(&Day[0]);
; }
; else
; {
xjmp L22
L21:
.dbline 181
.dbline 182
wdr
.dbline 183
movw R30,R20
ldd R16,z+0
xcall _lcd_write_data
.dbline 185
subi R20,255 ; offset = 1
sbci R21,255
.dbline 186
L22:
.dbline 180
; Print(" ");
movw R30,R20
ldd R2,z+0
tst R2
brne L21
.dbline -2
L20:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r str 20 pc
.dbend
.dbfunc e GotoXY _GotoXY fV
; y -> R22
; x -> R20
.even
_GotoXY::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 191
; }
; }
;
; //********************************************************
; IntToStr(month,&Month[0]);//转换月位,显示
; GotoXY(11,0);
; if(time_set!=5)//按下时间设定键,第5下为月设置
; {
; Print(&Month[0]);
; }
; else if(time_set==5)
.dbline 192
; {
tst R22
brne L25
.dbline 193
; if((flash_flag)%2==0)
mov R16,R20
ori R16,128
xcall _lcd_write_code
L25:
.dbline 194
cpi R22,1
brne L27
.dbline 195
mov R16,R20
subi R16,64
ori R16,128
xcall _lcd_write_code
L27:
.dbline -2
L24:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r y 22 c
.dbsym r x 20 c
.dbend
.dbfunc e lcd_init _lcd_init fV
.even
_lcd_init::
.dbline -1
.dbline 199
; {
; Print(&Month[0]);
; }
; else
; {
; Print(" ");
.dbline 200
; }
wdr
.dbline 201
; }
ldi R16,400
ldi R17,1
xcall _delay_ms
.dbline 202
; //********************************************************
sbi 0x15,4
.dbline 204
; IntToStr1(year,&Year[0]);//转换年位,显示
; GotoXY(6,0);
ldi R16,15
ldi R17,0
xcall _delay_ms
.dbline 205
; if(time_set!=6)//按下时间设定键,第6下为年设置
ldi R16,56
xcall _lcd_write_code
.dbline 206
; {
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 207
; Print(&Year[0]);
ldi R16,56
xcall _lcd_write_code
.dbline 208
; }
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 209
; else if(time_set==6)
ldi R16,56
xcall _lcd_write_code
.dbline 210
; {
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 211
; if((flash_flag)%2==0)
ldi R16,12
xcall _lcd_write_code
.dbline 212
; {
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 213
; Print(&Year[0]);
ldi R16,6
xcall _lcd_write_code
.dbline 214
; }
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 215
; else
ldi R16,1
xcall _lcd_write_code
.dbline 216
; {
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 217
; Print(" ");
ldi R16,2
xcall _lcd_write_code
.dbline 218
; }
wdr
.dbline -2
L29:
.dbline 0 ; func end
ret
.dbend
.area data(ram, con, rel)
.dbfile D:\练习\LCD显示1602/lcd1602.h
_sec::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile D:\练习\LCD显示1602/lcd1602.h
.dbfile D:\练习\LCD显示1602\lcd1602.c
.dbsym e sec _sec c
_min::
.blkb 1
.area idata
.byte 5
.area data(ram, con, rel)
.dbfile D:\练习\LCD显示1602\lcd1602.c
.dbsym e min _min c
_hou::
.blkb 1
.area idata
.byte 18
.area data(ram, con, rel)
.dbfile D:\练习\LCD显示1602\lcd1602.c
.dbsym e hou _hou c
_year::
.blkb 2
.area idata
.word 2007
.area data(ram, con, rel)
.dbfile D:\练习\LCD显示1602\lcd1602.c
.dbsym e year _year i
_month::
.blkb 1
.area idata
.byte 4
.area data(ram, con, rel)
.dbfile D:\练习\LCD显示1602\lcd1602.c
.dbsym e month _month c
_day::
.blkb 1
.area idata
.byte 23
.area data(ram, con, rel)
.dbfile D:\练习\LCD显示1602\lcd1602.c
.dbsym e day _day c
_flash_flag::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile D:\练习\LCD显示1602\lcd1602.c
.dbsym e flash_flag _flash_flag c
_time_set::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile D:\练习\LCD显示1602\lcd1602.c
.dbsym e time_set _time_set c
.area text(rom, con, rel)
.dbfile D:\练习\LCD显示1602\lcd1602.c
.dbfunc e IntToStr _IntToStr fV
; a -> y+0
; i -> R20
; str -> R22,R23
; t -> R20
.even
_IntToStr::
xcall push_gset2
movw R22,R18
mov R20,R16
sbiw R28,2
.dbline -1
.dbline 39
.dbline 43
ldi R17,10
mov R16,R20
xcall div8u
ldi R17,10
xcall mod8u
std y+0,R16
.dbline 44
ldi R17,10
mov R16,R20
xcall mod8u
std y+1,R16
.dbline 45
clr R20
xjmp L35
L32:
.dbline 46
movw R24,R28
mov R2,R20
clr R3
add R2,R24
adc R3,R25
movw R30,R2
ldd R24,z+0
subi R24,208 ; addi 48
std z+0,R24
L33:
.dbline 45
inc R20
L35:
.dbline 45
cpi R20,2
brlo L32
.dbline 47
clr R20
xjmp L39
L36:
.dbline 48
.dbline 49
movw R24,R28
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R2,z+0
movw R30,R22
std z+0,R2
.dbline 50
subi R22,255 ; offset = 1
sbci R23,255
.dbline 51
L37:
.dbline 47
inc R20
L39:
.dbline 47
cpi R20,2
brlo L36
.dbline 52
clr R2
movw R30,R22
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -