#include<reg52.h>
sbit LED0 = P1^0;
sbit LED1 = P1^1;
sbit LED2 = P1^2;
sbit LED3 = P1^3;
unsigned char task_delay[4]={0};
void ( * code task[])() = {task0,task1,task2,task3}; !!!!!!!!这个地方怎么编译出错啊,不懂
void init()
{
unsigned char i;
for(i=0;i<4;i++)
task_delay[i]=0;
TMOD=0x01;
TH0=0xec;
TL0=0x78;
ET0=1;
TR0=1;
}
void run(void (*ptask)())
{
(*ptask)();
}
void
timer0(void) interrupt 1
{
unsigned char i;
TH0=0xec;
TL0=0x78;
for(i=0;i<4;i++)
{
if(task_delay[i]!=0)
task_delay[i]--;
}
}
void main()
{
unsigned char j;
init();
EA=1;
for(j=0;j<4;j++)
{
if(task_delay[j]==0)
run(task[j]);
break;
}
}
void task0()
{
LED0 = !LED0;
task_delay[0] =100;
}
void task1()
{
LED1 = !LED1;
task_delay[1] = 50;
}
void task2()
{
LED2 = !LED2;
task_delay[2] = 10;
}
void task3()
{
static unsigned char j=0;
switch(j)
{
case 0:LED3=!LED3;
task_delay[3]=5;
j=1;
break;
case 1:LED3=!LED3;
task_delay[3]=10;
j=2;
break;
case 2:LED3=!LED3;
task_delay[3]=20;
j=0;
default :j=0;
task_delay[3]=5;
break;
}
}
做出来就好,如果可以,欢迎你把解决方法贴上来,供大家学习学习。
一周热门 更多>