四位方波频率计

 #include<reg52.h>
#define uchar unsigned char
code uchar xianshi[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
sbit gw=P2^4;
sbit sw=P2^5;
sbit bw=P2^6;
sbit qw=P2^7;
uchar k,pl,m,pl0,k0,m0;
void delay(unsigned int tc)
{
unsigned int i;
for(i=0;i<125;i++)
{;}
tc--;
}
void LED()
{
 gw=0;
 P0=xianshi[pl0%10];
 delay(10);
 gw=1;
 sw=0;
 P0=xianshi[pl0/10];
 delay(8);
 sw=1;
 bw=0;
 P0=xianshi[k0];
 delay(6);
 bw=1;
 qw=0;
 P0=xianshi[m0];
 delay(4);
 qw=1;
}
void t0(void) interrupt 1 //定时中断服务函数
{
static unsigned int tcnt=0,sec=0;
tcnt++; //每过250ust tcnt 加一
if(tcnt==400) //计满400 次(1/10 秒)时
{
tcnt=0; //重新再计
sec++;
if(sec==10) //定时10 秒,在从零开始计时
{
sec=0;
pl0=pl;k0=k;m0=m;
pl=0;k=0;m=0;
}
}
}

void t1in(void) interrupt 3
{
pl++;
TH1=0xff;
TL1=0xff;
if(pl>99)
{
k++;
pl=0;
}
if(k>9)
{
m++;
k=0;
}
if(m>9)
{
m=0;
k=0;
pl=0;
}

}
void main(void)
{
EA=1;
IP=0x02;
TH0=TL0=0x1b;
TMOD=0x52;
IE=0x8A;
TH1=0xff;
TL1=0xff;
TR0=1;     
TR1=1;
while(1)

LED();
}
}               

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值