#include<reg51.h>
#define uchar unsigned char
uchar mima[4]={1,2,3,4}
uchar keymm[4]={0,0,0,0}
sbit key1=P1^0
sbit key2=P1^1
sbit key3=P1^2
sbit key4=P1^3
sbit led=P1^4
bit flag=0
void delay(uchar a)
{
uchar i
while(a--)for(i=0i<120i++)
}
main()
{
uchar i
led=1
while(1)
{
if(key1==0)
{
while(key1==0)
keymm[0]++
keymm[0]%=10
}
if(key2==0)
{
while(key2==0)
keymm[1]++
keymm[1]%=10
}
if(key3==0)
{
while(key3==0)
keymm[2]++
keymm[2]%=10
}
if(key4==0)
{
while(key4==0)
keymm[3]++
keymm[3]%=10
}
for(i=0i<4i++)
{
if(keymm[i]!=mima[i])break
if(i==3)flag=1
}
if(flag)
{
i=10
while(i--)
{
led=~led
delay(100)
}
flag=0
}
}
}
sbit KEY = P0^1sbit LED = P0^2
int keyscan(void)
{
bit keyval=0
if(KEY)
{
delay(30)//延时消抖
if(KEY)
{
keyval = ~keyval//值取反
if(keyval )
{
LED = 1//led亮
}
else
{
LED = 0//led灭
}
}
}
}
#include<reg52.h>#define uchar unsigned char
#define uint unsigned int
uchar code table[]=
{
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
}
sbit key1=P3^4
uchar num=0
void delay(uint z)
void main()
{
while(1)
{
P2=0xfe
P0=table[num]
delay(50)
if(key1==0)
{
while(!key1)
num++
}
if(num==10)
{
num=0
}
}
}
void delay(uint z)
{
while(z--)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)