📄 1602.s
字号:
.module _1602.c
.area text(rom, con, rel)
.dbfile D:\学习工具\单片机程序\1602液晶\1602.c
.area code(ram, con, rel)
.dbfile D:\学习工具\单片机程序\1602液晶\1602.c
.area lit(rom, con, rel)
_table_1::
.byte 49,53,49,53,52,56,52,49,54,54,0
.dbsym e table_1 _table_1 A[11:11]kc
.area data(ram, con, rel)
.dbfile D:\学习工具\单片机程序\1602液晶\1602.c
_table_2::
.blkb 2
.area idata
.byte 48,48
.area data(ram, con, rel)
.dbfile D:\学习工具\单片机程序\1602液晶\1602.c
.blkb 2
.area idata
.byte 45,48
.area data(ram, con, rel)
.dbfile D:\学习工具\单片机程序\1602液晶\1602.c
.blkb 2
.area idata
.byte 48,45
.area data(ram, con, rel)
.dbfile D:\学习工具\单片机程序\1602液晶\1602.c
.blkb 2
.area idata
.byte 48,48
.area data(ram, con, rel)
.dbfile D:\学习工具\单片机程序\1602液晶\1602.c
.dbsym e table_2 _table_2 A[8:8]c
.area text(rom, con, rel)
.dbfile D:\学习工具\单片机程序\1602液晶\1602.c
.dbfunc e WriteDataLCM _WriteDataLCM fV
; WDLCM -> R10
.even
_WriteDataLCM::
st -y,R10
mov R10,R16
.dbline -1
.dbline 71
; //把明浩的1602的程序移植到了ATMEGA8上,共享一下。
; /*============================================================
; 使用1602液晶显示的实验例子 明浩 2004/2/27
; ==============================================================
;
; SMC1602A(16*2)模拟口线接线方式
; 连接线图:
; ---------------------------------------------------
; |LCM-----51 | LCM-----51 | LCM------51 |
; --------------------------------------------------|
; |DB0-----P1.0 | DB4-----P1.4 | RW-------P2.0 |
; |DB1-----P1.1 | DB5-----P1.5 | RS-------P2.1 |
; |DB2-----P1.2 | DB6-----P1.6 | E--------P2.2 |
; |DB3-----P1.3 | DB7-----P1.7 | VLCD接1K电阻到GND|
; ---------------------------------------------------
;
; SMC1602A(16*2)模拟口线接线方式
; 连接线图:
; ---------------------------------------------------
; |LCM-----M8 | LCM-----M8 | LCM------M8 |
; ----------------------------------------------|
; |DB0-----PB0 | DB4-----PB4 | RW-------PD6 |
; |DB1-----PB1 | DB5-----PB5 | RS-------PD7 |
; |DB2-----PB2 | DB6-----PB6 | E--------PD5 |
; |DB3-----PB3 | DB7-----PB7 | VLCD接1K电阻到GND|
; ---------------------------------------------------
; ==============================================================*/
; #include <iom16V.h>
; #include <macros.h>
;
; #define CTLPORT PORTD //模拟总线用了PD口的PD5,PD6,PD7
; #define LCD_RS 5 // pin-0 on CTLPORT
; #define LCD_RW 6 // pin-1 on CTLPORT
; #define LCD_E 7 // pin-2 on CTLPORT
;
; #define SET_LCD_E CTLPORT|=(1<<LCD_E) // LCD: E = 1
; #define CLR_LCD_E CTLPORT&=~(1<<LCD_E) // LCD: E = 0
; #define SET_LCD_RW CTLPORT|=(1<<LCD_RW) // LCD: R/W = 1 (read)
; #define CLR_LCD_RW CTLPORT&=~(1<<LCD_RW) // LCD: R/W = 0 (write)
; #define SET_LCD_RS CTLPORT|=(1<<LCD_RS) // LCD: R/S = 1 (data reg)
; #define CLR_LCD_RS CTLPORT&=~(1<<LCD_RS) // LCD: R/S = 0 (status reg)
;
; //#define DataPortOUT PORTB // 数据端口PB口
; //#define DataPortIN PINB
; #define DataPortfx DDRB
; #define Busy 0x80
; #define LCM_Data PORTB // 数据端口PB口
; #define LCM_Data1 PINB // 数据端口PB口
;
; #pragma data:code
; unsigned char const table_1[] = {"1515484166"};
; //unsigned char table_2[] = {'0','0','-','0','0','-','0','0'};
; #pragma data:data
; unsigned char table_2[] = {'0','0','-','0','0','-','0','0'};
; void WriteDataLCM(unsigned char WDLCM);
; void WriteCommandLCM(unsigned char WCLCM,unsigned char BuysC);
; unsigned char ReadDataLCM(void);
; unsigned char ReadStatusLCM(void);
; void LCMInit(void);
; void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
; void DisplayListChar(unsigned char X, unsigned char Y, unsigned char const *DData);
; void Delay5Ms(void);
; void Delay400Ms(void);
;
;
;
;
;
; //写数据
; void WriteDataLCM(unsigned char WDLCM)
; {
.dbline 72
; ReadStatusLCM(); //检测忙
xcall _ReadStatusLCM
.dbline 73
; LCM_Data = WDLCM;
out 0x18,R10
.dbline 74
; SET_LCD_RS;
sbi 0x12,5
.dbline 75
; CLR_LCD_RW;
cbi 0x12,6
.dbline 76
; SET_LCD_RS;
sbi 0x12,5
.dbline 77
; CLR_LCD_RW;
cbi 0x12,6
.dbline 78
; CLR_LCD_E; //若晶振速度太高可以在这后加小的延时
cbi 0x12,7
.dbline 79
; CLR_LCD_E; //延时
cbi 0x12,7
.dbline 80
; CLR_LCD_E;
cbi 0x12,7
.dbline 81
; CLR_LCD_E;
cbi 0x12,7
.dbline 82
; CLR_LCD_E;
cbi 0x12,7
.dbline 83
; CLR_LCD_E;
cbi 0x12,7
.dbline 84
; SET_LCD_E;
sbi 0x12,7
.dbline 85
; SET_LCD_E;
sbi 0x12,7
.dbline -2
L1:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym r WDLCM 10 c
.dbend
.dbfunc e WriteCommandLCM _WriteCommandLCM fV
; BuysC -> R12
; WCLCM -> R10
.even
_WriteCommandLCM::
st -y,R10
st -y,R12
mov R12,R18
mov R10,R16
.dbline -1
.dbline 90
; }
;
; //写指令
; void WriteCommandLCM(unsigned char WCLCM,unsigned char BuysC) //BuysC为0时忽略忙检测
; {
.dbline 91
; if (BuysC) ReadStatusLCM(); //根据需要检测忙
tst R12
breq L3
X0:
.dbline 91
xcall _ReadStatusLCM
L3:
.dbline 92
; LCM_Data = WCLCM;
out 0x18,R10
.dbline 93
; CLR_LCD_RS;
cbi 0x12,5
.dbline 94
; CLR_LCD_RW;
cbi 0x12,6
.dbline 95
; CLR_LCD_E;
cbi 0x12,7
.dbline 96
; CLR_LCD_E;
cbi 0x12,7
.dbline 97
; CLR_LCD_E;
cbi 0x12,7
.dbline 98
; CLR_LCD_E;
cbi 0x12,7
.dbline 99
; CLR_LCD_E;
cbi 0x12,7
.dbline 100
; CLR_LCD_E;
cbi 0x12,7
.dbline 101
; SET_LCD_E;
sbi 0x12,7
.dbline 102
; SET_LCD_E;
sbi 0x12,7
.dbline -2
L2:
.dbline 0 ; func end
ld R12,y+
ld R10,y+
ret
.dbsym r BuysC 12 c
.dbsym r WCLCM 10 c
.dbend
.dbfunc e ReadDataLCM _ReadDataLCM fc
.even
_ReadDataLCM::
.dbline -1
.dbline 107
; }
;
; //读数据
; unsigned char ReadDataLCM(void)
; {
.dbline 108
; SET_LCD_RS;
sbi 0x12,5
.dbline 109
; SET_LCD_RW;
sbi 0x12,6
.dbline 110
; CLR_LCD_E;
cbi 0x12,7
.dbline 111
; CLR_LCD_E;
cbi 0x12,7
.dbline 112
; CLR_LCD_E;
cbi 0x12,7
.dbline 113
; CLR_LCD_E;
cbi 0x12,7
.dbline 114
; CLR_LCD_E;
cbi 0x12,7
.dbline 115
; CLR_LCD_E;
cbi 0x12,7
.dbline 116
; CLR_LCD_E;
cbi 0x12,7
.dbline 117
; SET_LCD_E;
sbi 0x12,7
.dbline 118
; SET_LCD_E;
sbi 0x12,7
.dbline 119
; return(LCM_Data);
in R16,0x18
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbend
.dbfunc e ReadStatusLCM _ReadStatusLCM fc
.even
_ReadStatusLCM::
.dbline -1
.dbline 124
; }
;
; //读状态
; unsigned char ReadStatusLCM(void)
; {
.dbline 125
; DDRB=0x00; //输入
clr R2
out 0x17,R2
.dbline 126
; CLR_LCD_RS;
cbi 0x12,5
.dbline 127
; SET_LCD_RW;
sbi 0x12,6
.dbline 128
; CLR_LCD_E;
cbi 0x12,7
.dbline 129
; CLR_LCD_E;
cbi 0x12,7
.dbline 130
; CLR_LCD_E;
cbi 0x12,7
.dbline 131
; CLR_LCD_E;
cbi 0x12,7
.dbline 132
; SET_LCD_E;
sbi 0x12,7
L7:
.dbline 133
; while (LCM_Data1 & Busy); //检测忙信号
L8:
.dbline 133
sbic 0x16,7
rjmp L7
X1:
.dbline 134
; DDRB=0xff;//变回输出
ldi R24,255
out 0x17,R24
.dbline 135
; return(LCM_Data1);
in R16,0x16
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCMInit _LCMInit fV
.even
_LCMInit::
.dbline -1
.dbline 139
; }
;
; void LCMInit(void) //LCM初始化
; {
.dbline 140
; LCM_Data = 0;
clr R2
out 0x18,R2
.dbline 141
; WriteCommandLCM(0x38,0); //三次显示模式设置,不检测忙信号
clr R18
ldi R16,56
xcall _WriteCommandLCM
.dbline 142
; Delay5Ms();
xcall _Delay5Ms
.dbline 143
; WriteCommandLCM(0x38,0);
clr R18
ldi R16,56
xcall _WriteCommandLCM
.dbline 144
; Delay5Ms();
xcall _Delay5Ms
.dbline 145
; WriteCommandLCM(0x38,0);
clr R18
ldi R16,56
xcall _WriteCommandLCM
.dbline 146
; Delay5Ms();
xcall _Delay5Ms
.dbline 148
;
; WriteCommandLCM(0x38,1); //显示模式设置,开始要求每次检测忙信号
ldi R18,1
ldi R16,56
xcall _WriteCommandLCM
.dbline 149
; WriteCommandLCM(0x08,1); //关闭显示
ldi R18,1
ldi R16,8
xcall _WriteCommandLCM
.dbline 150
; WriteCommandLCM(0x01,1); //显示清屏
ldi R18,1
ldi R16,1
xcall _WriteCommandLCM
.dbline 151
; WriteCommandLCM(0x06,1); // 显示光标移动设置
ldi R18,1
ldi R16,6
xcall _WriteCommandLCM
.dbline 152
; WriteCommandLCM(0x0C,1); // 显示开及光标设置
ldi R18,1
ldi R16,12
xcall _WriteCommandLCM
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbend
.dbfunc e DisplayOneChar _DisplayOneChar fV
; DData -> y+2
; Y -> R22
; X -> R20
.even
_DisplayOneChar::
st -y,R20
st -y,R22
mov R22,R18
mov R20,R16
.dbline -1
.dbline 157
; }
;
; //按指定位置显示一个字符
; void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
; {
.dbline 158
; Y &= 0x1;
andi R22,1
.dbline 159
; X &= 0xF; //限制X不能大于15,Y不能大于1
andi R20,15
.dbline 160
; if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;
tst R22
breq L12
X2:
.dbline 160
ori R20,64
L12:
.dbline 161
; X |= 0x80; //算出指令码
ori R20,128
.dbline 162
; WriteCommandLCM(X, 1); //这里不检测忙信号,发送地址码
ldi R18,1
mov R16,R20
xcall _WriteCommandLCM
.dbline 163
; WriteDataLCM(DData);
ldd R16,y+2
xcall _WriteDataLCM
.dbline 164
; WriteCommandLCM(X, 0); //光标返回,调节时很重要
clr R18
mov R16,R20
xcall _WriteCommandLCM
.dbline -2
L11:
.dbline 0 ; func end
ld R22,y+
ld R20,y+
ret
.dbsym l DData 2 c
.dbsym r Y 22 c
.dbsym r X 20 c
.dbend
.dbfunc e DisplayListChar _DisplayListChar fV
; ListLength -> R10
; DData -> R12,R13
; Y -> R22
; X -> R20
.even
_DisplayListChar::
xcall push_xgsetF03C
mov R22,R18
mov R20,R16
sbiw R28,1
ldd R12,y+9
ldd R13,y+10
.dbline -1
.dbline 169
; }
;
; //按指定位置显示一串字符
; void DisplayListChar(unsigned char X, unsigned char Y, unsigned char const *DData)
; {
.dbline 172
; unsigned char ListLength;
;
; ListLength = 0;
clr R10
.dbline 173
; Y &= 0x1;
andi R22,1
.dbline 174
; X &= 0xF; //限制X不能大于15,Y不能大于1
andi R20,15
xjmp L16
L15:
.dbline 176
; while (DData[ListLength]>0x20) //若到达字串尾则退出
; {
.dbline 177
; if (X <= 0xF) //X坐标应小于0xF
ldi R24,15
cp R24,R20
brlo L18
X3:
.dbline 178
; {
.dbline 179
; DisplayOneChar(X, Y, DData[ListLength]); //显示单个字符
mov R30,R10
clr R31
add R30,R12
adc R31,R13
lpm R2,Z
std y+0,R2
mov R18,R22
mov R16,R20
xcall _DisplayOneChar
.dbline 180
; ListLength++;
inc R10
.dbline 181
; X++;
inc R20
.dbline 182
; }
L18:
.dbline 183
; }
L16:
.dbline 175
mov R30,R10
clr R31
add R30,R12
adc R31,R13
lpm R2,Z
ldi R24,32
cp R24,R2
brlo L15
X4:
.dbline -2
L14:
.dbline 0 ; func end
adiw R28,1
xjmp pop_xgsetF03C
.dbsym r ListLength 10 c
.dbsym r DData 12 pkc
.dbsym r Y 22 c
.dbsym r X 20 c
.dbend
.dbfunc e Delay5Ms _Delay5Ms fV
; TempCyc -> R16,R17
.even
_Delay5Ms::
.dbline -1
.dbline 188
; }
;
; //5ms延时
; void Delay5Ms(void)
; {
.dbline 189
; unsigned int TempCyc = 5552;
ldi R16,5552
ldi R17,21
L21:
.dbline 190
; while(TempCyc--);
L22:
.dbline 190
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L21
tst R3
brne L21
X5:
.dbline -2
L20:
.dbline 0 ; func end
ret
.dbsym r TempCyc 16 i
.dbend
.dbfunc e Delay400Ms _Delay400Ms fV
; TempCycA -> R16
; TempCycB -> R18,R19
.even
_Delay400Ms::
.dbline -1
.dbline 195
; }
;
; //400ms延时
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -