標題:
藍橋杯板子51單片機的頻率測量程序(測量555定時器脈沖)
[打印本頁]
作者:
1979759100Ls
時間:
2018-4-21 11:58
標題:
藍橋杯板子51單片機的頻率測量程序(測量555定時器脈沖)
測量555定時器脈沖。
用藍橋杯板子寫的程序,大家自行下載,看一下
單片機源程序如下:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sfr AUXR=0x8e;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};
void smg_xianshi(uchar yi,er,san,si,wu,liu,qi,ba);
uchar yi,er,san,si,wu,liu,qi,ba;
void delay(uint x);
void close ();
void Timer0Init(void);
void zd_t1();
void Timer1Init(void);
uint time,fre;
void main()
{
Timer1Init();
Timer0Init();
EA=1;
ET1=1;
while(1)
{
yi=11;er=11;san=11;
si=fre/10000;
wu=(fre%10000)/1000;
liu=(fre%1000)/100;
qi=(fre%100)/10;
ba=(fre%100)%10;
smg_xianshi(yi,er,san,si,wu,liu,qi,ba);
}
}
void zd_t1() interrupt 3
{
time++;
if(time==1000)
{
TR0=0;
time=0;
fre=TH0*256+TL0;
TH0=0;
TL0=0;
TR0=1;
}
}
void Timer1Init(void) //1毫秒@11.0592MHz
{
AUXR &= 0xBF; //定時器時鐘12T模式
TMOD &= 0x0F; //設置定時器為定時模式
TL1 = 0x66; //設置定時初值
TH1 = 0xFC; //設置定時初值
TF1 = 0; //清除TF1標志
TR1 = 1 ; //定時器1開始計時
}
void Timer0Init(void)
{
AUXR &= 0x7F; //定時器時鐘12T模式
TMOD |= 0x05; //設置定時器為計數(shù)模式
TL0 = 0x00; //設置定時初值
TH0 = 0x00; //設置定時初值
TF0 = 0; //清除TF0標志
TR0 = 1; //定時器0開始計時
}
void delay(uint x)
{
uchar i;
while(x--)
{
for(i=0;i<120;i++);
}
}
void close ()
{
P2=0x80;
P0=0xff;
P2=0x1f;
P2=0xa0;
P0=0x00;
P2=0x1f;
}
void smg_xianshi(uchar yi,er,san,si,wu,liu,qi,ba)
{
P2=0xc0;
P0=0x01;
P2=0xe0;
P0=tab[yi];
delay(5);
P2=0xc0;
P0=0x02;
P2=0xe0;
P0=tab[er];
delay(5);
P2=0xc0;
P0=0x04;
P2=0xe0;
P0=tab[san];
delay(5);
P2=0xc0;
P0=0x08;
P2=0xe0;
P0=tab[si];
delay(5);
P2=0xc0;
P0=0x10;
P2=0xe0;
P0=tab[wu];
delay(5);
P2=0xc0;
P0=0x20;
P2=0xe0;
P0=tab[liu];
delay(5);
P2=0xc0;
P0=0x40;
P2=0xe0;
P0=tab[qi];
delay(5);
P2=0xc0;
P0=0x80;
P2=0xe0;
P0=tab[ba];
delay(5);
}
復制代碼
所有資料51hei提供下載:
555.zip
(197 Bytes, 下載次數(shù): 45)
2018-4-21 11:58 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1