#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>#define uchar unsigned char
uchar sec,min,num
sbit led1=P1^0
sbit led2=P1^1
sbit key=P3^2
bit flag
void delay(uchar x)
{
uchar i,j
for(i=0i<xi++)
for(j=0j<120j++)
}
void t0isr() interrupt 1
{
TH0=(65536-50000)/256
TL0=(65536-50000)%256
num++
if(num>=20)
{
num=0
sec++
if(sec>59)
{
sec=0
min++
switch(min)
{
case 0:led1=0break
case 1:if(flag){led1=0min=0flag=0}
break
case 4:led1=1led2=0break
case 8:led2=1break
default:break
}
if(min>=20)min=0
}
}
}
void ext0() interrupt 0
{
delay(30)
if(key==0)
{
while(!key)
flag=1
sec=0
min=0
num=0
led1=1
led2=1
}
}
main()
{
TMOD=0x01
TH0=(65536-50000)/256
TL0=(65536-50000)%256
ET0=1
EA=1
EX0=1
IT0=1
TR0=1
led1=0
led2=1
flag=0
while(1)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)