#include <reg52.h>
unsigned int i,j,k;
unsigned char T0RH=0;
unsigned char T0RL=0;
void Configtime0(unsigned int ms);
void main()
{
EA=1;
while(1)
{
P0=0x00;
//delay(1000);
Configtime0(1000);//定时1s
P0=0xFF;
Configtime0(1000);//定时1s
}
}
void Configtime0(unsigned int ms)
{
unsigned long tmp;
tmp=11059200/12;//计算定时器的计数频率
tmp=(tmp*ms)/1000;//计算定时器的计数个数
tmp=65536-tmp;//计算计数初值
T0RH=(unsigned char)(tmp>>8);
T0RL=(unsigned char)tmp;
TH0=T0RH;
TL0=T0RL;
TMOD&=0xF0;
TMOD|=0x01;
ET0=1;
TR0=1;
}
void Time0() interrupt 1
{
TH0=T0RH;
TL0=T0RL;
}
|