//S0、S1均未按下,黄灯亮,其余灯灭。
//S0单独按下,红灯亮,其余灯灭;
//S1单独按下,绿灯亮,其余灯灭;
//S0、S1均按下,红绿黄灯全亮;
/* Main.c file generated by New Project wizard
*
* Created: 周四 4月 6 2023
* Processor: AT89C51
* Compiler: Keil for 8051
*/
#include <reg51.h>
#include <stdio.h>
sbit s0=P1^7;
sbit s1=P1^6;
sbit R=P1^2;
sbit G=P1^1;
sbit Y=P1^0;
void main(void)
{
// Write your code here
unsigned char Q;
while (1)
{
Q=P1&0xc0;
switch(Q)
{
case 0xc0: P1=P1&0xfe|0xfe;break;
case 0x40: P1=P1&0xfb|0xfb;break;
case 0x80: P1=P1&0xfd|0xfd;break;
default: P1=P1&0xf8|0xf8;
}
}
}