计数器89C51(C语言版)
计数器
1#include<absacc.h>
2#include<reg51.h>
3#define COM XBYTE[0xa001]
4#define DAT XBYTE[0xa000]
5void display();
6unsigned char disbuf[6],hour=0,min=0,sec=0;
7unsigned char code led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80} ;
8void int_to() interrupt 1
9{
10 TL0=60536%256;
11 TH0=60536/256;
12
13
14 if(++sec==100)
15 {
16 sec=0;
17 if(++min==60)
18 {
19 min=0;
20 if(++hour==60)
21 {
22 hour=0;
23 }
24 }
25 }
26 display();
27}
28void init8279()
29{
30 COM=0;
31 COM=0x32;
32 COM=0xdf;
33 while(COM&0x80);
34}
35void display()
36{
37unsigned char data dd,i,comm=0x80;
38disbuf[0]=hour/10;
39disbuf[1]=hour%10;
40disbuf[2]=min/10;
41disbuf[3]=min%10;
42disbuf[4]=sec/10;
43disbuf[5]=sec%10;
44for(i=0;i<6;i++)
45{
46COM=comm++;
47dd=disbuf[i];
48DAT=led[dd];
49}
50}
51void int_ex0() interrupt 0
52{
53TR0=~TR0;
54}
55void int_ex1() interrupt 2
56{
57int i;
58for(i=0;i<6;i++)
59disbuf[i]=0;
60}
61 void main()
62 {
63 TMOD=0x01;
64 TH0=60536/256;
65 TL0=60536%256;
66 TR0=1;
67 ET0=1;
68 EX0=1;
69 EX1=1;
70 EA=1;
71
72 init8279();
73 while(1);
74 {
75 display();
76 }
77}
78
2#include<reg51.h>
3#define COM XBYTE[0xa001]
4#define DAT XBYTE[0xa000]
5void display();
6unsigned char disbuf[6],hour=0,min=0,sec=0;
7unsigned char code led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80} ;
8void int_to() interrupt 1
9{
10 TL0=60536%256;
11 TH0=60536/256;
12
13
14 if(++sec==100)
15 {
16 sec=0;
17 if(++min==60)
18 {
19 min=0;
20 if(++hour==60)
21 {
22 hour=0;
23 }
24 }
25 }
26 display();
27}
28void init8279()
29{
30 COM=0;
31 COM=0x32;
32 COM=0xdf;
33 while(COM&0x80);
34}
35void display()
36{
37unsigned char data dd,i,comm=0x80;
38disbuf[0]=hour/10;
39disbuf[1]=hour%10;
40disbuf[2]=min/10;
41disbuf[3]=min%10;
42disbuf[4]=sec/10;
43disbuf[5]=sec%10;
44for(i=0;i<6;i++)
45{
46COM=comm++;
47dd=disbuf[i];
48DAT=led[dd];
49}
50}
51void int_ex0() interrupt 0
52{
53TR0=~TR0;
54}
55void int_ex1() interrupt 2
56{
57int i;
58for(i=0;i<6;i++)
59disbuf[i]=0;
60}
61 void main()
62 {
63 TMOD=0x01;
64 TH0=60536/256;
65 TL0=60536%256;
66 TR0=1;
67 ET0=1;
68 EX0=1;
69 EX1=1;
70 EA=1;
71
72 init8279();
73 while(1);
74 {
75 display();
76 }
77}
78
版权声明:本文为jhlishero原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。