#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
void delayms(uint);
sbit pwm=P2^7;
uchar aa=1,bb=0,cc=0,dd=0,ee=1;
void main()
{
TMOD=0X01;
TH0=(65536-1000)/256;
TL0=(65536-1000)/256;
EA=1;
ET0=1;
TR0=1;
while(1);
}
void key() //按鍵檢測處理函數
{
uchar temp;
P3=0xfe;
temp=P3;
temp=(temp&0xf0);
if(temp!=0xf0)
{
delayms(10);
if(temp!=0xf0)
{
temp=P3; //消抖
switch(temp)
{
case 0xee:
TR0=~TR0;
break;
case 0xde:
if(cc==0)
aa+=10;
if(aa>100)
aa=1;
break;
}
while(temp!=0xf0) //等待按鍵釋放
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=(temp&0xf0);
if(temp!=0xf0)
{
delayms(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:
if(dd=0)
aa+=1;
break;
case 0xdd:
if(cc=1)
cc=1;
dd=1;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
}
void time1()interrupt 3
{
TH0=(65536-1000)/256;
TL0=(65536-1000)/256;
bb++;
if(bb>=100) bb=0;
if(bb<=aa)
pwm=1;
else
pwm=0;
}
void time2()interrupt 1
{
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i++)
for(j=110;j>0;j++);
}
|