电路仿真 0~999的计数器
- 提问者网友:雾里闻花香
- 2021-04-11 17:01
- 五星知识达人网友:大漠
- 2021-04-11 17:14
#include "reg51.h"
int a;
bit aa,ab,ac;
sbit k1=P1^0;
sbit k2=P1^1;
sbit k3=P1^2;
sbit d1=P2^0;
sbit d2=P2^1;
sbit d3=P2^2;
sbit d4=P2^3;
char code tab[15]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x40,0x79,0x80};//0~9-E.
delay(int z)
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
display(int a)
{
char a1,a2,a3;
a3=a/100;
a2=a%100/10;
a1=a%10;
if(a3!=0)
d2=0;
P0=tab[a3];
delay(10);
d2=1;
if(a2!=0)
d3=0;
P0=tab[a2];
delay(10);
d3=1;
d4=0;
P0=tab[a1];
delay(10);
d4=1;
}
void main()
{
a=0;
aa=1;
ab=1;
ac=1;
while(1)
{
if(k1==0&&aa!=0)
{
a=a+1;
aa=0;
}
if(k1==1)
aa=1;
if(k2==0&&ab!=0)
{
a=a+2;
ab=0;
}
if(k2==1)
ab=1;
if(k3==0&&ac!=0)
{
a=a+3;
ac=0;
}
if(k3==1)
ac=1;
display(a);
if(a==1000)
a=0;
}
} //看不懂请Q我