#define uint unsigned int
#define uchar unsigned char
void delay_ms(uint)
sbit led0=P0^0
sbit led1=P0^1
sbit key1=P3^2
sbit key2=P3^3
void main()
{
uchar i=0
uchar j=0
while(1)
{
if(key1==0)//按键1
{
delay_ms(10)
if(key1==0)
{
i++
i=i%2
switch(i)
{
case 0: led0=1 break//关小灯
case 1: led0=0 break//开小灯
default: break
}
}
while(!key1)
}
if(key2==0)//按键2
{
delay_ms(10)
if(key2==0)
{
j++
j=j%2
switch(j)
{
case 0: led1=1 break//关小灯
case 1: led1=0 break//开小灯
default: break
}
}
while(!key2)
}
}
}
void delay_ms(uint z) //延时子程序
{
uint x,y
for(x=zx>0x--)
for(y=110y>0y--)
}
#include "reg51.h"sbit led_1 = P0^0
sbit led_2 = P0^1
sbit led_3 = P0^3
int main(void)
{
while(1)
{
switch(P2 & 0x0F)
{
case 12:
case 8:
case 7:
case 9:
case 10:
case 11:
case 13:
case 14:
case 15:led_1 = 0 led_2 = 1 led_3 = 1break
case 4:
case 5:
case 6:led_1 = 1 led_2 = 0 led_3 = 1break
case 0:
case 1:
case 2:led_1 = 1 led_2 = 1 led_3 = 0break
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)