用DS1302一般是用时间来控制某一设备。
精确到分钟,小时是24一天。
开机时间:DS_RAM0,DS_RAM1 中存储
关机时间:DS_RAM2,DS_RAM3 中存储
软件:PICC
//********************************************************
void YEAR10000(void)
{
#define DS_RAM0 0XC1 //open_hour 设定时间
#define DS_RAM1 0XC3 //open_minute
#define DS_RAM2 0XC5 //close_hour
#define DS_RAM3 0XC7 //close_minute
unsigned char open_hour,open_minute,hour,minute,close_hour,close_minute;
unsigned char t_flag;
//读开小时和分钟
open_hour = DSRecive_byte(DS_RAM0); //ram1
open_minute = DSRecive_byte(DS_RAM1);
//读关小时和分钟
close_hour = DSRecive_byte(DS_RAM2);
close_minute = DSRecive_byte(DS_RAM3);
t_flag = 0;
//读当前时间
hour = DS1302_ReadHour(); /**/
minute = DS1302_ReadMinute(); /****/
if (open_hour == close_hour)
{
if (hour == open_hour)
{
if ((open_minute <=minute)&&(minute <=close_minute)) t_flag = 1;
else t_flag = 0;
}
}
else if (open_hour < close_hour)
{
if ((hour==open_hour)&&(minute >=open_minute)) t_flag =1; //else t_flag = 0;
else if ((open_hour < hour)&&(hour < close_hour)) t_flag = 1; //else t_flag = 0;
else if ((hour == close_hour)&&(minute <=close_minute)) t_flag = 1;//else t_flag = 0;
else t_flag = 0;
}
else if (open_hour > close_hour)
{
if ((hour==open_hour)&&(minute >= open_minute)) t_flag =1;//else t_flag = 0;
else if ((open_hour < hour)&&(hour < 0x24)) t_flag =1;//else t_flag = 0;
else if ((0 < hour )&&(hour< close_hour)) t_flag = 1;//else t_flag = 0;
else if ((hour == close_hour)&&(minute <=close_minute)) t_flag = 1;//else t_flag = 0;
else t_flag = 0;
}
if (t_flag ==1) HeadLamp = 1;else HeadLamp = 0;
}
文章评论(0条评论)
登录后参与讨论