#include
#define uchar unsigned char
#define uint unsigned int
uint Time_Num_2ms,Time_Num_500ms;
sbit PWM1=P1^0;// 位定义2ms方波输出的端口
sbit PWM2=P1^1;// 位定义500ms方波输出的端口
void InitTimer0(void)
{
TMOD=0x01;//设定定时器0为工作方式1
TH0=(65536-1000)/256;//装初值,1ms初值
TH0=(65536-1000)%256;//装初值,1ms初值
EA=1;//开总中断
ET0=1;//开定时器0中断
TR0=1; //启动定时器0
}
void T0Timer() interrupt 1
{
TH0=(65536-1000)/256;//重装初值,1ms初值
TH0=(65536-1000)%256;//重装初值,1ms初值
Time_Num_2ms++;
Time_Num_500ms++;
}
void main(void)
{
P1=0xff;
InitTimer0();
while(1)
{
if(Time_Num_2ms==2)
{
Time_Num_2ms=0;
PWM1=~PWM1;
}
if(Time_Num_500ms==500)
{
Time_Num_500ms=0;
PWM2=~PWM2;
}
}
}