#define MAIN_Fosc 2400000UL
#include "STC15FXXXX.H"
sbit led_1=P1^7;
sbit led_2=P1^6;
sbit led_3=P4^7;
sbit led_4=P4^6;
void init()
{
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
ET0=1;
EA=1;
}
void
timer (void) interrupt 1
{
static count=0;
unsigned int i=0;
count++;
if(count==20)
{
i++;
count=0;
}
if(i==4)
{
i=0;
}
switch (i)
{
case 0:{led_1=0;led_2=1;led_3=1;led_4=1;}break;
case 1:{led_1=1;led_2=0;led_3=1;led_4=1;}break;
case 2:{led_1=1;led_2=1;led_3=0;led_4=1;}break;
case 3:{led_1=1;led_2=1;led_3=1;led_4=0;}break;
default:{led_1=0;led_2=0;led_3=0;led_4=0;}break;
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
void main()
{
init();
while(1);
}
LED灯直接不亮 void timer (void) interrupt 1 这个是定时器0的中断程序
一周热门 更多>