一、功能描述
人体红外模拟开关的灯亮
二、程序
#include <REGX51.H>
#define uchar unsigned char
#define uint unsigned int
sbit light=P3^4;
sbit add=P2^7;
sbit cut=P2^6;
sbit ex0=P3^2;
uint time=2000;
void delay(uint ms);
main()
{
EA=1;
EX0=1;
IT0=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 0 using 0
{
light=1;
while(ex0==0);
delay(time);
light=0;
}
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<125;j++);
}
三、电路图
四、小结
本次课是在家上的,一开始打完代码发现有错,但是没找出来,后经过检查多打了一个字母,最终成功了。