本帖最后由 Listen丶51 于 2018-4-14 12:45 编辑
/*
/*******************
工作芯片:STC 15W101
********************
*/
#include <reg51.h>
#include<RegDefined.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;
sbit BEEP = P3^0;
//u8 Motor_on[]={0,5,10,15};
char timer;
/*
void delay(u16 num)
{
u16 x,y;
for(x=num; x>0; x--)
for(y=110; y>0; y--)
{
;
}
}
*/
void IO_Init(void)
{
P3M0 = 0x10;
P3M1 = 0x20;
PWM = 0;
r_led = 1;
g_led = 1;
b_led = 1;
}
void InitTimer0(void)
{
TMOD = 0x01;
//TL0 = 0x48; //200us定时
//TL0 = 0x0A4;
TH0 = 0x0FF; //5us定时
TL0 = 0x0FB;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main (void)
{
IO_Init();
InitTimer0();
while(1);
}
void timer_t0(void) interrupt 1//定时器0中断服务函数,入口 定时200us
{
//TL0 = 0x48; //200us定时
//TL0 = 0x0A4;
TH0 = 0x0FF; //5us定时
TL0 = 0x0FB;
timer++;
if(timer == 9)
timer = 1;
if(timer <= 5)
PWM = 0;
else
PWM = 1;
}
|