我当时也是用这个办法的,总体差不多,不过工作方式有点不同,我的是 TMOD=0x15;//T0工作计数器状态,T1工作于定时器状态
下面是我的代码,在我单片机上面好的,我没有仿真过,单片机是AT89S52晶振:11.0593MHz~~~
#include
#include
unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7};
unsigned char code dispcode[]
={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned char dispbuf[8]={0,0,0,0,0,0};
unsigned char temp[4];
unsigned char dispcount;
unsigned char T0count;
unsigned char timecount;
bit flag; //标志位,初始值为1
unsigned long x;
void main(void)
{
unsigned char i;
//定时器初始化
TMOD=0x15;//T0工作计数器状态,T1工作于定时器状态
TH0=0;
TL0=0;
TH1=(65536-3650)/256; //定时为4ms
TL1=(65536-3650)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
while(1)
{
if(flag==1)
{
flag=0;
x=T0count*65536+TH0*256+TL0; //读取T0中的频率
for(i=0;i