51单片机写好定时程序后键盘程序可以中断其他的,不能中断流水灯二进制加法的程序。是P0和P2口同时二进制 5
发一部分上来voidtimer0_init(){TMOD=0x001;TH0=0XFC;TL0=0X17;EA=1;ET0=1;TR0=1;}voidkey(){unsi...
发一部分上来
void timer0_init()
{TMOD=0x001;
TH0=0XFC;
TL0=0X17;
EA=1;
ET0=1;
TR0=1;
}
void key()
{ unsigned char ckey,lkey;
ckey=P1&0x07;
if(ckey!=0x07)
{ if(lkey==0x07)
{switch(ckey)
{
case 0x06:mode++;if(mode>10)mode=0;break;
}
}
}
lkey=ckey;
}
void flow1()
{unsigned char op,os,ob;
op=0x01;os=0x01;
for(ob=0;ob<1;ob=0)
{P0=op;P2=os;delay_ms(100);
op++;os++;
}
}
void flow1()
{unsigned char op,os,ob;
op=0x01;os=0x01;
for(ob=0;ob<1;ob=0)
{P0=op;P2=os;delay_ms(100);
op++;os++;
}
}
void flow()
{
if(mode==0)flow0();
else if(mode==1)flow1();
else if(mode==2)flow2();
else if(mode==3)flow3();
else if(mode==4)flow4();
else if(mode==5)flow5();
else if(mode==6)flow6();
else if(mode==7)flow7();
}
void main()
{
P0=P2=0;
timer0_init();
while(1)
{
flow();
}
}
void timer0_interrupt() interrupt 1
{ key();
} 展开
void timer0_init()
{TMOD=0x001;
TH0=0XFC;
TL0=0X17;
EA=1;
ET0=1;
TR0=1;
}
void key()
{ unsigned char ckey,lkey;
ckey=P1&0x07;
if(ckey!=0x07)
{ if(lkey==0x07)
{switch(ckey)
{
case 0x06:mode++;if(mode>10)mode=0;break;
}
}
}
lkey=ckey;
}
void flow1()
{unsigned char op,os,ob;
op=0x01;os=0x01;
for(ob=0;ob<1;ob=0)
{P0=op;P2=os;delay_ms(100);
op++;os++;
}
}
void flow1()
{unsigned char op,os,ob;
op=0x01;os=0x01;
for(ob=0;ob<1;ob=0)
{P0=op;P2=os;delay_ms(100);
op++;os++;
}
}
void flow()
{
if(mode==0)flow0();
else if(mode==1)flow1();
else if(mode==2)flow2();
else if(mode==3)flow3();
else if(mode==4)flow4();
else if(mode==5)flow5();
else if(mode==6)flow6();
else if(mode==7)flow7();
}
void main()
{
P0=P2=0;
timer0_init();
while(1)
{
flow();
}
}
void timer0_interrupt() interrupt 1
{ key();
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏5(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询