//程序说明:这是6位数显频率计,外部方波接到单片机的P3.4(T0),通过数码管显示所测的频率 #include #include #define uchar unsigned char #define unit unsigned int #define ulong unsigned long //uchar code dispbit[]={... //程序说明:这是6位数显频率计,外部方波接到单片机的P3.4(T0),通过数码管显示所测的频率
#include
#include
#define uchar unsigned char
#define unit unsigned int
#define ulong unsigned long
//uchar code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; // 定义位选
uchar code dispbit[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; // 定义位选
uchar code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x89,0xbf};//定义段码
uchar dispbuf[8]={0,0,0,0,0,0,11,10}; //显示缓冲
uchar temp[8];
uchar dispcount;
uchar T0count;//T0计数
uchar timecount;//时间计数
bit flag;
ulong x;
void main(void)
{
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
while(1)
{
uchar i;
if(flag==1)
{
flag=0;
x=T0count*65536+TH0*256+TL0;
for(i=0;i<8;i++)
{
temp[i]=0;
}
i=0;
while(x/10)
{
temp[i]=x%10;
x=x/10;
i++;
}
temp[i]=x;
for(i=0;i<6;i++)
{
dispbuf[i]=temp[i];
}
timecount=0;
T0count=0;
TH0=0;
TL0=0;
TR0=1;
}
}
}
void t0(void) interrupt 1 using 1//T0工作在计数状态下,T0的Z大计数频率为250KHz
{
T0count++;
}
void t1(void) interrupt 3 using 2
{
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
timecount++;
if(timecount==250)
{
TR0=0;
timecount=0;
flag=1;
}
P0=dispcode[dispbuf[dispcount]];
P2=dispbit[dispcount];
dispcount++;
if(dispcount==8)
{
dispcount=0;
}
}
全部评论
多扫描几次,就不闪了,可以去我的博客上看看,估计会对你有用。
您可能感兴趣的社区主题
评论
选购仪器 上yiqi.com
仪器网络推广
品牌网上传播
长按识别二维码查看信息详情