/*函数原型:void setup(void)*/
/*功能:延时时间设置函数,通过矩阵式键盘可快速设置300s以内任意熄灯延时时间*/
/*调用函数:readkey()、delayms*/
/*入口参数:无*/
/*出口参数:无*/
#include <reg52.h>
#include <delay.h>
#include <readkey.h>
#include <infrared.h>
#include <showbuffer.h>
void setup()
{
uint n;
uchar key_val;
uchar numcount = 0;
set_sig_led = 0; //指示灯亮,表示正在设置延时时间
if(light == 1)
{
led = 0;
}
/*初始化6位数码管显示器:前三位为横杠,后三位全灭*/
for(n=0; n<3; n++)
{
buffer[n] = 0x0a;
}
for(n=3; n<6; n++)
{
buffer[n] = 0x0d;
}
showflag = 0x01;
while(showflag == 0x01)
{
do
{
key_val = readkey();
}while(key_val == 16); /*扫描键盘直到有键按下*/
switch(key_val)
{
case 0:;
case 1:;
case 2:;
case 3:;
case 4:;
case 5:;
case 6:;
case 7:;
case 8:;
case 9:
if(numcount != 3)
{
buffer[numcount] = key_val;
numcount++;
}
break;
case 11: /*确认键*/
n = (uint)buffer[0]*100+(uint)buffer[1]*10+(uint)buffer[2];
if((numcount == 3)&&(n < 300))
{
countdown = n;
timedown = countdown;
showflag = 0x00;
set_sig_led = 1;
led = 1;
}
else /*显示error并重新赋值*/
{
buffer[0] = 0x0b;
buffer[1] = 0x0c;
buffer[2] = 0x0c;
buffer[3] = 0x00;
buffer[4] = 0x0c;
buffer[5] = 0x0d;
delayms(2000);
for(n=0; n<3; n++)
{
buffer[n] = 0x0a;
}
for(n=3; n<6; n++)
{
buffer[n] = 0x0d;
}
}
numcount = 0x00;
break;
case 12: /*删除键*/
if(numcount != 0x00)
{
numcount--;
buffer[numcount] = 0x0a;
}
break;
case 13: /*取消键*/
countdown = countdown;
timedown = countdown;
buffer[0] = timedown/100;
buffer[1] = (timedown%100)/10;
buffer[2] = timedown%10;
set_sig_led = 1;
led = 1;
showflag = 0x00;
break;
default:break;
}
}
}
基于51单片机的人体感应灯设计
1星 需积分: 5 48 浏览量
2018-11-25
16:24:14
上传
评论 58
收藏 43KB ZIP 举报
kayrii
- 粉丝: 6
- 资源: 1
最新资源
- python-leetcode面试题解之第157题用Read4读取N个字符-题解.zip
- python-leetcode面试题解之第156题上下翻转二叉树-题解.zip
- python-leetcode面试题解之第155题最小栈-题解.zip
- python-leetcode面试题解之第153题寻找旋转排序数组中的最小值-题解.zip
- python-leetcode面试题解之第152题乘积最大子数组-题解.zip
- python-leetcode面试题解之第151题反转字符串中的单词-题解.zip
- python-leetcode面试题解之第150题逆波兰表达式求值-题解.zip
- python-leetcode面试题解之第149题直线上最多的点数-题解.zip
- python-leetcode面试题解之第148题排序链表-题解.zip
- python-leetcode面试题解之第147题对链表进行插入排序-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈