?? lcd.s
字號:
.module lcd.c
.area text(rom, con, rel)
.dbfile D:\ac19-1\lcd.c
.dbfunc e ePutstr _ePutstr fV
; l -> R20
; i -> R22
; ptr -> R10,R11
; y -> R12
; x -> R14
.even
_ePutstr::
xcall push_gset5
mov R12,R18
mov R14,R16
sbiw R28,2
ldd R10,y+12
ldd R11,y+13
.dbline -1
.dbline 15
; #include <iom16v.h>
; #include <macros.h>
; #define uchar unsigned char
; #define uint unsigned int
; #define LCM_RS_1 PORTB|=BIT(PB0)
; #define LCM_RS_0 PORTB&=~BIT(PB0)
; #define LCM_RW_1 PORTB|=BIT(PB1)
; #define LCM_RW_0 PORTB&=~BIT(PB1)
; #define LCM_EN_1 PORTB|=BIT(PB2)
; #define LCM_EN_0 PORTB&=~BIT(PB2)
; #define DataPort PORTA
; #define Busy 0x80
; //***************************************
; void ePutstr(uchar x,uchar y,uchar const *ptr)
; {
.dbline 16
; uchar i,l=0;
clr R20
xjmp L3
L2:
.dbline 17
.dbline 17
inc R20
.dbline 17
L3:
.dbline 17
; while(ptr[l]>31){l++;}// ptr[l]大于31時,為ASCII碼,進入while語句循環,
mov R30,R20
clr R31
add R30,R10
adc R31,R11
lpm R30,Z
ldi R24,31
cp R24,R30
brlo L2
.dbline 19
clr R22
xjmp L8
L5:
.dbline 19
; //l累加,計算出字符串長度。
; for(i=0;i<l;i++){
.dbline 20
; DisplayOneChar(x++,y,ptr[i]);// 顯示單個字符,同時x軸座標遞增。
mov R30,R22
clr R31
add R30,R10
adc R31,R11
lpm R2,Z
clr R3
std y+1,R3
std y+0,R2
mov R18,R12
clr R19
mov R2,R14
clr R3
mov R24,R2
subi R24,255 ; addi 1
mov R14,R24
mov R16,R2
clr R17
xcall _DisplayOneChar
.dbline 21
; if(x==8){//若x等于16,進入if語句。
mov R24,R14
cpi R24,8
brne L9
.dbline 21
.dbline 22
; x=0;y^=1;// x賦0,y與1按位異或(取反)。
clr R14
.dbline 22
ldi R24,1
eor R12,R24
.dbline 23
; }
L9:
.dbline 24
L6:
.dbline 19
inc R22
L8:
.dbline 19
cp R22,R20
brlo L5
.dbline -2
L1:
adiw R28,2
xcall pop_gset5
.dbline 0 ; func end
ret
.dbsym r l 20 c
.dbsym r i 22 c
.dbsym r ptr 10 pkc
.dbsym r y 12 c
.dbsym r x 14 c
.dbend
.dbfunc e LocateXY _LocateXY fV
; temp -> R20
; posy -> R22
; posx -> R10
.even
_LocateXY::
xcall push_gset3
mov R22,R18
mov R10,R16
.dbline -1
.dbline 28
; }
; }
; //*************************************
; void LocateXY(char posx,char posy)
; {
.dbline 30
; uchar temp;
; temp&=0x7f;// temp 的變化范圍0~7。
andi R20,127
.dbline 31
; temp=posx&0x07;//屏蔽高5位。
mov R20,R10
andi R20,7
.dbline 32
; posy&=0x01;// posy的變化范圍0~1。
andi R22,1
.dbline 33
; switch(posy)
clr R23
cpi R22,1
ldi R30,0
cpc R23,R30
breq L15
xjmp L13
X0:
.dbline 34
; {
L15:
.dbline 35
; case 1:temp|=0x40;break;//若posy 為1(顯示第2行),地址碼+0x40。
ori R20,64
.dbline 35
.dbline 36
; default:break;
L13:
.dbline 38
; }
; temp|=0x80;//指令碼為地址碼+0x80。
ori R20,128
.dbline 39
; LcdWriteCommand(temp,0);// 將指令temp 寫入LCM,忽略忙信號檢測。
clr R18
clr R19
mov R16,R20
clr R17
xcall _LcdWriteCommand
.dbline -2
L11:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r posy 22 c
.dbsym r posx 10 c
.dbend
.dbfunc e DisplayOneChar _DisplayOneChar fV
; Wdata -> y+4
; y -> R22
; x -> R20
.even
_DisplayOneChar::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 43
; }
; //**************************************
; void DisplayOneChar(uchar x,uchar y,uchar Wdata)
; {
.dbline 44
; LocateXY(x,y);//調用LocateXY 函數定位顯示地址。
mov R18,R22
mov R16,R20
xcall _LocateXY
.dbline 45
; LcdWriteData(Wdata);//將數據Wdata寫入LCM。
ldd R16,y+4
clr R17
xcall _LcdWriteData
.dbline -2
L16:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l Wdata 4 c
.dbsym r y 22 c
.dbsym r x 20 c
.dbend
.dbfunc e InitLcd _InitLcd fV
.even
_InitLcd::
.dbline -1
.dbline 49
; }
; //****************************************
; void InitLcd(void)
; {
.dbline 50
; LcdWriteCommand(0x38,0); //8位數據傳送,2行顯示,5*7字形,不檢測忙信號
clr R18
clr R19
ldi R16,56
ldi R17,0
xcall _LcdWriteCommand
.dbline 51
; Delay_nms(5);
ldi R16,5
ldi R17,0
xcall _Delay_nms
.dbline 52
; LcdWriteCommand(0x38,0); //8位數據傳送,2行顯示,5*7字形,不檢測忙信號
clr R18
clr R19
ldi R16,56
ldi R17,0
xcall _LcdWriteCommand
.dbline 53
; Delay_nms(5);
ldi R16,5
ldi R17,0
xcall _Delay_nms
.dbline 54
; LcdWriteCommand(0x38,0); //8位數據傳送,2行顯示,5*7字形,不檢測忙信號
clr R18
clr R19
ldi R16,56
ldi R17,0
xcall _LcdWriteCommand
.dbline 55
; Delay_nms(5);
ldi R16,5
ldi R17,0
xcall _Delay_nms
.dbline 56
; LcdWriteCommand(0x38,1); //8位數據傳送,2行顯示,5*7字形,檢測忙信號
ldi R18,1
ldi R19,0
ldi R16,56
ldi R17,0
xcall _LcdWriteCommand
.dbline 57
; LcdWriteCommand(0x08,1); //關閉顯示,檢測忙信號
ldi R18,1
ldi R19,0
ldi R16,8
ldi R17,0
xcall _LcdWriteCommand
.dbline 58
; LcdWriteCommand(0x01,1); //清屏,檢測忙信號
ldi R18,1
ldi R19,0
ldi R16,1
ldi R17,0
xcall _LcdWriteCommand
.dbline 59
; LcdWriteCommand(0x06,1); //顯示光標右移設置,檢測忙信號
ldi R18,1
ldi R19,0
ldi R16,6
ldi R17,0
xcall _LcdWriteCommand
.dbline 60
; LcdWriteCommand(0x0c,1); //顯示屏打開,光標不顯示、不閃爍,檢測忙信號
ldi R18,1
ldi R19,0
ldi R16,12
ldi R17,0
xcall _LcdWriteCommand
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LcdWriteCommand _LcdWriteCommand fV
; Attribc -> R22
; CMD -> R20
.even
_LcdWriteCommand::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 64
; }
; //****************************************
; void LcdWriteCommand(uchar CMD,uchar Attribc)
; {
.dbline 65
; if(Attribc)WaitForEnable();
tst R22
breq L19
.dbline 65
xcall _WaitForEnable
L19:
.dbline 66
; Delay_nms(5);
ldi R16,5
ldi R17,0
xcall _Delay_nms
.dbline 67
; LCM_RS_0;LCM_RW_0;_NOP();
cbi 0x18,0
.dbline 67
cbi 0x18,1
.dbline 67
nop
.dbline 68
; DataPort=CMD;_NOP();
out 0x1b,R20
.dbline 68
nop
.dbline 69
; LCM_EN_1;_NOP();_NOP();LCM_EN_0;
sbi 0x18,2
.dbline 69
nop
.dbline 69
nop
.dbline 69
cbi 0x18,2
.dbline -2
L18:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r Attribc 22 c
.dbsym r CMD 20 c
.dbend
.dbfunc e LcdWriteData _LcdWriteData fV
; dataW -> R20
.even
_LcdWriteData::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 73
; }
; //***************************************
; void LcdWriteData(uchar dataW)
; {
.dbline 74
; WaitForEnable();
xcall _WaitForEnable
.dbline 75
; Delay_nms(5);
ldi R16,5
ldi R17,0
xcall _Delay_nms
.dbline 76
; LCM_RS_1;LCM_RW_0;_NOP();
sbi 0x18,0
.dbline 76
cbi 0x18,1
.dbline 76
nop
.dbline 77
; DataPort=dataW;_NOP();
out 0x1b,R20
.dbline 77
nop
.dbline 78
; LCM_EN_1;_NOP();_NOP();LCM_EN_0;
sbi 0x18,2
.dbline 78
nop
.dbline 78
nop
.dbline 78
cbi 0x18,2
.dbline -2
L21:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r dataW 20 c
.dbend
.dbfunc e WaitForEnable _WaitForEnable fV
; val -> R16
.even
_WaitForEnable::
.dbline -1
.dbline 82
; }
; //****************************************
; void WaitForEnable(void)
; {
.dbline 84
; uchar val;
; DataPort=0xff;
ldi R24,255
out 0x1b,R24
.dbline 85
; LCM_RS_0;LCM_RW_1;_NOP();
cbi 0x18,0
.dbline 85
sbi 0x18,1
.dbline 85
nop
.dbline 86
; LCM_EN_1;_NOP();_NOP();
sbi 0x18,2
.dbline 86
nop
.dbline 86
nop
.dbline 87
; DDRA=0x00;
clr R2
out 0x1a,R2
.dbline 88
; val=PINA;
in R16,0x19
xjmp L24
L23:
.dbline 89
.dbline 89
in R16,0x19
.dbline 89
wdr
.dbline 89
L24:
.dbline 89
; while(val&Busy){val=PINA;WDR();}
sbrc R16,7
rjmp L23
.dbline 90
; LCM_EN_0;
cbi 0x18,2
.dbline 91
; DDRA=0xff;
ldi R24,255
out 0x1a,R24
.dbline -2
L22:
.dbline 0 ; func end
ret
.dbsym r val 16 c
.dbend
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -