【044】秒表-八位数码管显示2007-05-05 16:31:00
【评论】
【打印】
【字体:大 中 小】
本文链接:http://blog.pfan.cn/wentao/25598.html
dot_l equ 30h
dot_h equ 31h
sec_l equ 32h
sec_h equ 33h
min_l equ 34h
min_h equ 35h
hou_l equ 36h
hou_h equ 37h
dot equ 38h
sec equ 39h
min equ 40h
hou equ 41h
dis_b equ 42h
dis_r equ 43h
key_t equ 44h
K bit p1.4
org 0000h
ajmp start
org 000bh
ajmp time0
org 001bh
ajmp time1
org 0030h
start:
mov p2,#0xff
mov p1,#0xff
mov dis_b,#0x7f
mov dis_r,#0
mov dot,#0
mov sec,#0
mov min,#0
mov hou,#0
mov key_t,#0
mov tmod,#00010001b
mov th0,#0xd8
mov tl0,#0xf0
mov th1,#0xfc
mov tl1,#0x18
setb ea
setb et0
setb et1
clr tr0
setb tr1
lop:
jb K,lop
lcall d_10ms
jb K,lop
jnb K,$
lcall key_to
ajmp lop
key_to:
inc key_t
mov a,key_t
cjne a,#1,key_2
setb tr0
ret
key_2: cjne a,#2,key_3
clr tr0
ret
key_3: cjne a,#3,back
mov dot,#0
mov sec,#0
mov min,#0
mov hou,#0
mov key_t,#0
back: ret
time0:
push psw
push acc
inc dot
mov a,dot
cjne a,#100,over
mov dot,#0
inc sec
mov a,sec
cjne a,#60,over
mov sec,#0
inc min
mov a,min
cjne a,#60,over
mov min,#0
inc hou
mov a,hou
cjne a,#100,over
mov hou,#0
over: mov th0,#0xd8
mov tl0,#0xf0
pop acc
pop psw
reti
time1:
push psw
push acc
push b
mov a,dot
mov b,#10
div ab
mov dot_l,b
mov dot_h,a
mov a,sec
mov b,#10
div ab
mov sec_l,b
mov sec_h,a
mov a,min
mov b,#10
div ab
mov min_l,b
mov min_h,a
mov a,hou
mov b,#10
div ab
mov hou_l,b
mov hou_h,a
mov dptr,#table
mov a,#dot_l
add a,dis_r
mov r0,a
mov a,@r0
movc a,@a+dptr
mov p2,dis_b
mov r0,dis_b
cjne r0,#0xdf,b3
ajmp add_dot
b3: cjne r0,#0xf7,b1
ajmp add_dot
b1: cjne r0,#0xfd,com
add_dot: anl a,#0x7f
com: mov p0,a
inc dis_r
anl dis_r,#0x07
mov a,dis_b
rr a
mov dis_b,a
mov th1,#0xfc
mov tl1,#0x18
pop b
pop acc
pop psw
reti
d_10ms: mov r5,#20
temp1: mov r6,#255
djnz r6,$
djnz r5,temp1
ret
table: db 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf
end
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
void delay_ms(uchar ms);
void key_scan();
void key_to();
uchar code dis_code[11] = {0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,0xbf};
uchar data dis[8];
uchar data dot = 0;
uchar data sec = 0;
uchar data min = 0;
uchar data hou = 0;
uchar data dis_b;
uchar data dis_r;
uchar data key_t = 0;
sbit K = P1^4;
void main()
{
P2 = 0xff;
P1 = 0xff;
dis[2] = 10;
dis[5] = 10;
dis_b = 0x7f;
dis_r = 0;
TMOD = 0x11;
TH0 = 0xd8;
TL0 = 0xf0;
TH1 = 0xfc;
TH1 = 0x18;
EA = 1;
ET0 = 1;
ET1 = 1;
TR0 = 0;
TR1 = 1;
while(1)
{
if(K != 1)
{
delay_ms(10);
if(K != 1)
{
while(K != 1);
key_to();
}
}
}
}
void key_to()
{
key_t++;
if(key_t == 1)
TR0 = 1;
else
{
if(key_t == 2)
TR0 = 0;
else
{
if(key_t == 3)
{
dot = 0;
sec = 0;
min = 0;
hou = 0;
key_t = 0;
}
}
}
}
void tiem0(void) interrupt 1
{
dot++;
if(dot == 100)
{
dot = 0;
sec++;
if(sec == 60)
{
sec = 0;
min++;
if(min == 60)
{
min = 0;
hou++;
if(hou == 100)
hou = 0;
}
}
}
TH0 = 0xd8;
TL0 = 0xf0;
}
void time1(void) interrupt 3
{
uchar data t = 0;
dis[0] = dot % 10;
dis[1] = dot / 10;
dis[2] = sec % 10;
dis[3] = sec / 10;
dis[4] = min % 10;
dis[5] = min / 10;
dis[6] = hou % 10;
dis[7] = hou / 10;
t = dis_code[dis[dis_r]];
if(dis_b == 0xdf | dis_b == 0xf7 | dis_b == 0xfd)
t &= 0x7f;
P2 = dis_b;
P0 = t;
dis_r++;
dis_r &= 0x07;
dis_b = _cror_(dis_b,1);
TH1 = 0xfc;
TL1 = 0x18;
}
void delay_ms(uchar ms)
{
uchar i;
while(ms--)
for(i = 0; i < 124; i++);
}
阅读(7615) | 评论(10)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论