void keyscan()
{
if (k1==0)
Delayms(20);
if (k1==0)
{ while (!k1);
cs++;
if (cs==4)
cs=1;
}
switch (cs)
{
case 1:
//hight();//高亮状态,进入定时并显示
led_3 ();
break;
case 2:
//bight();//中亮
led_3 ();
break;
case 3:
//light();//低亮
led_3 ();
break;
case 4:hight();break; //静止状态
case 5:bight();break;
case 6:light();break;
case 7: //定时10s
led_2();
break;
case 8:
led_2();
break;
case 9:
led_2();
break;
case 10: //定时30S
led_1();
break;
case 11:
led_1();
break;
case 12:
led_1();
break;
void keyscan()
{
if (k1==0)
Delayms(20);
if (k1==0)
{ while (!k1);
cs++;
if (cs==4)
cs=1;
}
switch (cs)
{
case 1:
//hight();//高亮状态,进入定时并显示状态
led_3 ();
break;
case 2:
//bight();//中亮
led_3 ();
break;
case 3:
//light();//低亮
led_3 ();
break;
case 4:hight();break; //¾²Ö¹×´Ì¬
case 5:bight();break;
case 6:light();break;
case 7: //
led_2();
break;
case 8:
led_2();
break;
case 9:
led_2();
break;
case 10: //¶¨Ê±30Ãë
led_1();
break;
case 11:
led_1();
break;
case 12:
led_1();
break;
是哪个帖子呢。。
谢谢大牛。还有一步就是按键可控制整体(16路)亮度共三档(高中低)现在共有3种时间5S、10S、30S每种时间有高中低三种亮度,也就是共9个模式。
void init()
{
TMOD=0x01; //
TH0=(65536-50000)/256; //
TL0=(65536-50000)%256;
ET0=1; //
TR0=1; //
}
void time0() interrupt 1 //
{
TH0=(65536-50000)/256;//50ms
TL0=(65536-50000)%256;
p++;
} 这个是定时的基准时间50MS
void bight()
{
for (pwm=time;pwm>0;pwm--)
{
P0=P1=0XFF;
delay(6);
P0=P1=0X00;
delay(4);
}
}
void light()
{
for (pwm=time;pwm>0;pwm--)
{
P0=P1=0XFF;
delay(1);
P0=P1=0X00;
delay(9);
}
}这个使用for循环写了俩亮度,中和低
我用同样的方法switch 一个变量来计按键次数来进入相应的时间控制程序,但整体亮度就没反应,这个该怎么组下呢?
void keyscan()
{
if (k1==0)
Delayms(20);
if (k1==0)
{ while (!k1);
cs++;
if (cs==4)
cs=1;
}
switch (cs)
{
case 1:
//hight();//高亮状态,进入定时并显示
led_3 ();
break;
case 2:
//bight();//中亮
led_3 ();
break;
case 3:
//light();//低亮
led_3 ();
break;
case 4:hight();break; //静止状态
case 5:bight();break;
case 6:light();break;
case 7: //定时10s
led_2();
break;
case 8:
led_2();
break;
case 9:
led_2();
break;
case 10: //定时30S
led_1();
break;
case 11:
led_1();
break;
case 12:
led_1();
break;
}
}
最终main里只有 keyscan()扫描程序。按键后进入switch 亮度和定时显示,只能进一个。。。
void keyscan()
{
if (k1==0)
Delayms(20);
if (k1==0)
{ while (!k1);
cs++;
if (cs==4)
cs=1;
}
switch (cs)
{
case 1:
//hight();//高亮状态,进入定时并显示状态
led_3 ();
break;
case 2:
//bight();//中亮
led_3 ();
break;
case 3:
//light();//低亮
led_3 ();
break;
case 4:hight();break; //¾²Ö¹×´Ì¬
case 5:bight();break;
case 6:light();break;
case 7: //
led_2();
break;
case 8:
led_2();
break;
case 9:
led_2();
break;
case 10: //¶¨Ê±30Ãë
led_1();
break;
case 11:
led_1();
break;
case 12:
led_1();
break;
}
}
这是最终while(1)循环的按键检测程序,,亮度程序和定时显示程序只能进一个,。。。额..
一周热门 更多>