📄 main.s
字号:
.module main.c
.area data
_k::
.blkb 1
.area idata
.byte 0
.area data
_l::
.blkb 1
.area idata
.byte 0
.area data
_Alarm_Flag::
.blkb 1
.area idata
.byte 1
.area data
.area text
; u2 -> 0,X
; u1 -> 1,X
_delay::
ais #-2
tsx
clr 1,X
bra L5
L2:
L3:
inc 1,X
L5:
; /*-----------------------------------------------------*
; *工 程 名:
; *硬件连接:
; *程序描述: SD-HC08 模板生成
; */
; /*[头文件]*/
; #include "GP32C.h" //映像寄存器地址头文件
; #include "KB.h" //键盘中断头文件
; #define PTC1 1
; /*[函数声明]*/
; //在LCD第m行第n列显示一个字符
; extern void LcdshowCharacter(unsigned char str,unsigned char m,unsigned char n);
; extern void Lcd_Command(unsigned char cmd); //命令执行子程序
; extern void Lcdshowtime(void); //显示时钟
; extern void Lcdshowalarm(void); //显示闹钟
; extern unsigned char ChangeASCII(unsigned char x); //转换数值x为对应的ASCII码
; extern void Timer1init(void); //定时器1初始化
; extern void LcdInit(void); //Lcd初始化子程序
; extern unsigned char KB_Def(unsigned char KB_valve); //键值转为定义值函数
; extern void MoveCursor(unsigned char m,unsigned char n); //移到光标到第m行,第n列
; extern void LcdShowCursor(void); //开光标显示,闪烁
; extern unsigned char GetKey(void); //判断并获得按下键的定义值
; extern void LcdShowMenu(void); //显示菜单
; extern void LcdShowCursor(void); //开光标显示,闪烁
; //将输入的键值传送到相应位置的位
; void Transmission(unsigned char Keyvalue,unsigned char temp[],unsigned char m,unsigned char n);
; extern unsigned char Discriminant(unsigned char key); //判断按下的键是否数字键
; /*定义常量变量*/
; unsigned char time[14]; //存放时钟年、月、日、时、分、秒
; unsigned char alarm[14]; //存放闹钟的年、月、日、时、分、秒
; unsigned char Key; //存放按下键的定义值
; unsigned char k=0; //光标向右移动的次数
; unsigned char l=0; //光标向下移动的次数
; unsigned char t;
; unsigned char Alarm_Flag=1;
;
; void delay(void)
; {
; unsigned char u1,u2;
; for(u1=0;u1<200;u1++);
lda 1,X
cmp #-56
blo L2
clr ,X
bra L9
L6:
L7:
inc ,X
L9:
; for(u2=0;u2<220;u2++);
lda ,X
cmp #-36
blo L6
L1:
ais #2
.dbline 0 ; func end
rts
; i -> 0,X
; j -> 1,X
; n -> 2,X
; h -> 3,X
; Keyvalue -> 4,X
_main::
ais #-5
tsx
; }
;
; /*[主函数]*/
; void main()
; {
; unsigned char i,n,h;
; unsigned char j;
; unsigned char Keyvalue;
;
; asm("SEI"); //关总中断
SEI
; Timer1init(); //调定时器1初始化子程序
jsr _Timer1init
; KB_Init();
jsr _KB_Init
tsx
; INTKBSCR&= ~(1<<IntBit); //开放键盘中断(IMASKk=1)
bclr #1,0x1a
; asm("CLI"); //开总中断
CLI
;
; //赋时钟初始值2007年06月06日5点59分30秒;闹钟初始值2007年06月05日5时59分40秒
; time[0]=alarm[0]=2; time[1]=alarm[1]=0; time[2]=alarm[2]=0; time[3]=alarm[3]=7;
lda #2
sta *_alarm
lda #2
sta *_time
clr *_alarm+1
clr *_time+1
clr *_alarm+2
clr *_time+2
lda #7
sta *_alarm+3
lda #7
sta *_time+3
; time[4]=alarm[4]=0; time[5]=alarm[5]=6; time[6]=alarm[6]=0; time[7]=alarm[7]=6;
clr *_alarm+4
clr *_time+4
lda #6
sta *_alarm+5
lda #6
sta *_time+5
clr *_alarm+6
clr *_time+6
lda #6
sta *_alarm+7
lda #6
sta *_time+7
; time[8]=0;alarm[8]=0; time[9]=5; alarm[9]=5;time[10]=5; alarm[10]=5;time[11]=9;
clr *_time+8
clr *_alarm+8
lda #5
sta *_time+9
lda #5
sta *_alarm+9
lda #5
sta *_time+10
lda #5
sta *_alarm+10
lda #9
sta *_time+11
; alarm[11]=9;time[12]=3;alarm[12]=4; time[13]=0; alarm[13]=0;
lda #9
sta *_alarm+11
lda #3
sta *_time+12
lda #4
sta *_alarm+12
clr *_time+13
clr *_alarm+13
; i=time[13];
lda *_time+13
sta ,X
; DDRC=0xFF;
lda #-1
sta 0x6
jmp L40
L39:
;
; BEGING:
; while(1)
; {
; j=time[13];
lda *_time+13
sta 1,X
; if (i!=j) //时间有更新
lda ,X
cmp 1,X
beq L43
; {
; Lcdshowtime(); //显示日期时间
jsr _Lcdshowtime
tsx
; i=j;
lda 1,X
sta ,X
; }
L43:
;
; if(Key=='C')
lda *_Key
cmp #67
bne L45
; {
; Alarm_Flag++;
inc *_Alarm_Flag
; if (Alarm_Flag=1)Alarm_Flag=0;
lda #1
sta *_Alarm_Flag
lda #1
beq L47
clr *_Alarm_Flag
L47:
; }
L45:
;
;
; if((time[12]==0)&&(time[11]==0)&&(time[10]==0))
lda *_time+12
bne L49
lda *_time+11
bne L49
lda *_time+10
bne L49
; {
;
; n=time[9]+time[8]*10; //多少点就响多少下
lda *_time+8
ldx #10
mul
tsx
sta *__r0
lda *_time+9
add *__r0
sta 2,X
;
; //LcdshowCharacter('A', 1, 15);
;
;
; for(h=0;h<n;h++)
clr 3,X
bra L59
L56:
bset #1,0x2
jsr _delay
lda 0x2
ora #-3
sta 0x2
jsr _delay
tsx
L57:
inc 3,X
L59:
lda 3,X
cmp 2,X
blo L56
; {
; PTC|=1<<PTC1;
; delay();
; PTC|=~(1<<PTC1);
; delay();
; }
;
; }
L49:
;
; /* if((time[11]==0)&&(time[10]==0)&&(Alarm_Flag==1))
; {
; unsigned char h;
; for(h=0;h<=2;h++)
; {
; PTC|=1<<PTC1;
; delay();
; PTC|=~(1<<PTC1);
; delay();
; }
;
; }*/
;
;
; //闹钟程序
; if((time[13]==alarm[13])&&(time[12]==alarm[12])&&(time[11]==alarm[11])&&(time[10]==alarm[10])&&(time[9]==alarm[9])&&(time[8]==alarm[8])&&(Alarm_Flag==1))
lda *_time+13
cmp *_alarm+13
bne L60
lda *_time+12
cmp *_alarm+12
bne L60
lda *_time+11
cmp *_alarm+11
bne L60
lda *_time+10
cmp *_alarm+10
bne L60
lda *_time+9
cmp *_alarm+9
bne L60
lda *_time+8
cmp *_alarm+8
bne L60
lda *_Alarm_Flag
cmp #1
bne L60
; {
; //unsigned char h;
; for(h=0;h<=2;h++)
clr 3,X
bra L77
L74:
bset #1,0x2
jsr _delay
lda 0x2
ora #-3
sta 0x2
jsr _delay
tsx
L75:
inc 3,X
L77:
lda 3,X
cmp #2
bls L74
; {
; PTC|=1<<PTC1;
; delay();
; PTC|=~(1<<PTC1);
; delay();
;
; }
; }
L60:
;
;
; if(Key=='A') //弹出菜单
lda *_Key
cmp #65
beq X4
jmp L78
X4:
; {
L80:
; MENU: LcdShowMenu(); //显示菜单:1. Set Time;2. Set Alarm
jsr _LcdShowMenu
tsx
; Key=0;
clr *_Key
jmp L82
L81:
; while(1)
; {
; if(Key=='B') //返回
lda *_Key
cmp #66
bne L84
; {
; Key=0;
clr *_Key
; goto BEGING;
jmp L40
L84:
; }
; if(Key=='1') //选择子菜单1
lda *_Key
cmp #49
beq X5
jmp L86
X5:
; {
; Lcdshowtime();
jsr _Lcdshowtime
; LcdShowCursor(); //开光标显示,闪烁
jsr _LcdShowCursor
; MoveCursor(1,4); //光标初始位置(1,4),第一行第四列
lda #4
psha
lda #1
psha
jsr _MoveCursor
ais #2
tsx
; Key=0;
clr *_Key
jmp L89
L88:
; while(1)
; {
;
; if(Key=='#') //光标右移
lda *_Key
cmp #35
bne L91
; {
; ++k; //K为关标右移次数
inc *_k
; if(l%2==0) //现在光标在第一行 l为光标所在行数
lda *_l
ldx #2
clrh
div
pshh
pula
tsx
tsta
bne L93
; {
; if(k>9) k=0; //光标在末端时返回到起始位置
lda *_k
cmp #9
bls L95
clr *_k
L95:
; MoveCursor((1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
jsr _MoveCursor
ais #2
tsx
; }
bra L94
L93:
; else //现在光标在第二行
; {
; if(k>8) k=1; //现在光标在末端
lda *_k
cmp #8
bls L97
lda #1
sta *_k
L97:
; MoveCursor((1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
jsr _MoveCursor
ais #2
tsx
; }
L94:
; Key=0;
clr *_Key
;
; }
L91:
; if(Key=='*') //光标下移
lda *_Key
cmp #42
bne L99
; {
; ++l;
inc *_l
; // if(k==0) k++; //现在光标在第一行始端
; // if(k==9) k--; //现在光标在第一行末端
; if(l>1) l=0; //现在光标在第二行
lda *_l
cmp #1
bls L101
clr *_l
L101:
; MoveCursor((1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
jsr _MoveCursor
ais #2
tsx
; Key=0;
clr *_Key
; }
L99:
; if(Key=='B')
lda *_Key
cmp #66
bne L103
; {
; Key=0;
clr *_Key
; goto MENU; //返回
jmp L80
L103:
; }
; if(Key=='D') //按下确定键
lda *_Key
cmp #68
bne L105
; {
; Key=0;
clr *_Key
; goto BEGING;
jmp L40
L105:
; }
; if(Key!=0&&Discriminant(Key)) //Discriminant为判断是否按下数字键
lda *_Key
beq L107
lda *_Key
psha
jsr _Discriminant
ais #1
tsx
sta *__r1
beq L107
; {
; Keyvalue=Key-0x30;
lda *_Key
sub #48
sta 4,X
; Transmission(Keyvalue, (unsigned char *)time,(1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
lda #<_time
psha
lda #>_time
psha
lda 4,X
psha
jsr _Transmission
ais #5
; Lcdshowtime();
jsr _Lcdshowtime
; LcdShowCursor(); //开光标显示,闪烁
jsr _LcdShowCursor
; MoveCursor((1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
jsr _MoveCursor
ais #2
tsx
; Key=0;
clr *_Key
; }
L107:
L89:
jmp L88
X0:
;
; }
;
; }
L86:
;
; if(Key=='2') //选择子菜单2
lda *_Key
cmp #50
beq X6
jmp L109
X6:
; {
; Lcdshowalarm();
jsr _Lcdshowalarm
; LcdShowCursor(); //开光标显示,闪烁
jsr _LcdShowCursor
; MoveCursor(2,12); //光标初始位置(2,5),第二行第五列
lda #12
psha
lda #2
psha
jsr _MoveCursor
ais #2
tsx
; Key=0;
clr *_Key
jmp L112
L111:
; while(1)
; {
;
; if(Key=='#') //光标右移
lda *_Key
cmp #35
bne L114
; {
; ++k;
inc *_k
; if(l%2==0) //现在光标在第一行
lda *_l
ldx #2
clrh
div
pshh
pula
tsx
tsta
bne L116
; {
; if(k>9) k=0; //现在光标在末端
lda *_k
cmp #9
bls L118
clr *_k
L118:
; MoveCursor((1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
jsr _MoveCursor
ais #2
tsx
; }
bra L117
L116:
; else //现在光标在第二行
; {
; if(k>8) k=1; //现在光标在末端
lda *_k
cmp #8
bls L120
lda #1
sta *_k
L120:
; MoveCursor((1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
jsr _MoveCursor
ais #2
tsx
; }
L117:
; Key=0;
clr *_Key
;
; }
L114:
; if(Key=='*') //光标下移
lda *_Key
cmp #42
bne L122
; {
; ++l;
inc *_l
; if(k==0) k++; //现在光标在第一行始端
lda *_k
bne L124
inc *_k
L124:
; if(k==9) k--; //现在光标在第一行末端
lda *_k
cmp #9
bne L126
dec *_k
L126:
; if(l>1) l=0; //现在光标在第二行
lda *_l
cmp #1
bls L128
clr *_l
L128:
; MoveCursor((1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
jsr _MoveCursor
ais #2
tsx
; Key=0;
clr *_Key
; }
L122:
; if(Key=='B')
lda *_Key
cmp #66
bne L130
; {
; Key=0;
clr *_Key
; goto MENU; //返回
jmp L80
L130:
; }
; if(Key=='D') //按下确定键
lda *_Key
cmp #68
bne L132
; {
; Key=0;
clr *_Key
; goto BEGING;
bra L40
L132:
; }
; if(Key!=0&&Discriminant(Key))
lda *_Key
beq L134
lda *_Key
psha
jsr _Discriminant
ais #1
tsx
sta *__r1
beq L134
; {
; Keyvalue=Key-0x30;
lda *_Key
sub #48
sta 4,X
; Transmission(Keyvalue,(unsigned char *) alarm,(1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
lda #<_alarm
psha
lda #>_alarm
psha
lda 4,X
psha
jsr _Transmission
ais #5
; Lcdshowalarm();
jsr _Lcdshowalarm
; LcdShowCursor(); //开光标显示,闪烁
jsr _LcdShowCursor
; MoveCursor((1+l),(4+k));
lda *_k
add #4
psha
lda *_l
add #1
psha
jsr _MoveCursor
ais #2
tsx
; Key=0;
clr *_Key
; }
L134:
L112:
jmp L111
X1:
;
; }
; }
L109:
L82:
jmp L81
X2:
;
;
;
; }
;
; }
L78:
L40:
jmp L39
X3:
L10:
ais #5
.dbline 0 ; func end
rts
.area bss
_t::
.blkb 1
_Key::
.blkb 1
_alarm::
.blkb 14
_time::
.blkb 14
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -