设计一个节目彩灯控制器,在单片机的p0口接有8个发光二极管作为指示灯,p1.0~p1.3接有4个按键开关。
当不同的脚上的按键按下时,实现如下功能:按下p1.0脚得按键-8只灯全亮然后全灭,再全亮然后全灭,交替闪亮;按下p1.1脚的按键-按此键则停止点亮8个灯,所有灯全灭;按下...
当不同的脚上的按键按下时,实现如下功能:按下p1.0脚得按键-8只灯全亮然后全灭,再全亮然后全灭,交替闪亮;按下p1.1脚的按键-按此键则停止点亮8个灯,所有灯全灭;按下p1.2脚的按键-LED灯由上向下流动点亮;按下p1.3脚的按键-LED等由下向上流动点亮。求仿真模型和编程
展开
展开全部
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
uchar led=0xfe,led1=0x00;
void delay(uchar a)
{
uchar i;
while(a--)for(i=0;i<120;i++);
}
main()
uchar keyval=0;
{
while(1)
{
if(key1==0);
{
while(key1==0);
keyval=1;
}
if(key2=0);
{
while(key2==0);
keyval=2;
}
if(key3==0);
{
while(key3==0);
keyval=3;
}
if(key4==0);
{
while(key4==0);
keyval=4;
}
switch(keyval)
{
case 1:
P0=led1;
led1=~led1;
delay(100);
break;
case 2:
P0=0xff;
break;
case 3:
P0=led;
led=_crol_(led,1);
delay(100);
break;
case 4:
P0=led;
led=_cror_(led,1);
delay(100);
break;
}
}
}
#include<intrins.h>
#define uchar unsigned char
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
uchar led=0xfe,led1=0x00;
void delay(uchar a)
{
uchar i;
while(a--)for(i=0;i<120;i++);
}
main()
uchar keyval=0;
{
while(1)
{
if(key1==0);
{
while(key1==0);
keyval=1;
}
if(key2=0);
{
while(key2==0);
keyval=2;
}
if(key3==0);
{
while(key3==0);
keyval=3;
}
if(key4==0);
{
while(key4==0);
keyval=4;
}
switch(keyval)
{
case 1:
P0=led1;
led1=~led1;
delay(100);
break;
case 2:
P0=0xff;
break;
case 3:
P0=led;
led=_crol_(led,1);
delay(100);
break;
case 4:
P0=led;
led=_cror_(led,1);
delay(100);
break;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询