一、功能描述
①
②
二、程序
①#include <REGX51.H>
#define uchar unsigned char
#define uint unsigned int
sbit light=P1^2;
sbit add=P2^0;
sbit cut=P2^1;
sbit ex0=P3^3;
uint time=20000;
void delay(uint ms);
main()
{
EA=1;
EX1=1;
IT1=0;
while(1)
{
if(add==0)
{
delay(10);
while(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 using 0
{
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++)
;
}
②#include <REGX51.H>
#define uchar unsigned char
#define uint unsigned int
sbit light=P1^0;
sbit ex1=P3^3;
/*---------ÑÓʱkmsº¯Êý---------*/
void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++)
{
for(j=0;j<125;j++)
;
}
}
/*---------Ö÷º¯Êý---------*/
void main()
{
EA=1;
EX1=1;
IT1=1;
while(1)
{;}
}
void int_ex0(void) interrupt 2
{
light=0;
while(ex1==0);
delay(2000);
light=1;
}
四、小结