用的是11.0592 晶振,定时10us,调不出25KHz,请指教.....
#include <reg51.h>
typedef unsigned int u16;
typedef unsigned char u8;
sbit PWM = P3^4;
sbit key = P3^5;
sbit r_led = P3^2;
sbit g_led = P3^1;
sbit b_led = P3^3;
//u8 Motor_on[]={0,5,10,15};
u8 timer;
/*
void delay(u16 num)
{
u16 x,y;
for(x=num; x>0; x--)
for(y=110; y>0; y--)
{
;
}
}
*/
void IO_Init(void)
{
PWM = 0;
r_led = 1;
g_led = 1;
b_led = 1;
}
void InitTimer0(void) //10us定时
{
TMOD = 0x01;
TH0 = 0x0FF;
TL0 = 0x0F7;
//TH0 = (65536-50000)/256;
//TL0 = (65536-50000)&256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main (void)
{
IO_Init();
InitTimer0();
while(1);
}
void timer_t0(void) interrupt 1//定时器0中断服务函数,入口
{
TR0 = 0;
TH0 = 0x0FF;
TL0 = 0x0F7;
//TH0 = (65536-50000)/256;
//TL0 = (65536-50000)&256;
TR0 = 1;
timer++;
if(timer == 100)
timer = 0;
if(timer <= 30)
PWM = 1;
else PWM = 0;
}