要求: 当K1按钮开关按下时(未放开)K2.K3.K4同时也可以控制LED2.LED3.LED4 请各位大侠帮忙看看怎么 改我是新手请大侠指导 谢谢。。。程序如下:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char counter;
sbit LED1=P0^0;
sbit LED2=P0^1;
sbit LED3=P0^2;
sbit LED4=P0^3;
sbit LED5=P0^4;
sbit LED6=P0^5;
sbit LED7=P0^6;
sbit K1=P2^0;
sbit K2=P2^1;
sbit K3=P2^2;
sbit K4=P2^3;
/********延时**************/
void DelayMS(uint x)
{
uchar i;
while(x--) for(i=0;i<120;i++);
}
/*****************主程序**********/
void main()
{
P0=0xff;
P2=0xff;
while(1)
{
LED2=K2;
LED3=K3;
LED4=K4;
LED1=K1;
LED5=K1;
if(K1==0)
{
while(K1==0);//等待按键释放
counter++;
if(counter>=20)
LED6=0;
if(counter>=10)
LED7=0;
}
DelayMS(10);
}
|