#include<reg52.h>
sbit Key0=P1^0; //P1^0
sbit Key1=P1^1;// P1^1
sbit PWM=P1^7;
unsigned char num=0,Duty=5;
void Delay(unsigned int time)
{
unsigned int i=0,j=0;
for(i=0;i<time;i++)
for(j=0;j<114;j++);
}
void Key_Scanf(void)
{
if(Key0==0)
{
Delay(20);
if(Key0==0)
Duty-=1;
while(!Key0);
}
if(Key1==0)
{
Delay(20);
if(Key1==0)
Duty+=1;
while(!Key1);
}
Duty=Duty>1?Duty:1;
Duty=Duty<9?Duty:9;
}
void Timer0_Inits(void)
{
TMOD|=0x01;
TH0=(65535-10000)/256;
TL0=(65535-10000)%256;
TR0=1;
ET0=1;
EA=1;
}
void main(void)
{
Timer0_Inits();
while(1)
{
Key_Scanf();
}
}
void PIT0(void) interrupt 1
{
TH0=(65535-10000)/256;
TL0=(65535-10000)%256;
++num;
if(num<=Duty)
PWM=1;
else
PWM=0;
if(num>9)
num=0;
}
牧羊人nacy