📄 lcdshow.s
字号:
.module LCDShow.c
.area text
; n -> 4,X
; m -> 3,X
; str -> 2,X
_LcdshowCharacter::
tsx
; /*文件描述:本文件包含了用HD44780显示相关的3个子程序 *
; * 1. LCDShow:在LCD上显示32个字符 *
; * 2. LcdInit:初始化Lcd *
; * 3. Lcd_Command:执行给定的cmd命令 *
; *-------------《嵌入式应用技术基础教程》--------------*/
; //[以下为子程序源代码]
; //[头文件]
; #include "GP32C.h" //包含头文件
;
; #define LcdData PTB //Lcd显示数据传送口
; #define LcdData_D DDRB //数据口方向寄存器
; #define LcdCtrl PTC //Lcd控制信号传送口
; #define LcdCtrl_D DDRC //控制口方向寄存器
; #define LcdRS 0 //Lcd寄存器选择信号PTC0
; #define LcdRW 1 //读写信号接PTC1
; #define LcdE 2 //Lcd使能信号接PTC2
;
; //内部调用子程序
; void Lcd_Command(unsigned char cmd); //命令执行子程序
; void LcdInit(void); //Lcd初始化子程序
; //在HD44780显示屏上显示一个字符子函数
; void LcdshowCharacter(unsigned char str,unsigned char m,unsigned char n);
; unsigned char ChangeASCII(unsigned char x); //转换数值x为对应的ASCII码子函数
; //外部变量
; extern unsigned char time[14];
; extern unsigned char alarm[14];
; extern unsigned char Ttime[3];
; extern int Tdate[3];
; extern unsigned char Ttime2[3];
; extern int Tdate2[3];
;
;
;
;
;
; /*LcdshowCharacter:在HD44780显示屏上显示一个字符--------------------*
; *功能描述:在HD44780显示屏上第m行,第n列显示字符str *
; *参 数:str:待显示字符 *
; *返 回:无 *
; *------------------以上为子程序说明-------------------*/
; void LcdshowCharacter(unsigned char str,unsigned char m,unsigned char n)
; {
; LcdCtrl&=~(1<<LcdRS); //RS、R/W=00,写指令
bclr #0,0x2
; LcdCtrl&=~(1<<LcdRW);
bclr #1,0x2
; Lcd_Command(0b10000000|((m-1)*0x40+(n-1)));
lda 4,X
sub #1
sta *__r0
lda 3,X
sub #1
nsa
and #-16
lsla
lsla
add *__r0
ora #-128
psha
jsr _Lcd_Command
ais #1
tsx
; LcdCtrl|=1<<LcdRS; //RS、R/W=10,写数据到DDRAM中
bset #0,0x2
; LcdCtrl&=~(1<<LcdRW);
bclr #1,0x2
; Lcd_Command(str);
lda 2,X
psha
jsr _Lcd_Command
ais #1
tsx
L1:
.dbline 0 ; func end
rts
; y -> 0,X
; x -> 3,X
_ChangeASCII::
ais #-1
tsx
; }
;
; unsigned char ChangeASCII(unsigned char x) //转换数值x为对应的ASCII码
; {
; unsigned char y;
; return y=x+0x30;
lda 3,X
add #48
sta *__r1
sta ,X
mov *__r1,*__r0
lda *__r1
L2:
ais #1
.dbline 0 ; func end
rts
; i -> 0,X
; m -> 6,X
; n -> 5,X
; str -> 3,X
_LcdShowString::
ais #-1
tsx
; }
;
; //显示大小为n字符数组在第m行的子函数
; void LcdShowString(unsigned char str[],unsigned char n,unsigned char m)
; {
; unsigned char i;
; LcdInit();
jsr _LcdInit
tsx
; for(i=0;i<n;i++)
clr ,X
bra L7
L4:
lda ,X
add #1
psha
lda 6,X
psha
clr *__r0
lda ,X
add 4,X
sta *__r1
lda *__r0
adc 3,X
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _LcdshowCharacter
ais #3
tsx
L5:
inc ,X
L7:
lda ,X
cmp 5,X
blo L4
L3:
ais #1
.dbline 0 ; func end
rts
; i -> 0,X
; temp -> 3,X
_Lcdshow::
ais #-1
tsx
; {
; LcdshowCharacter(str[i],m,(i+1));
; }
; }
;
;
;
; void Lcdshow(unsigned char temp[]) //显示日期时间子程序
; { unsigned char i;
; LcdInit();
jsr _LcdInit
tsx
; for(i=0;i<4;i++)
clr ,X
bra L12
L9:
clr *__r0
lda ,X
add 4,X
sta *__r1
lda *__r0
adc 3,X
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
tsx
sta *__r1
lda ,X
add #4
psha
lda #1
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
tsx
L10:
inc ,X
L12:
lda ,X
cmp #4
blo L9
; {
; LcdshowCharacter(ChangeASCII(temp[i]),1,(i+4));
; }
;
; LcdshowCharacter('-',1,8);
lda #8
psha
lda #1
psha
lda #45
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[4]),1,9);
lda 4,X
add #4
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #9
psha
lda #1
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[5]),1,10);
lda 4,X
add #5
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #10
psha
lda #1
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
; LcdshowCharacter('-',1,11);
lda #11
psha
lda #1
psha
lda #45
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[6]),1,12);
lda 4,X
add #6
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #12
psha
lda #1
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[7]),1,13);
lda 4,X
add #7
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #13
psha
lda #1
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[8]),2,5);
lda 4,X
add #8
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #5
psha
lda #2
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[9]),2,6);
lda 4,X
add #9
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #6
psha
lda #2
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
; LcdshowCharacter(':',2,7);
lda #7
psha
lda #2
psha
lda #58
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[10]),2,8);
lda 4,X
add #10
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #8
psha
lda #2
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[11]),2,9);
lda 4,X
add #11
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #9
psha
lda #2
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
; LcdshowCharacter(':',2,10);
lda #10
psha
lda #2
psha
lda #58
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[12]),2,11);
lda 4,X
add #12
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #11
psha
lda #2
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
tsx
; LcdshowCharacter(ChangeASCII(temp[13]),2,12);
lda 4,X
add #13
sta *__r1
lda 3,X
adc #0
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _ChangeASCII
ais #1
sta *__r1
lda #12
psha
lda #2
psha
lda *__r1
psha
jsr _LcdshowCharacter
ais #3
tsx
L8:
ais #1
.dbline 0 ; func end
rts
; i -> 0,X
_LcdInit::
ais #-1
tsx
;
; }
;
; /*LcdInit:初始化Lcd------------------------------------*
; *功 能:初始化Lcd(HD44780),设置显示方式,清屏,AC自动+1 *
; *参 数:无 *
; *返 回:无 *
; *-----------------------------------------------------*/
; void LcdInit(void)
; {
; unsigned char i;
; LcdData_D=0b11111111; //数据口为输出
lda #-1
sta 0x5
; LcdCtrl_D|=(1<<LcdE); //控制口低三位为输出
bset #2,0x6
; LcdCtrl_D|=(1<<LcdRS);
bset #0,0x6
; LcdCtrl_D|=(1<<LcdRW);
bset #1,0x6
; LcdCtrl|=(1<<LcdE); //E=1
bset #2,0x2
; LcdCtrl&=~(1<<LcdRS); //RS、R/W=00,写指令
bclr #0,0x2
; LcdCtrl&=~(1<<LcdRW);
bclr #1,0x2
; Lcd_Command(0b00111000); //8位数据接口,2行,5*7点阵
lda #56
psha
jsr _Lcd_Command
ais #1
; Lcd_Command(0b00001000); //关显示,关光标显示,不闪烁
lda #8
psha
jsr _Lcd_Command
ais #1
; Lcd_Command(0b00000001); //清屏
lda #1
psha
jsr _Lcd_Command
ais #1
tsx
clr ,X
bra L17
L14:
L15:
inc ,X
L17:
; for(i=0;i<250;i++); //延时>1.6ms
lda ,X
cmp #-6
blo L14
clr ,X
bra L21
L18:
L19:
inc ,X
L21:
; for(i=0;i<250;i++);
lda ,X
cmp #-6
blo L18
; Lcd_Command(0b00001100); //开显示,关光标显示,不闪烁
lda #12
psha
jsr _Lcd_Command
ais #1
tsx
L13:
ais #1
.dbline 0 ; func end
rts
; i -> 0,X
; cmd -> 3,X
_Lcd_Command::
ais #-1
tsx
; }
; /*Lcd_Command:执行给定的cmd命令------------------------*
; *功 能:执行给定的cmd命令,且延时 *
; *参 数:cmd:待执行的命令 *
; *返 回:无 *
; *-----------------------------------------------------*/
; void Lcd_Command(unsigned char cmd)
; {
clr ,X
bra L26
L23:
L24:
inc ,X
L26:
; unsigned char i;
; for (i=0;i<20;i++); //等待>40us
lda ,X
cmp #20
blo L23
; LcdData=cmd; //把指令码送到Lcd数据传送口
lda 3,X
sta 0x1
; LcdCtrl|=(1<<LcdE); //Lcd开始接收数据
bset #2,0x2
; asm("NOP");
NOP
; asm("NOP");
NOP
; asm("NOP");
NOP
; LcdCtrl&=~(1<<LcdE); //Lcd结束接收数据
bclr #2,0x2
clr ,X
bra L30
L27:
L28:
inc ,X
L30:
; for (i=0;i<20;i++); //等待>40us
lda ,X
cmp #20
blo L27
L22:
ais #1
.dbline 0 ; func end
rts
; n -> 3,X
; m -> 2,X
_LcdShowCursor::
tsx
; }
;
; void LcdShowCursor(unsigned char m,unsigned char n) //显示光标在第m行,第n列
; {
; LcdCtrl&=~(1<<LcdRS); //RS、R/W=00,写指令
bclr #0,0x2
; LcdCtrl&=~(1<<LcdRW);
bclr #1,0x2
; Lcd_Command(0b00001111);
lda #15
psha
jsr _Lcd_Command
ais #1
tsx
; Lcd_Command(0b10000000|((m-1)*0x40+(n-1)));
lda 3,X
sub #1
sta *__r0
lda 2,X
sub #1
nsa
and #-16
lsla
lsla
add *__r0
ora #-128
psha
jsr _Lcd_Command
ais #1
tsx
L31:
.dbline 0 ; func end
rts
; n -> 8,X
; m -> 7,X
; temp -> 5,X
; Keyvalue -> 4,X
_Transmission::
ais #-2
tsx
; }
;
;
;
;
;
; /*void LcdShowMenu(void) //显示菜单
; {
; unsigned char temp[12]="1. Set Time";
; unsigned char temp2[13]="2. Set Alarm";
; unsigned char i;
; LcdInit();
; for(i=0;i<11;i++)
; {
; LcdshowCharacter(temp[i],1,(i+1));
; }
; for(i=0;i<12;i++)
; {
; LcdshowCharacter(temp2[i],2,(i+1));
; }
; }*/
;
; //将输入的键值传送到相应位置的位
; void Transmission(unsigned char Keyvalue,unsigned char temp[],unsigned char m,unsigned char n)
; {
; if(m==1) //在第一行
lda 7,X
cmp #1
beq X16
jmp L33
X16:
; {
; switch(n)
clr ,X
lda 8,X
sta 1,X
lda ,X
bne X0
lda 1,X
cmp #4
beq L38
X0:
lda ,X
bne X1
lda 1,X
cmp #5
beq L39
X1:
lda ,X
bne X2
lda 1,X
cmp #6
beq L40
X2:
lda ,X
bne X3
lda 1,X
cmp #7
beq L41
X3:
lda ,X
bne X4
lda 1,X
cmp #9
bne X17
jmp L42
X17:
X4:
lda ,X
bne X5
lda 1,X
cmp #10
bne X18
jmp L43
X18:
X5:
lda ,X
bne X6
lda 1,X
cmp #12
bne X19
jmp L44
X19:
X6:
lda ,X
bne X7
lda 1,X
cmp #13
bne X20
jmp L45
X20:
X7:
jmp L35
X8:
; {
L38:
; case 4:temp[0]=Keyvalue;break;
lda 6,X
sta *__r1
lda 5,X
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
jmp L36
L39:
; case 5:temp[1]=Keyvalue;break;
lda 6,X
add #1
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L36
L40:
; case 6:temp[2]=Keyvalue;break;
lda 6,X
add #2
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L36
L41:
; case 7:temp[3]=Keyvalue;break;
lda 6,X
add #3
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L36
L42:
; case 9:temp[4]=Keyvalue;break;
lda 6,X
add #4
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L36
L43:
; case 10:temp[5]=Keyvalue;break;
lda 6,X
add #5
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L36
L44:
; case 12:temp[6]=Keyvalue;break;
lda 6,X
add #6
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L36
L45:
; case 13:temp[7]=Keyvalue;break;
lda 6,X
add #7
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
L35:
L36:
;
; }
; }
L33:
; if(m==2) //在第二行
lda 7,X
cmp #2
beq X21
jmp L46
X21:
; {
; switch(n)
clr ,X
lda 8,X
sta 1,X
lda ,X
bne X9
lda 1,X
cmp #5
beq L51
X9:
lda ,X
bne X10
lda 1,X
cmp #6
beq L52
X10:
lda ,X
bne X11
lda 1,X
cmp #8
beq L53
X11:
lda ,X
bne X12
lda 1,X
cmp #9
beq L54
X12:
lda ,X
bne X13
lda 1,X
cmp #11
beq L55
X13:
lda ,X
bne X14
lda 1,X
cmp #12
beq L56
X14:
bra L48
X15:
; {
L51:
; case 5:temp[8]=Keyvalue;break;
lda 6,X
add #8
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L49
L52:
; case 6:temp[9]=Keyvalue;break;
lda 6,X
add #9
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L49
L53:
; case 8:temp[10]=Keyvalue;break;
lda 6,X
add #10
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L49
L54:
; case 9:temp[11]=Keyvalue;break;
lda 6,X
add #11
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L49
L55:
; case 11:temp[12]=Keyvalue;break;
lda 6,X
add #12
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
bra L49
L56:
; case 12:temp[13]=Keyvalue;break;
lda 6,X
add #13
sta *__r1
lda 5,X
adc #0
sta *__r0
lda 4,X
ldhx *__r0
sta ,x
tsx
L48:
L49:
; }
; }
L46:
L32:
ais #2
.dbline 0 ; func end
rts
; m -> 2,X
_Discriminant::
tsx
; }
;
; //判断按下的键是否数字键
; unsigned char Discriminant(unsigned char m)
; {
; if(m=='1'||m=='2'||m=='3'||m=='4'||m=='5'||m=='6'||m=='7'||m=='8'||m=='9'||m=='0')
lda 2,X
cmp #49
beq L68
cmp #50
beq L68
cmp #51
beq L68
cmp #52
beq L68
cmp #53
beq L68
cmp #54
beq L68
cmp #55
beq L68
cmp #56
beq L68
cmp #57
beq L68
cmp #48
bne L58
L68:
; return 1;
lda #1
bra L57
L58:
; else return 0;
clra
L57:
.dbline 0 ; func end
rts
; u -> 0,X
; v -> 1,X
_Delay::
ais #-2
tsx
; }
;
; void Delay(void)
; { unsigned char u;
; unsigned char v;
; for(u=0;u<=250;u++)
clr ,X
bra L73
L70:
clr 1,X
bra L77
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -