以下是电路,我要的功能很简单,按键第按一次,数码管后两位显示加1,到100后回头,看这样写能不能称作“任务调度”,如果是,那么这种方式比较好处理,因为程序执行的间隔时间都是固定的,但对于有些交互式外设,如AD,DA,LCD,必须从对方读取数据,时间间隔是离散的,应该怎样安排任务? 以上请教!
#include <reg51.h>
#define uchar unsigned char
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar shu=85,count;
bit flag;
sbit kb=P3^4;
void sumaguan()
{
static uchar i=0;
i++;
P0=0XFF;
P2=~(1<<(i-1));
if(i<3)
P0=0XC0;
else if(i==3)
P0=tab[shu/10];
else if(i==4)
{
P0=tab[shu%10];
i=0;
}
}
void anjianchuli()
{
static uchar zhuangtai=0;
switch(zhuangtai)
{
case 0:
{
if(kb==0)
zhuangtai++;
};break;
case 1:
{
if(kb==0)
zhuangtai++;
else
zhuangtai--;
};break;
case 2:
{
if(kb==0)
{
zhuangtai++;
shu++;
if(shu==100)
shu=0;
}
else
zhuangtai--;
};break;
case 3:
{
if(kb==1)
zhuangtai=0;
};break;
}
}
main()
{
TMOD = 0x01;
TH0 = 0x0E8;
TL0 = 0x90;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1)
{
if(flag==1)
{
flag=0;
sumaguan();
}
if(count>=3)
{
anjianchuli();
count=0;
}
}
}
void timer0() interrupt 1
{
flag=1;
count++;
TH0 = 0x0E8;
TL0 = 0x90;
}
|