1、没必要通过24c02来存储设置的数据
2、89C52没有ADC,如果需要输入模拟量,请外接ADC
3、部分程序贴出。供大家参考:(全部程序请下载zip附件)
#include<REG52.h>#include<timer.h>
#include<DigitalTube.h>
//中断0唤醒单片机 //开启单片机按键接P3^2
//以下随意改,只要不与数码管数据冲突
sbit key_1 = P1^0 //关孙颂闭单片机
sbit key_2 = P1^1 //时间+
sbit key_3 = P1^2 //时间-
sbit key_4 = P1^3 //确认
#define Period 5 //每次加或减的时间(分钟)
sbit LAMP = P1^4 //台灯开关控制输入
bit confirm=0
char time=40 //以分钟为单位,每次加Period分钟或减Period分钟
void menu(void)
{
if(key_1==0)
{
delay(10)
if(key_1==0)
{
delay(5)
while(key_1==0)delay(5)
PCON=0x02 //进入掉电模式
}
}
if(key_2==0)
{
delay(10)
if(key_2==0)
{
delay(5)
while(key_2==0)delay(5)
if(time<60)
{
time+=Period
}
}
}
if(key_3==0)
{
delay(10)
if(key_3==0)
{
delay(5)
while(key_3==0)delay(5)
if(time>20)
{
time-=Period
}
}
}
if(key_4==0)
{
delay(10)
if(key_4==0)
{
delay(5)
while(key_4==0)delay(5)
confirm=1
}
}
}
void main(void)
{
IE=0x81 //开中断
IT0=1 //低电平触发
LAMP=1 //点亮台灯
PCON=0x02 //关闭单片机
while(1)
{
while(!confirm)
{
menu()
DigitalTube_disNum(0,time/10)
DigitalTube_disNum(1,time%10)
}
while(time>0)
{
time--
delay(60000) //一分钟,误差有一点
}
LAMP=0 //关闭台灯
time=40
confirm=0
}
}
void Wakeup() interrupt 0 using 0 //中高凯旁断唤戚橡醒单片机
{
unsigned char i = 0
IE = 0x00
delayMicroseconds(10)
while(i<4)
{
DigitalTube_disNum(i++,8)
}
IE = 0x81
}
#include"timer.h"
#if FOSC==12 //如果使用12MHz晶振
void delay(unsigned int ms)
{
unsigned int i
for(ms>0ms--)
for(i=0i<124i++)
}
#else
void delay(unsigned int ms)
{
unsigned int i
for(ms>0ms--)
for(i=0i<=113i++)
}
#endif
void delayMicroseconds(unsigned int us)
{
for(us>4us-=4)
}
#ifdef USE_MORE_DELAY
void delayminutes(unsigned int minute)
{
unsigned int i,j
for(minute>0minute--)
for(i=0i<125i++)
for(j=0j<60000j++)
}
void delayday(unsigned int day)
{
unsigned int i,j
for(day>0day--)
for(i=0i<3000i++)
for(j=0j>60000j++)
}
#endif
#include"DigitalTube.h"
#define HIGH 0
#define LOW 1
#ifdef CO_CATHODE
#define N_0 0xC0
#define N_1 0xF9
#define N_2 0xA4
#define N_3 0xB0
#define N_4 0x99
#define N_5 0x92
#define N_6 0x82
#define N_7 0xF8
#define N_8 0x80
#define N_9 0x90
#endif
#ifdef CO_ANODE
#define N_0 0x3F
#define N_1 0x06
#define N_2 0x5B
#define N_3 0x4D
#define N_4 0x66
#define N_5 0x6D
#define N_6 0x7D
#define N_7 0x07
#define N_8 0x7F
#define N_9 0x6F
#endif
#if Seg_Number>7
#define SegLOW {Segment_7 = LOWSegment_6 = LOWSegment_5 = LOWSegment_4 = LOWSegment_3 = LOWSegment_2 = LOWSegment_1 = LOWSegment_0 = LOW}
#endif
#if Seg_Number>6
#ifndef SegLOW
#define SegLOW {Segment_6 = LOWSegment_5 = LOWSegment_4 = LOWSegment_3 = LOWSegment_2 = LOWSegment_1 = LOWSegment_0 = LOW}
#endif
#endif
#if Seg_Number>5
#ifndef SegLOW
#define SegLOW {Segment_5 = LOWSegment_4 = LOWSegment_3 = LOWSegment_2 = LOWSegment_1 = LOWSegment_0 = LOW}
#endif
#endif
#if Seg_Number>4
#ifndef SegLOW
#define SegLOW {Segment_4 = LOWSegment_3 = LOWSegment_2 = LOWSegment_1 = LOWSegment_0 = LOW}
#endif
#endif
#if Seg_Number>3
#ifndef SegLOW
#define SegLOW {Segment_3 = LOWSegment_2 = LOWSegment_1 = LOWSegment_0 = LOW}
#endif
#endif
#if Seg_Number>2
#ifndef SegLOW
#define SegLOW {Segment_2 = LOWSegment_1 = LOWSegment_0 = LOW}
#endif
#endif
#if Seg_Number>1
#ifndef SegLOW
#define SegLOW {Segment_1 = LOWSegment_0 = LOW}
#endif
#endif
#if Seg_Number>0
#ifndef SegLOW
#define SegLOW {Segment_0 = LOW}
#endif
#endif
unsigned int i = 0
void DigitalTube_disNum(unsigned char seg_Number,unsigned char Data)
{
switch(Data)
{
case 0: SegData_Port = N_0break
case 1: SegData_Port = N_1break
case 2: SegData_Port = N_2break
case 3: SegData_Port = N_3break
case 4: SegData_Port = N_4break
case 5: SegData_Port = N_5break
case 6: SegData_Port = N_6break
case 7: SegData_Port = N_7break
case 8: SegData_Port = N_8break
case 9: SegData_Port = N_9break
}
SegLOW
switch(seg_Number)
{
#if Seg_Number>7
case 7:Segment_7 = HIGHbreak
#endif
#if Seg_Number>6
case 6:Segment_6 = HIGHbreak
#endif
#if Seg_Number>5
case 5:Segment_5 = HIGHbreak
#endif
#if Seg_Number>4
case 4:Segment_4 = HIGHbreak
#endif
#if Seg_Number>3
case 3:Segment_3 = HIGHbreak
#endif
#if Seg_Number>2
case 2:Segment_2 = HIGHbreak
#endif
#if Seg_Number>1
case 1:Segment_1 = HIGHbreak
#endif
#if Seg_Number>0
case 0:Segment_0 = HIGHbreak
#endif
}
while(i++<30)i=0 //一点点延时,保障数码管不闪烁也不缺段
}
1、测人体的话可以选择人体红外传感器,当光束被挡时输出高电平,这种传感器有一种半成品,输出也是脉冲的,当有人时输出3。5V高电平维持3秒,如人没有离开就继续输出,人离开后就变成低电平。2、测光源基本上用光敏电阻就可以了,将光敏电阻附加三极管等元件做成一个光敏传感器,一旦光强空顷好低于某个值就向单片机返回一个高/低电平信号,由单片机处理。
3、单片机用51即可,输出引脚上连一个7407,然后连到继电器上即可。
4、其实也可以不用单片机的,只要一个逻辑芯片就可以了,比如如果高电平时有人,高电平时光弱,那么乎悔只要将这两个信号送到一个与门就可以了,与门输出一个高电平,然后驱动继电器即可!
希望能帮到你,对于这个东西你可以分成几个模斗铅块,一个模块一个模块搞定再综合,多在网上搜索一下,网上有大量的资料可以借鉴,加油!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)