?? 1602lcd.s
字號:
.module _1602LCD.c
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列單片機實驗開發板演示程序\1602LCD/delay.h
.dbfunc e DelayUS _DelayUS fV
; time -> R16,R17
.even
_DelayUS::
.dbline -1
.dbline 9
; /**********************************************
; 液晶1602實驗
; 晶振: 內部8.0000Mhz
; 連接:RS PA2,
; RW PA1,
; EN PA0,
; DATA PD0-PD7
; ***********************************************/
; /******************頭文件**********************/
xjmp L3
L2:
.dbline 11
subi R16,1
sbci R17,0
L3:
.dbline 10
; #include <iom16v.h>
ldi R24,1
ldi R25,0
cp R24,R16
cpc R25,R17
brlo L2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r time 16 i
.dbend
.dbfunc e DelayMS _DelayMS fV
; i -> R20,R21
; time -> R16,R17
.even
_DelayMS::
xcall push_gset1
.dbline -1
.dbline 20
; #include <macros.h>
; #include "delay.h"
; /******************宏定義**********************/
; #define uchar unsigned char
; #define uint unsigned int
;
; #define mode 0x38 //功能設置
; //DL=1 八位數據接口
; //N=1 兩行顯示
; //F=0 5*7點陣字符
xjmp L7
L6:
.dbline 23
; #define cursor 0x0f //顯示開/關設置
; //D=1 顯示屏開
; //C=1 光標開
.dbline 24
; //B=1 閃爍開
ldi R20,1
ldi R21,0
xjmp L12
L9:
.dbline 25
L10:
.dbline 24
subi R20,255 ; offset = 1
sbci R21,255
L12:
.dbline 24
cpi R20,118
ldi R30,4
cpc R21,R30
brlo L9
.dbline 26
L7:
.dbline 22
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L6
tst R3
brne L6
X0:
.dbline -2
L5:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r time 16 i
.dbend
.area lit(rom, con, rel)
_table1::
.byte 'j,'i,32,'s,'h,'u,32,'w,'u,32,'l,'i,32,'x,'i,0
.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列單片機實驗開發板演示程序\1602LCD\1602LCD.c
.dbsym e table1 _table1 A[16:16]kc
_table2::
.byte 'd,'i,'a,'n,'z,'i,'x,'i,'a,'o,'z,'u,53,48,55,0
.dbsym e table2 _table2 A[16:16]kc
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列單片機實驗開發板演示程序\1602LCD\1602LCD.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 57
; #define shift_off 0x06 //輸入方式設置
; //ID=1 讀寫一個字符后,地址和光標加1
; //S=0 屏幕視窗停留在1-16列寄存器不移動
; #define shift_on 0x07 //輸入方式設置
; //ID=1 讀寫一個字符后,地址和光標加1
; //S=1 每次寫完一個字符屏幕視窗從左邊的寄存器向右邊的寄存器移動實現字符左移的效果
; #define run 0x1c //光標、畫面移動,不影響DDRAM
; //S/C=1 屏幕視窗向右平移一個字符
; //R/L=1 右移
; #define clean 0x01 //清屏指令
; #define enter 0x02 //歸位指令 AC=0 光標,畫面回HOME位
;
; #define RS_H PORTA|=BIT(2) //RS=1,選擇數據
; #define RS_L PORTA&=~BIT(2) //RS=0,選擇命令
;
; #define RW_H PORTA|=BIT(1) //R/W=1,讀
; #define RW_L PORTA&=~BIT(1) //R/W=0,寫
;
; #define EN_H PORTA|=BIT(0) //EN=1,使能關
; #define EN_L PORTA=~BIT(0) //EN=0,使能開
;
; const uchar table1[]="ji shu wu li xi"; //定義數據在flash中
; const uchar table2[]="dianzixiaozu507";
; /******************函數聲明******************/
; void port_init(void); //M16初始化
; void n1602_init(void); //1602初始化
; void write_com(uchar com); //寫指令
; void write_dat(uchar dat); //寫數據
; void set_xy(uchar x,uchar y); //設置行列
; void show(uchar x,uchar y,uchar *str); //顯示函數,x行,y列,*str字符串
; /*****************M16初始化******************/
; void port_init(void)
; {
.dbline 58
; PORTA = 0x00;//設置端口數據、方向
clr R2
out 0x1b,R2
.dbline 59
; DDRA = 0xFF;
ldi R24,255
out 0x1a,R24
.dbline 60
; PORTB = 0x00;
out 0x18,R2
.dbline 61
; DDRB = 0x00;
out 0x17,R2
.dbline 62
; PORTC = 0x00;
out 0x15,R2
.dbline 63
; DDRC = 0x00;
out 0x14,R2
.dbline 64
; PORTD = 0x00;
out 0x12,R2
.dbline 65
; DDRD = 0xFF;
out 0x11,R24
.dbline -2
L13:
.dbline 0 ; func end
ret
.dbend
.dbfunc e n1602_init _n1602_init fV
.even
_n1602_init::
.dbline -1
.dbline 69
; }
; /*****************1602初始化*****************/
; void n1602_init(void)
; {
.dbline 70
; EN_L;
ldi R24,254
out 0x1b,R24
.dbline 71
; write_com(mode); //功能設置
ldi R16,56
xcall _write_com
.dbline 72
; DelayMS(1);
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline 73
; write_com(clean); //清屏
ldi R16,1
xcall _write_com
.dbline 74
; DelayMS(1);
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline 75
; write_com(cursor); //顯示開/關設置
ldi R16,15
xcall _write_com
.dbline 76
; DelayMS(1);
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline 77
; write_com(shift_off); //每寫完一個字符地址指針加+1,屏幕視窗不移動
ldi R16,6
xcall _write_com
.dbline 78
; DelayMS(1);
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline -2
L14:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 82
;
; }
; void init_devices(void)
; {
.dbline 83
; CLI(); //禁止所有中斷
cli
.dbline 84
; MCUCR = 0x00;//INT0、INT1中斷觸發方式
clr R2
out 0x35,R2
.dbline 85
; MCUCSR = 0x80;//禁止JTAG
ldi R24,128
out 0x34,R24
.dbline 86
; GICR = 0x00;//外部中斷使能
out 0x3b,R2
.dbline 87
; port_init();
xcall _port_init
.dbline 88
; n1602_init();
xcall _n1602_init
.dbline 89
; SEI();//開全局中斷
sei
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e write_com _write_com fV
; com -> R20
.even
_write_com::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 93
; }
; /******************寫指令********************/
; void write_com(uchar com)
; {
.dbline 94
; RS_L; //選擇命令
cbi 0x1b,2
.dbline 95
; RW_L; //寫
cbi 0x1b,1
.dbline 96
; PORTD=com; //送命令
out 0x12,R20
.dbline 97
; EN_H;
sbi 0x1b,0
.dbline 98
; DelayMS(1); //延時不可少,否則數據丟失
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline 99
; EN_L; //下降沿寫入
ldi R24,254
out 0x1b,R24
.dbline -2
L16:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r com 20 c
.dbend
.dbfunc e write_dat _write_dat fV
; dat -> R20
.even
_write_dat::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 103
; }
; /******************寫數據********************/
; void write_dat(uchar dat)
; {
.dbline 104
; RS_H; //選擇數據
sbi 0x1b,2
.dbline 105
; RW_L; //寫
cbi 0x1b,1
.dbline 106
; PORTD=dat; //送數據
out 0x12,R20
.dbline 107
; EN_H;
sbi 0x1b,0
.dbline 108
; DelayMS(1); //延時不可少,否則數據丟失
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline 109
; EN_L; //下降沿寫入
ldi R24,254
out 0x1b,R24
.dbline -2
L17:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r dat 20 c
.dbend
.dbfunc e set_xy _set_xy fV
; y -> R20
; x -> R22
.even
_set_xy::
xcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 113
; }
; /******************設置行列******************/
; void set_xy(uchar x,uchar y) //x從1-2,y從1-40
; {
.dbline 114
; if(x==1)
cpi R22,1
brne L19
.dbline 115
; {write_com(0x80+y-1);} //對y調整為寄存器地址
.dbline 115
mov R16,R20
subi R16,128 ; addi 128
subi R16,1
xcall _write_com
.dbline 115
xjmp L20
L19:
.dbline 117
.dbline 117
mov R16,R20
subi R16,64 ; addi 192
subi R16,1
xcall _write_com
.dbline 117
L20:
.dbline -2
L18:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r y 20 c
.dbsym r x 22 c
.dbend
.dbfunc e main _main fV
; i -> R20
.even
_main::
.dbline -1
.dbline 121
; else
; {write_com(0x80+0x40+y-1);}
; }
; /*******************主函數********************/
; void main()
; {
.dbline 123
; uchar i;
; init_devices(); //單片機、1602初始化
xcall _init_devices
.dbline 126
;
; ///***********************************第一種方法**************************************
; set_xy(1,1); //數據放入第1行第18列以后的寄存器
ldi R18,1
ldi R16,1
xcall _set_xy
.dbline 127
; DelayMS(1); //若出現亂碼,可加適當延時
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline 128
; for(i=0;i<15;i++) //循環table1的字符數
clr R20
xjmp L25
L22:
.dbline 129
.dbline 130
ldi R24,<_table1
ldi R25,>_table1
mov R30,R20
clr R31
add R30,R24
adc R31,R25
lpm R16,Z
xcall _write_dat
.dbline 131
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline 132
L23:
.dbline 128
inc R20
L25:
.dbline 128
cpi R20,15
brlo L22
.dbline 133
; {
; write_dat(table1[i]); //寫入第i個字符
; DelayMS(1); //若出現亂碼,可加適當延時
; }
; set_xy(2,1); //數據放入第2行第20列以后的寄存器
ldi R18,1
ldi R16,2
xcall _set_xy
.dbline 134
; DelayMS(1); //若出現亂碼,可加適當延時
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline 135
; for(i=0;i<15;i++) //循環table2的字符數
clr R20
xjmp L29
L26:
.dbline 136
.dbline 137
ldi R24,<_table2
ldi R25,>_table2
mov R30,R20
clr R31
add R30,R24
adc R31,R25
lpm R16,Z
xcall _write_dat
.dbline 138
ldi R16,1
ldi R17,0
xcall _DelayMS
.dbline 139
L27:
.dbline 135
inc R20
L29:
.dbline 135
cpi R20,15
brlo L26
.dbline -2
L21:
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -