c#实现51单片机频率计的代码分享(数字频率计设计)
本文导语: 代码如下:#include #define uchar unsigned char#define uint unsigned int#define ulong unsigned long //按键sbit button=P1^7;//LEDsbit led2=P3^5;sbit led3=P3^7;//数码管位选sbit c0 = P3^0;sbit c1 = P3^1;sbit c2 = P3^2;sbit c3 = P3^3;//数码管段码uchar code dm[]={0xC0,0xF9,0xA4,0xB0,0x9...
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
//按键
sbit button=P1^7;
//LED
sbit led2=P3^5;
sbit led3=P3^7;
//数码管位选
sbit c0 = P3^0;
sbit c1 = P3^1;
sbit c2 = P3^2;
sbit c3 = P3^3;
//数码管段码
uchar code dm[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uchar wm[]={0,0,0,0};
ulong pl;
uchar mode;
void delay3ms(void) //误差 0us
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=176;b>0;b--)
for(a=7;a>0;a--);
}
void smg()
{
static uchar i=0;
c0=1;c1=1;c2=1;c3=1;
P1 = 0XFF;
switch(i)
{
case 0: c0=0;
break;
case 1: c1=0;
break;
case 2: c2=0;
break;
case 3: c3=0;
break;
}
P1 = dm[wm[i]];
i++;
if(i>3)
{
i=0;
}
}
void ledmode()
{
switch(mode)
{
case 0:led2=led3=0;
break;
case 1:led2=1;led3=0;
break;
case 2:led2=0;led3=1;
break;
case 3:led2=led3=1;
break;
}
}
void key()
{
static uchar num;
delay3ms();
button=1;
switch(num)
{
case 0: if(!button)
{
num=1;
}
break;
case 1: if(!button)
{
if(mode99)
{
time=0;
pl=TH0*256+TL0;
wm[0]=(pl/1000)%10;
wm[1]=(pl/100)%10;
wm[2]=(pl/10)%10;
wm[3]=pl%10;
TH0=TL0=0;
}
TR0=1;
}
您可能感兴趣的文章:
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。