?? 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 + -