巧了,国亲无聊做了一个玩玩,给你看看把,其实电子钟挺简单的,下面是程序:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit ch=P3^2
sbit key=P3^5
sbit key1=P3^4
uchar t0,numn,numy,numr,nums,numf,numm,sw,w,q,b,s,g,sw1,w1,q1,b1,s1,g1,rq,temp,x
uint u
void init()
void display(uchar,uchar,uchar,uchar,uchar,uchar)
void delay(uint z)
{
uint x,y
for(x=zx>0x--)
for(y=70y>0y--)
}
void main()
{
init()
while(1)
{
if(rq==1)
{
if(rq==1)
display(sw,w,q,b,s,g)
}
else if(rq==2)
{
if(rq==2)
display(sw1,w1,q1,b1,s1,g1)
}
else if(rq==3)
{
if(rq==3)
display(w,w,w,w,w,w)
}
else if(rq==4)
{
uchar i
temp=0x01
for(i=0i<8i++)
{
P1=~temp
delay(100)
temp<<=1
}
temp=0x80
for(i=0i<8i++)
{
P1=~temp
delay(100)
temp>>=1
}
temp=0x01
for(i=0i<8i++)
{
P1=temp
delay(100)
temp<<=1
}
temp=0x7F
for(i=0i<8i++)
{
P1=temp
delay(100)
temp>>=1
}
}
else
rq=1
}
}
void init()
{
rq=1
x=1
nums=22
numf=0
numm=0
numn=9
numy=10
numr=15
TMOD=0x11
TH0=(65536-50000)/256
TL0=(65536-50000)%256
IT0=1
IT0=2
EA=1
EX0=1
EX1=1
ET0=1
TR0=1
ET1=1//IE=0x82 //CPU开中断,CT0开中断
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256
TL0=(65536-50000)%256
t0++
if(key==0)
{
delay(50)
if(key==0)
{
x++
while(key==0)
}
}
if(x==2&rq==1)
{
//P0=0xf3
if(key1==0)
{
numf++
while(key1==0)
}
}
else if(x==3&rq==1)
{
// P0=0xfc
if(key1==0)
{
nums++
while(key1==0)
}
}
else if(x==2&rq==2)
{
// P0=0xcf
if(key1==0)
{
numr++
while(key1==0)
}
}
else if(x==3&rq==2)
{
// P0=0xf3
if(key1==0)
{
numy++
while(key1==0)
}
}
else if(x==4&rq==2)
{
// P0=0xfc
if(key1==0)
{
numn++
while(key1==0)
}
}
else
{
x=1
}
if(t0==20)
{
t0=0
numm++
}
if(numm==60)
{
numm=0
numf++
}
if(numf==60)
{
for(u=500u>0u--)
{
bell=0
delay(1)
bell=1
delay(1)
}
numf=0
nums++
}
if(nums==24)
{
nums=0
numr++
}
if(numr==30)
{
numr=0
numy++
}
if(numy==12)
{
numy=0
numn++
}
if(numn==100)
{
numn=0
}
g=numm%10
s=numm/10
b=numf%10
q=numf/10
w=nums%10
sw=nums/10
g1=numr%10
s1=numr/10
b1=numy%10
q1=numy/10
w1=numn%10
sw1=numn/10
}
void exert0() interrupt 0
{
delay(50)
rq++
while(ch==0)
}
void t0int() interrupt 3
{
TR1=0
bell=!bell
TH1=timer0h
TL1=timer0l
TR1=1
}
void exert1() interrupt 2
{
rq=100
}
void display(uchar sw,uchar w,uchar q,uchar b,uchar s,uchar g)
{
P2=tabdu[sw]
P0=tabwe[0]
delay(5)
P0=0xff
P2=tabdu[w]
P0=tabwe[1]
delay(5)
P0=0xff
P2=tabdu[q]
P0=tabwe[2]
delay(5)
P0=0xff
P2=tabdu[b]
P0=tabwe[3]
delay(5)
P0=0xff
P2=tabdu[s]
P0=tabwe[4]
delay(5)
P0=0xff
P2=tabdu[g]
P0=tabwe[5]
delay(5)
P0=0xff
}
下面这个是电路图,图我没有画啊,不过我用仿真去做,应该跟电路图差不多了,你可以参考下,可以实现流水灯,闹铃,日期,时间,等功能,上面给你的是按照你的要求,另外我懒得改了所以多了个功能就是可以看日期,你看上面的程序,第一个按钮ch,按一下查看日期,再按一下查看温度(被删了,随机现在是随机显示一个数字),再按一下是流水灯,再按一下又回到时间,另外两个键key/key1;按key是选择锁定分还是时,如果你当前显示的是日期的话就是顺序锁定日,月,年,按key1调整,图上显示的是22点00分09秒,就这样了
设计方案的话..........呵呵,AT89S52+6个数码管+11.0592晶振+2个30P电容+3个按钮+1个10UF电容如图连接,你自己去写方案把,分数给那么少,就只帮你那么多了
KEYVAL EQU 30H
KEYTM EQU 31H
KEYSCAN EQU 32H
DAT EQU 33H
SCANLED EQU 39H
CLK EQU 77H
SEC EQU 78H
MIN EQU 79H
HOUR EQU 7AH
PAUSE BIT 00H
DOT BIT 01H
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0ISR 50ms定时
ORG 001BH
LJMP T1ISR 扫描显示
ORG 0030H
MAIN:
MOV SP,#5FH
MOV TMOD,#11H
MOV TH0,#03CH
MOV TL0,#0B0H
MOV TH1,#0ECH
MOV TL1,#078H
MOV KEYVAL,#0
MOV SCANLED,#0
MOV 33H,#10H
MOV 34H,#10H
MOV 35H,#10H
MOV 36H,#10H
MOV 37H,#10H
MOV 38H,#10H
MOV SEC,#0
MOV MIN,#0
MOV HOUR,#0
MOV CLK,#0
CLR PAUSE
SETB EA
SETB ET1
SETB TR1
LOOP:
LCALL KEYSEL
MOV A,KEYVAL
CJNE A,#0FFH,LOOP1
SJMP LOOP
LOOP1:
CJNE A,#10,LOOP2 “ON”启动
SETB TR0
SETB ET0
SETB PAUSE
SJMP LOOP
LOOP2:
CJNE A,#11,LOOP3 “=”清零
MOV SEC,#0
MOV MIN,#0
MOV HOUR,#0
LCALL DISCHG
SJMP LOOP
LOOP3:
CJNE A,#15,LOOP4 “+”暂停
CLR TR0
CLR ET0
CLR PAUSE
SJMP LOOP
LOOP4:
CJNE A,#14,LOOP5 “-”清显示暂停
MOV 33H,#10H
MOV 34H,#10H
MOV 35H,#10H
MOV 36H,#10H
MOV 37H,#10H
MOV 38H,#10H
CLR TR0
CLR ET0
CLR PAUSE
SJMP LOOP
LOOP5:
CJNE A,#10,LOOP6 数字键
LOOP6:
JC LOOP7
LJMP LOOP
LOOP7:
JNB PAUSE,LOOP8 暂停状态可以输入数字键
LJMP LOOP
LOOP8:
MOV 33H,34H
MOV 34H,35H
MOV 35H,36H
MOV 36H,37H
MOV 37H,38H
MOV 38H,KEYVAL
MOV A,33H
SWAP A
ORL A,34H
LCALL BCDH
MOV HOUR,A
MOV A,35H
SWAP A
ORL A,36H
LCALL BCDH
MOV MIN,A
MOV A,37H
SWAP A
ORL A,38H
LCALL BCDH
MOV SEC,A
LJMP LOOP
------------------
BCD转换为十六进制
BCDH:
MOV B,#10H
DIV AB
MOV R7,B
MOV B,#10
MUL AB
ADD A,R7
RET
------------------
十六进制转换为BCD
HBCD:
MOV B,#10
DIV AB
SWAP A
ORL A,B
RET
------------------
KEYSEL:
MOV KEYVAL,#0
MOV KEYSCAN,#0EFH
LCALL GETKEY
MOV A,KEYTM
JZ KEYS1
MOV KEYVAL,A
SJMP KEYRTN
KEYS1:
MOV KEYSCAN,#0DFH
LCALL GETKEY
MOV A,KEYTM
JZ KEYS2
CLR C
ADD A,#4
MOV KEYVAL,A
SJMP KEYRTN
KEYS2:
MOV KEYSCAN,#0BFH
LCALL GETKEY
MOV A,KEYTM
JZ KEYS3
CLR C
ADD A,#8
MOV KEYVAL,A
SJMP KEYRTN
KEYS3:
MOV KEYSCAN,#7FH
LCALL GETKEY
MOV A,KEYTM
JZ KEYRTN
CLR C
ADD A,#12
MOV KEYVAL,A
KEYRTN:
LCALL CHGKEY
RET
--------------------
GETKEY:
MOV KEYTM,#0
MOV A,KEYSCAN
MOV P3,A
NOP
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ NOKEY
MOV R2,#10
LCALL DELAY
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ NOKEY
MOV A,P3
ANL A,#0FH
MOV R7,A
SF:
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JNZ SF
MOV A,R7
CJNE A,#0EH,NK1
MOV KEYTM,#1
SJMP NOKEY
NK1:
CJNE A,#0DH,NK2
MOV KEYTM,#2
SJMP NOKEY
NK2:
CJNE A,#0BH,NK3
MOV KEYTM,#3
SJMP NOKEY
NK3:
CJNE A,#07H,NOKEY
MOV KEYTM,#4
NOKEY: RET
--------------------
DELAY:
MOV R3,#50
DELAY1:
MOV R4,#100
DJNZ R4,$
DJNZ R3,DELAY1
DJNZ R2,DELAY
RET
--------------------
T0ISR:
PUSH ACC
CLR TR0
MOV TH0,#3CH
MOV TL0,#0B0H
SETB TR0
INC CLK
MOV A,CLK
CJNE A,#20,T0ISRE
MOV CLK,#0
INC SEC
MOV A,SEC
CJNE A,#60,T0ISRE
MOV SEC,#0
INC MIN
MOV A,MIN
CJNE A,#60,T0ISRE
MOV MIN,#0
INC HOUR
MOV A,HOUR
CJNE A,#24,T0ISRE
MOV SEC,#0
MOV MIN,#0
MOV HOUR,#0
T0ISRE:
LCALL DISCHG
POP ACC
RETI
--------------------
DISCHG:
MOV A,HOUR
LCALL HBCD
PUSH ACC
ANL A,#0FH
MOV 34H,A
POP ACC
ANL A,#0F0H
SWAP A
MOV 33H,A
MOV A,MIN
LCALL HBCD
PUSH ACC
ANL A,#0FH
MOV 36H,A
POP ACC
ANL A,#0F0H
SWAP A
MOV 35H,A
MOV A,SEC
LCALL HBCD
PUSH ACC
ANL A,#0FH
MOV 38H,A
POP ACC
ANL A,#0F0H
SWAP A
MOV 37H,A
RET
--------------------
T1ISR:
PUSH ACC
CLR TR1
MOV TH1,#0ECH
MOV TL1,#78H
SETB TR1
MOV DPTR,#LEDTAB
T100:
MOV R0,#DAT
MOV A,SCANLED
ADD A,R0
MOV R0,A
MOV A,SCANLED
JNZ T101
MOV P2,#01H
CLR DOT
SJMP T1DIS
T101:
DEC A
JNZ T102
MOV P2,#02H
SETB DOT
SJMP T1DIS
T102:
DEC A
JNZ T103
MOV P2,#04H
CLR DOT
SJMP T1DIS
T103:
DEC A
JNZ T104
MOV P2,#08H
SETB DOT
SJMP T1DIS
T104:
DEC A
JNZ T105
MOV P2,#10H
CLR DOT
SJMP T1DIS
T105:
MOV P2,#20H
CLR DOT
T1DIS:
MOV A,@R0
MOVC A,@A+DPTR
JNB DOT,T1DIS1
ORL A,#01H
T1DIS1:
CPL A
MOV P0,A
INC SCANLED
MOV A,SCANLED
CJNE A,#6,T1END
MOV SCANLED,#0
T1END:
POP ACC
RETI
--------------------
CHGKEY:
MOV A,KEYVAL
JZ KV16
DEC A
JNZ KV01
MOV KEYVAL,#7
RET
KV01:
DEC A
JNZ KV02
MOV KEYVAL,#4
RET
KV02:
DEC A
JNZ KV03
MOV KEYVAL,#1
RET
KV03:
DEC A
JNZ KV04
MOV KEYVAL,#10
RET
KV04:
DEC A
JNZ KV05
MOV KEYVAL,#8
RET
KV05:
DEC A
JNZ KV06
MOV KEYVAL,#5
RET
KV06:
DEC A
JNZ KV07
MOV KEYVAL,#2
RET
KV07:
DEC A
JNZ KV08
MOV KEYVAL,#0
RET
KV08:
DEC A
JNZ KV09
MOV KEYVAL,#9
RET
KV09:
DEC A
JNZ KV10
MOV KEYVAL,#6
RET
KV10:
DEC A
JNZ KV11
MOV KEYVAL,#3
RET
KV11:
DEC A
JNZ KV12
MOV KEYVAL,#11
RET
KV12:
DEC A
JNZ KV13
MOV KEYVAL,#12
RET
KV13:
DEC A
JNZ KV14
MOV KEYVAL,#13
RET
KV14:
DEC A
JNZ KV15
MOV KEYVAL,#14
RET
KV15:
DEC A
JNZ KV16
MOV KEYVAL,#15
RET
KV16:
MOV KEYVAL,#0FFH
RET
--------------------
LEDTAB: DB 0FCH "0" 00H
DB 60H "1" 01H
DB 0DAH "2" 02H
DB 0F2H "3" 03H
DB 66H "4" 04H
DB 0B6H "5" 05H
DB 0BEH "6" 06H
DB 0E0H "7" 07H
DB 0FEH "8" 08H
DB 0F6H "9" 09H
DB 0EEH "A" 0AH
DB 3EH "B" 0BH
DB 9CH "C" 0CH
DB 7AH "D" 0DH
DB 9EH "E" 0EH
DB 8EH "F" 0FH
DB 00H " " 10H
--------------------
END
20h.1半点标示位
20H.2闹钟设置中........标示,为了显示区别用
20H.3闹钟设置时间CHECK到,使能标志位
20H.5开/关闹钟设置中........标示
20H.6闹钟1开关标志位
20H.7闹钟2开关标志位
psw.5用来做显示开关标志位
21,22,23,24这里设置第一个闹钟的时间
25,26,27,28这里设置第二个闹钟的时间
29H
P0口输出数码管段码,
P2口 输出位选信号
70H存放P1.0--3按钮值,
71H--78H存放当前系统定时时间
78H 77H 76H 75H 74H 73H 72H 71H
星期* 小时 分钟 秒钟
ts equ 24h 这里设置`24小时周期制
trrequ #0bbh 这个是温度,晶振等的时间补偿值,
org 0000h 定时太慢此值调大,定时太快调小
jmp main
org 0bh 定时器0中断入口矢量
jmp bz
org 1bh 定时器1中断入口矢量
jmp t1int
org 0100h 主程序
主程序
main:clr p3.0 关继电器
mov sp,#30h
mov r3,#20
mov tmod,#10h
mov tl0,#06h 定时器1,方式1,定时 50 MS
mov th0,#06h
mov tl1,#0b0h
mov th1,#3ch
mov ie,#88h 开定时器1中断
mov 65h,#5
mov 66h,#100
mov 64h,#4
clr psw.5
clr p3.0
setb pt1 设置T1为高优先级中断
setb tr1
clr tr1开启T1中断
acall send 71h--78h 清零
acall send1 20h--29h 清零
dd: acall daa进行十进制调整71H-79H
acall compare第一闹钟
acall compare1 第二闹钟 设置值
acall sound
acall disp 数码管显示,78H--71H分别对应着8个数码管显示
acall key_scanf 按钮控制
acall time_adj 时间调整
acall lasttime 调用上一次的设置值为当前定时值
acall alarm1_set 设置定时开/关闹钟
ajmp dd
调用上次值为设置时间
lasttime:push acc
mov a,70h
jnb acc.2,return1
clr p3.0 紧急暂停按钮,按下后暂停,并把上次设定值恢复.
clr tr1
mov 73h,21h
mov 74h,22h
wait7:acall disp
acall key_scanf
mov a,70h
jnb acc.0,wait7
mov 71h,#0
mov 72h,#0
mov 79h,#0
mov tl1,trr
mov th1,#3ch
mov r3,#20
setb tr1
setb p3.0
return1:pop acc
ret
daa: push acc 对当前系统时间进行十进制调整
mov 71h,79h
mov r1,#71h
cjne @r1,#10,s2
mov 71h,#0h
mov 79h,#0
inc 72h
mov r1,#72h
cjne @r1,#6,s2
mov 72h,#0h
dec 73h
mov r1,#73h
cjne @r1,#255,s2
dec 74h
mov 73h,#9
s1: pop acc
ret
s2: mov r1,#73h
cjne @r1,#0,s1
mov r1,#74h
cjne @r1,#0,s1
clr p3.0
clr tr1
sjmp s1
h_half: 半点CHECK
mov r1,#73h
mov a,74h
swap a
xchd a,@r1
cjne a,#29h,o25 CHECK 当前时间是否为29分钟
xchd a,@r1
mov r1,#71h
mov a,72h
swap a
xchd a,@r1
cjne a,#59h,o25 CHECK 当前时间为59秒?
setb tr0启动T0
setb 20h.1 enable 半点flag bit
o25: xchd a,@r1
ret
compare: 闹钟1设置时间与当前时间比较
push acc
jnb 20h.6,nequ 闹钟1开/关标志位
mov a,73h
cjne a,21h,nequ 分低位
mov a,74h
cjne a,22h,nequ 分高位
mov a,75h
cjne a,23h,nequ 小时低位
mov a,76h
cjne a,24h,nequ 小时高位
setb 20h.3 到闹钟设置时间,使能闹钟报警标志位
nequ:pop acc
ret
compare1: 闹钟2设置时间与当前时间比较
push acc
jnb 20h.7,nequ33 闹钟2开/关标志位
mov a,73h
cjne a,25h,nequ33
mov a,74h
cjne a,26h,nequ33
mov a,75h
cjne a,27h,nequ33
mov a,76h
cjne a,28h,nequ33
setb 20h.3 到闹钟设置时间,使能闹钟报警标志位
nequ33:
pop acc
ret
sound:
acall h_half check 是否半点?
jb 20h.1,s23 半点则返回
jb 20h.0,s23
mov r1,#73h
mov a,74h
swap a
xchd a,@r1
cjne a,#59h,s25
xchd a,@r1
mov r1,#71h
mov a,72h
swap a
xchd a,@r1
s20: cjne a,#56h,s21
ajmp s26
s21: cjne a,#58h,s22
ajmp s26
s22: cjne a,#59h,s25
setb tr0
ajmp s26
s25: xchd a,@r1
s23: ret
s26: jb 20h.0,s25
setb tr0
xchd a,@r1
ret
T0中断服务程序,报时铃音信号输出
bz: djnz 64h,rrr
jb 20h.3,alarmsign闹钟到点报时有效
jb 20h.1,next 半点报时
mov 64h,#40.5KHZ
ajmp justh
alarmsign:
mov 64h,#1 2KHZ信号
justh:
djnz 66h,ccc
mov 66h,#100
djnz 65h,ccc产生1000次中断后关中断
mov 65h,#5 响0.5秒
setb 20h.0
clr tr0
reti
next:mov 64h,#2 1KHZ信号,半点报时音
ccc: jb 20h.3,cc
cpl p1.4 半点报时输出声音信号
rrr: reti
cc: cpl p1.4 闹钟报时输出声音信号
reti
T1中断服务程序,定时器主时钟
t1int:
clr ea
mov tl1,trr
mov th1,#3ch
djnz r3,sd 20*50MS=1S
mov r3,#20
cpl p1.4
inc 79h
clr 20h.0
clr 20h.1 半点报时标志清零
jb 20h.3,sdd 闹钟CHECK有效与否?
clr tr0关T0
sd: setb ea
reti
sdd: setb tr0 开T0,即开闹铃声音
setb ea
reti
显示子函数
dispnum1: 显示
ajmp disp_num
disp:
push acc
jb 20h.5,dispnum1开/关闹钟设置中界面...........
jb 20h.2,alarmcheck闹钟设置时间中界面..........
jb psw.5,closedisp
mov r2,#01h位选通信号输出到P2口
mov r5,#2 显示的位数循环控制
mov r0,#73h分别取出内存76H-71H
cjne r3,#10,dot1在小时和分之间闪烁DOT point
dot1:jnc dsp1
orl 73h,#10h
dot1:cjne r3,#11,dsp1
anl 73h,#0efh
dsp1:mov a,r2
cpl a
mov p2,a
mov a,@r0
dsp2:mov dptr,#bcd
movc a,@a+dptr
mov p0,a
acall delay
mov a,r2
rl a
mov r2,a
inc r0
djnz r5,dsp1
anl 73h,#0efh
pop acc
ret
closedisp: 关显示
acall delay
mov p0,#0ffh
mov p2,#0
pop acc
ret
闹钟的定时设置显示
alarmcheck:
mov r2,#01h
mov r5,#2 两位显示22-21H对应定时设置值
mov r0,#21h
dsp21:
mov a,r2
cpl a
mov p2,a
mov a,@r0
mov dptr,#bcd
movc a,@a+dptr
mov p0,a
acall delay
mov a,r2
rl a
mov r2,a
inc r0
djnz r5,dsp21
pop acc
ret
bcd:共阳接法数码管段码表
db 0c0h,0f9h,0a4h,0b0h
db 99h,92h,82h,0f8h
db 80h,90h,88h,83h
db 0c6h,0a1h,86h,8eh不带小数点七段
db 40h,79h,24h,30h,19h
db 12h,02h,78h,00h,10h
db 0ffh,0bfh,7fh,3fh带小数点七段
delay:mov r6,#4h
tm: mov r4,#0h
ee: djnz r4,ee 延时2048US=2MS
djnz r6,tm
ret
send:mov r7,#9 初始化设置
mov r0,#71h
mov a,#0h
ss: mov @r0,a
inc r0
djnz r7,ss
mov 78h,#1h
mov 77h,#01ah
mov 71h,#1
mov 72h,#2
mov 73h,#3
mov 74h,#4
ret
send1:初始化
mov r7,#10
mov r0,#20h
mov a,#0
ss1: mov @r0,a
inc r0
djnz r7,ss1
ret
开/关闹钟界面显示
disp_num:
mov p2,#0f7h
mov a,29h当前要 *** 作的闹钟号码
mov dptr,#bcd
movc a,@a+dptr
mov p0,a
acall delay
pop acc
ret
key_scanf: 按钮处理
push acc
mov 70h,#0
orl p1,#0fh
mov a,p1
cpl a
anl a,#07h
jz nokey1
acall daa
acall disp
mov a,p1
cpl a
anl a,#07h
jz nokey1
mov 70h,a
key_wait: 等按钮放下
acall daa
acall disp
mov a,p1
cpl a
anl a,#07h
jnz key_wait
mov a,70h
jnb acc.1,nokey1
cpl psw.5
nokey1: 无按钮
pop acc
ret
a_on_off:
jnb 29h.0,iii
cpl 20h.6
iii: jnb 29h.1,out_2
cpl 20h.7
out_2:
ajmp alarmnum
alarmnum:
setb 20h.5
acall daa
acall disp
acall key_scanf
clr 20h.5
mov a,70h
jb acc.0,a_on_off
jb acc.1,alar_adj_1
jb acc.2,a_num_inc
acall numb
ajmp alarmnum
alarm1_set:
push acc
mov a,70h
jb acc.1,alarmnum
alarm1_out:
clr 20h.2
pop acc
ret
a_num_inc:
inc 29h
mov a,29h
anl a,#0fh
cjne a,#3,alarmnum
anl 29h,#0
ajmp alarmnum
alar_adj_1:
setb 20h.2
acall daa
orl 21h,#10h
acall disp
anl 21h,#0fh
acall key_scanf
mov a,70h
jb acc.1,hadj_1
jb acc.2,minc_1
ajmp alar_adj_1
madj_2:
acall daa
orl 25h,#10h
acall disp
anl 25h,#0fh
acall key_scanf
mov a,70h
jb acc.1,hadj_2
jb acc.2,minc_2
ajmp madj_2
hadj_1:
acall daa
orl 23h,#10h
acall disp
anl 23h,#0fh
acall key_scanf
mov a,70h
jb acc.1,madj_2
jb acc.2,hinc_1
ajmp hadj_1
hadj_2:acall daa
orl 27h,#10h
acall disp
anl 27h,#0fh
acall key_scanf
mov a,70h
jb acc.1,alarm1_out
jb acc.2,hinc_2
ajmp hadj_2
minc_1:
inc 21h
mov r1,#21h
cjne @r1,#10,alar_adj_1
mov 21h,#0
inc 22h
mov r1,#22h
cjne @r1,#6,alar_adj_1
mov 22h,#0h
ajmp alar_adj_1
minc_2:
inc 25h
mov r1,#25h
cjne @r1,#10,madj_2
mov 25h,#0
inc 26h
mov r1,#26h
cjne @r1,#6,madj_2
mov 26h,#0
ajmp madj_2
hinc_1:
inc 23h
mov r1,#23h
cjne @r1,#10,ss14
mov 23h,#0
inc 24h
ss14:
mov a,24h
swap a
xchd a,@r1
cjne a,#ts,ss15
mov 23h,#0
mov 24h,#0
ajmp hadj_1
ss15:xchd a,@r1
ajmp hadj_1
hinc_2:
inc 27h
mov r1,#27h
cjne @r1,#10,sss14
mov 27h,#0
inc 28h
sss14:
mov a,28h
swap a
xchd a, @r1
cjne a,#ts,sss15
mov 27h,#0
mov 28h,#0
ajmp hadj_2
sss15:
xchd a,@r1
ajmp hadj_2
时间调整程序
time_adj:
clr psw.5
push acc
mov a,70h
jb acc.0,l1P1.0调时功能键,每按一次切换一位
ajmp nokeyout
adj_out:
mov 21h,73h
mov 22h,74h
setb p3.0 闭合继电器
setb tr1
nokeyout:
pop acc
ret
QQ: anl 73h,#0fh
anl 74h,#0fh
anl 78h,#0fh
ret
l1: clr tr1acall dab 分钟调整
orl 73h,#10h点亮分右下角的小数点,当前调整位置
acall disp
acall QQ
acall key_scanf
clr psw.5
mov a,70h
jb acc.0,h_adj切换到小时调整
jb acc.1,m_incP1.2加1按钮
ajmp l1
h_adj: 小时调整
acall dab
orl 74h,#10h
acall disp
acall QQ
acall key_scanf
clr psw.5
mov a,70h
jb acc.0,out_adj切换到星期调整
jb acc.1,h_inc小时加1
ajmp h_adj
w_adj:
acall daa
orl 78h,#10h
acall disp
acall QQ
acall key_scanf
clr psw.5
mov a,70h
jb acc.0,out_adj
jb acc.2,w_inc
ajmp w_adj
out_adj:
ajmp adj_out
m_inc:调整分时,对定时复位,初始化
clr tr1
mov 71h,#0
mov 72h,#0
mov 79h,#0
mov tl1,trr
mov th1,#3ch
mov r3,#20
inc 73h
mov r1,#73h
cjne @r1,#10,s12
mov 73h,#0
inc 74h
mov r1,#74h
cjne @r1,#10,s12
mov 74h,#0
s12: ajmp l1
调整小时位
h_inc:
inc 74h
mov r1,#74h
cjne @r1,#10,s14
mov 74h,#0
inc 76h
s14: ajmp h_adj
mov a,76h
swap a
xchd a,@r1
cjne a,#ts,s1512进制,24进制设置值决定
mov 75h,#0
mov 76h,#0
ajmp h_adj
s15: xchd a,@r1
ajmp h_adj
调整星期位
w_inc:
inc 78h
mov r1,#78h
cjne @r1,#8,s16
mov 78h,#1h
s16: ajmp w_adj
当前闹钟开/关情况报告位
numb:clr 29h.4
jnb 29h.0,iii1
jnb 20h.6,iii1
setb 29h.4
iii1:jnb 29h.1,out_21
jnb 20h.7,out_21
setb 29h.4
out_21:
jnb 20h.6,out_12
jnb 20h.7,out_13
mov 77h,#1dh
ajmp out_22
out_12:
jnb 20h.7,out_14
mov 77h,#1bh
ajmp out_22
out_13:
mov 77h,#1ch
ajmp out_22
out_14:
mov 77h,#1ah
out_22:
ret
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)