此帖出自嵌入式系统论坛
最新回复
https://item.taobao.com/item.htm ... 0175&_u=u2khuh52c6b
淘宝STC89C52单片机8位数码显示1HZ-1MH数字频率计
晶振24MHZ,P10脚有输出1MHZ信号, P3.4脚输入测试频率,三挡闸门,分别0.1秒,1秒,10秒,用S4键选定,
#include
#define uchar unsigned char
unsigned long num,j,k,x,y,z,f,g,v,s,b,p;
uchar a0,b0,c0,d0,e0,f0,g0,h0;
sbit dula=P2^6;
sbit wela=P2^7;
sbit s2=P1^4;
sbit s3=P1^1;
sbit s4=P3^2;
sfr T2MOD=0xc9;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
void delay(uchar i)
{
for(j=i;j>0;j--)
for(k=8;k>0;k--);
}
void dela(uchar z)
{
for(x=z;x>0;x--)
for(y=200;y>0;y--);
}
void ela()
{
TR0=0;
TR1=0;
(s3=~s3);
num=(TH0*256+TL0)+(65536*g);
TH0=0;
TL0=0;
f=0;
g=0;
TR0=1;
TR1=1;
TH1=v;
TL1=s;
}
void display(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f,uchar g,uchar h)
{
dula=0;
P0=table[a];
dula=1;
dula=0;
wela=0;
P0=0xfe;
wela=1;
wela=0;
delay(1);
P0=table;
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
delay(1);
P0=table[c];
dula=1;
dula=0;
P0=0xfb;
wela=1;
wela=0;
delay(1);
P0=table[d];
dula=1;
dula=0;
P0=0xf7;
wela=1;
wela=0;
delay(1);
P0=table[e];
dula=1;
dula=0;
P0=0xef;
wela=1;
wela=0;
delay(1);
P0=table[f];
dula=1;
dula=0;
P0=0xdf;
wela=1;
wela=0;
delay(1);
P0=table[g];
dula=1;
dula=0;
P0=0xbf;
wela=1;
wela=0;
delay(2);
P0=table[h];
dula=1;
dula=0;
P0=0x7f;
wela=1;
wela=0;
delay(1);
}
void timer0() interrupt 0
{
EX0=0;
dela(1000);
p++;
if(p==1)
{ b=25;
v=152;
s=247; }
if(p==2)
{b=245;
v=222;
s=22;
}
if(p>=3)
{b=2442;
v=154;
s=22;
p=0;}
EX0=1;
}
void timer1() interrupt 1
{
g++;
}
void timer3() interrupt 3
{
f++;
if (f>=b)
ela();
}
void timer5() interrupt 5
{
delay(100);
}
void main()
{
TMOD=0x05;
//模式设置,00000001,可见采用的是定时器0,工作与模式1(M1=0,M0=1)。
TR0=1;
TR1=1; //打开计数器
TH1=0;
TL1=0;
TH0=0;
TL0=0;
TH2=0;
TL2=0;
T2MOD=0xc9;
{
C_T2=0; //定时器模式
T2MOD=0x02; //T2OE=1,定时器2允许输出
RCAP2L=250; //赋T2的预置值0xfffa,输出频率1MHZ
RCAP2H=255;
TR2=1;
g=1;
b=245;
v=222;
s=22;
PT0=1;
PT1=0;
PX0=0;
EA = 1;
ET0 =1;
ET1=1;
ET2=0;
EX0=1;
//开定时器0中断
}
while(1)
{
if(num
详情
回复
发表于 2015-10-30 22:26
| ||
|
||
| |
|
|
| |
|
|
| |
|
|
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
| |
|
|
| |
|
|
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
此帖出自嵌入式系统论坛
| ||
|
||
EEWorld Datasheet 技术支持