一、电路图
二、程序展示
#include <REGX51.H>
#define uchar unsigned char
#define uint unsigned int
sbit light=P1^0;
sbit add=P2^0;
sbit cut=P2^1;
sbit ex0=P3^3;
uint time=2000;
void delay(uint ms);
main()
{
EA=1;
EX1=1;
IT1=0;
while(1)
{
if(add==0)
{
delay(10);
if(add==0)
{
while(add==0);
if(time<=50000)
time=time+ 1000;
}
}
if(cut==0)
{
delay(10);
if(cut==0)
{
while(cut==0);
if(time>=2000)
time=time-1000;
}
}
}
}
void int_ex0(void)interrupt 2
{
light=0;
while(ex0==0);
delay(time);
light=1;
}
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<125;j++)
;
}