不能用、
追答你端口跟我的端口以不一样
追问是1个开关。你这个是三个开关呀
追答我在帮你改成1个键控制
void KeyScang(void)
{
unsigned char i;
/* 按键1 */
if(Key_In1 == 0)
{
Delay_1ms(5);
if(Key_In1 == 0)
{
if(++Update_Flag1 >= 4)
Update_Flag1 = 0;
}
while(Key_In1 == 0);
}
//
/* LED全亮 */
if(Update_Flag1 == 1)
{
P1 = 0x00; /* P1口LED全亮 */
}
/* 循环显示最后全灭 */
if(Update_Flag1 == 2)
{
for(i = 0; i < 8; i++)
{
P1 = TABLE[i];
Delay_1ms(500);
}
P1 = 0xFF;
}
/* LED闪烁3次 */
if(Update_Flag1 == 3)
{
P1 = 0x00;
Delay_1ms(500);
P1 = 0xFF;
Delay_1ms(500);
P1 = 0x00;
Delay_1ms(500);
P1 = 0xFF;
Delay_1ms(500);
P1 = 0x00;
Delay_1ms(500);
P1 = 0xFF;
Delay_1ms(500);
}
}
需要编程 C51语言 要按第四下 跪求啊
追答#include "REG52.H"
sbit Key = P1^0;
void Delay_1ms(unsigned int Cnt)
{
unsigned int x, y;
for(x = Cnt; x > 0; x--) for(y = 110; y > 0; y--);
}
bit KeyRead(void)
{
if(!Key) {
Delay_1ms(5);
if(!Key) {
while(!Key);
return 0;
}
}
return 1;
}
void main()
{
while (1) {
while (KeyRead()); //等待第一次按键
P0 = 0; //全亮
while (KeyRead()); //等待第二次按键
P0 = 0xfe; Delay_1ms(500);//流水
P0 = 0xfd; Delay_1ms(500);
P0 = 0xfb; Delay_1ms(500);
P0 = 0xf7; Delay_1ms(500);
P0 = 0xef; Delay_1ms(500);
P0 = 0xdf; Delay_1ms(500);
P0 = 0xbf; Delay_1ms(500);
P0 = 0x7f; Delay_1ms(500);
P0 = 0xFF; //全灭
while (KeyRead()); //等待第三次按键
P0 = 0; Delay_1ms(500); //全亮
P0 = 0xFF; Delay_1ms(500); //全灭
P0 = 0; Delay_1ms(500); //全亮
P0 = 0xFF; Delay_1ms(500); //全灭
P0 = 0; Delay_1ms(500); //全亮
P0 = 0xFF; Delay_1ms(500); //全灭
}
}