完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include
#define uchar unsigned char #define uint unsigned int #define sysclk 12000000 uint T0_ONE_MS = 0; uint T0_ONE_S = 0; uint T0_ONE_Miniute = 0; uint T0_TEN_Miniute = 0; uint T0_ADD_TEN_Miniute = 0; uchar T0_Four_Hour = 0; uchar T0_THREE_Hour = 0; uchar LED_PWM = 0; ***it SIGNAL = P3^2; //晚上:SIGNAL=1;白天:SIGNAL=0 ***it LED = P3^1; ***it temprature =P3^0; //夏天:temprature=1;冬天:temprature=0 void Reset_Value(void) { T0_ONE_MS = 0; T0_ONE_S = 0; T0_TEN_Miniute = 0; T0_Four_Hour = 0; T0_THREE_Hour = 0; TR0 = 0; TR1 = 0; } void time_Init(void) { TMOD = 0x11; //定时器0.1,模式1 EA = 1; //开总中断 ET0 = 1; //开定时器0中断 ET1 = 1; //开定时器1中断 TL0 = (65536-1000)%256; //1ms TH0 = (65536-1000)/256; TL1 = (65536-2200)%256; TH1 = (65536-2200)/256; } void main() { Time_Init(); LED = 0; SIGNAL = 0; temprature = 0; while(1) { if(SIGNAL == 0) { Reset_Value(); LED = 0; } else if(SIGNAL == 1) //天黑,SIGNAL=1 { if(temprature == 1) //夏天 {TR0 = 1; //用定时器0延时10分钟 if(T0_TEN_Miniute == 1) { T0_TEN_Miniute = 0; LED = 1; //点亮负载 T0_ADD_TEN_Miniute++; if(T0_ADD_TEN_Miniute == 25) //4小时时间到 { T0_Four_Hour = 1; T0_ADD_TEN_Miniute = 0; } } } else if(temprature == 0) //冬天 {TR0 = 1; if(T0_TEN_Miniute == 1) { T0_TEN_Miniute = 0; LED = 1; //点亮负载 T0_ADD_TEN_Miniute++; if(T0_ADD_TEN_Miniute == 19) //3小时时间到 { T0_THREE_Hour = 1; T0_ADD_TEN_Miniute++; } } } } if(T0_ADD_TEN_Miniute > 37) //6小时时间到 { LED = 0; //关闭负载 T0_ADD_TEN_Miniute = 0; TR1 = 0; } else if(T0_Four_Hour == 1) { T0_Four_Hour = 0; TR1 = 1; //开定时器1 LED = 0; //关闭负载 ; } else if(T0_THREE_Hour == 1) { T0_THREE_Hour = 0; TR1 = 1; //开定时器1 } } } void Time0() interrupt 1 { TL0 = (65536-1000)%256; //1ms TH0 = (65536-1000)/256; T0_ONE_MS++; if(T0_ONE_MS>1000) { T0_ONE_MS = 0; T0_ONE_S++; if(T0_ONE_S == 600) //10分钟时间到 { T0_ONE_S = 0; T0_TEN_Miniute = 1; } } } void Time1() interrupt 3 //300Hz { if(LED_PWM == 1) { TL1 = (65536-1100)%256; //1100us TH1 = (65536-1100)/256; LED_PWM = 0; LED = 1; } else if(LED_PWM == 0) { TL1 = (65536-2200)%256; //2200us TH1 = (65536-2200)/256; LED_PWM = 1; LED = 0; } } |
|
相关推荐
2个回答
|
|
感觉你的逻辑好像冲突了,代码太多,没时间给你全部分析过去
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
182 浏览 0 评论
如何用OpenCV的相机捕捉视频进行人脸检测--基于米尔NXP i.MX93开发板
1207 浏览 0 评论
《DNK210使用指南 -CanMV版 V1.0》第四十章 YOLO2人手检测实验
493 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-网络编程示例之开发板测试
420 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-网络编程示例之网络socket程序编程
957 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11742 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 07:41 , Processed in 0.590851 second(s), Total 73, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号