您的位置:首页 > 科技 > 能源 > 网站排名易下拉刷词_展会布置_郑州网络推广哪家口碑好_优化网站标题是什么意思

网站排名易下拉刷词_展会布置_郑州网络推广哪家口碑好_优化网站标题是什么意思

2025/5/8 21:30:47 来源:https://blog.csdn.net/m0_72632761/article/details/146959397  浏览:    关键词:网站排名易下拉刷词_展会布置_郑州网络推广哪家口碑好_优化网站标题是什么意思
网站排名易下拉刷词_展会布置_郑州网络推广哪家口碑好_优化网站标题是什么意思

题目

 

 按键功能

 S4常规按键切换,S5,S8,S9不同界面小时数据或者参数加一,分钟加一,秒钟清零,且定时界面按下S9小时参数和分钟参数才生效。

时间界面下,时分值加一,秒钟清零,也就直接对时间数组进行操作,按下后修改值再写入ds1302里面。要注意ds1302是bcd码制的,16进制,而我们显示的是正常的十进制,所以我们要对写入ds1302的数据进行处理,逢十进一。

小时遇到23进位为0,分钟遇到59进位为0,特殊处理时间数据。

/*按键函数区域*/
void Key_Proc(){unsigned char t1;if(Key_Slow) return;else Key_Slow = 1;Key_Val = Key_Read();Key_Down = Key_Val & (Key_Val ^ Key_Old);Key_Up = ~Key_Val & (Key_Val ^ Key_Old);Key_Old = Key_Val;switch(Key_Down){case 4:if(++Seg_Mode == 3) Seg_Mode = 0;minite_disp = minite;//时间参数未生效的时候,显示的是之前生效的数据hour_disp = hour;break;case 5:if(Seg_Mode == 0){//在时间界面 按下时加一t1 = Time[0]/16;if(Time[0]%16 == 9){t1++;Time[0] = t1*16;}else if(Time[0] == 0x23) Time[0] = 0x00;else Time[0] = Time[0]+1;Time_Write(Time);}else if(Seg_Mode == 2){//在定时界面 按下时间参数加一hour_disp = hour_disp == 23?0:hour_disp+1;}break;case 8:if(Seg_Mode == 0){//在时间界面 按下分加一t1 = Time[1]/16;if(Time[1] == 0x59) Time[1] = 0x00;else if(Time[1]%16 == 9){t1++;Time[1] = t1*16;}else Time[1] = Time[1]+1;Time_Write(Time);}else if(Seg_Mode == 2){//在定时界面 按下分钟参数加一minite_disp = minite_disp ==59?0:minite_disp+1;}break;case 9:if(Seg_Mode == 0){//在时间界面 按下清零秒钟Time[2] = 0x00;Time_Write(Time);}else if(Seg_Mode == 2){//在定时界面 按下时间参数生效minite = minite_disp;hour = hour_disp;}break;}}

 这题的难点就是上面的时间进制转换。

显示功能

正常是时间显示温度显示和参数显示,多一个温度界面的测温启动与否。

定义一个标志位来判断就行了。

测温功能

ds1302内部时间到达我们设置的时间参数的时候就启动测温,按照题目的意思,就是测温一分钟,到不符合我们的参数,那就很简单了,一个简单的时间判断。

 

/*数码管函数区域*/
void Seg_Proc(){unsigned char hour1,minite1;if(Seg_Slow ) return;Seg_Slow = 1;Time_Read(Time);hour1 = Time[0]/16*10+Time[0]%16;minite1 = Time[1]/16*10+Time[1]%16;if((hour1 == hour)&&(minite1 == minite)){temp_flag = 1;//启动连续测温tempature = rd_tempature();}else temp_flag = 0;switch(Seg_Mode){case 0://时间界面Point[6] = 0;Seg_Buf[0] = Time[0]/16;Seg_Buf[1] = Time[0]%16;Seg_Buf[2] = 11;//-Seg_Buf[3] = Time[1]/16;Seg_Buf[4] = Time[1]%16;Seg_Buf[5] = 11;//-Seg_Buf[6] = Time[2]/16;Seg_Buf[7] = Time[2]%16;break;case 1://温度界面Seg_Buf[0] = 12;//CSeg_Buf[1] = 10;Seg_Buf[2] = 10;Seg_Buf[3] = 10;Seg_Buf[4] = 10;if(temp_flag){//启动测温Seg_Buf[5] = (unsigned char)tempature/10;Point[6] = 1;Seg_Buf[6] = (unsigned char)tempature%10;Seg_Buf[7] = (unsigned int)(tempature*10)%10;}else{Point[6] = 0;Seg_Buf[5] = 11;Seg_Buf[6] = 11;Seg_Buf[7] = 11;}break;case 2://参数界面Point[6] = 0;Seg_Buf[0] = 13;//ESeg_Buf[1] = 10;Seg_Buf[2] = 10;Seg_Buf[3] = hour_disp/10%10;Seg_Buf[4] = hour_disp%10;Seg_Buf[5] = 11;//-Seg_Buf[6] = minite_disp/10%10;Seg_Buf[7] = minite_disp%10;break;}
}

Led功能

也是很常规的界面点亮和功能启动闪烁led灯,不多赘述.

/*Led函数区域*/
void Led_Proc(){Led_Buf[0] = (Seg_Mode == 0);Led_Buf[1] = (Seg_Mode == 1);Led_Buf[2] = (Seg_Mode == 2);Led_Buf[7] = L8_flag;
}if(temp_flag){if(++Time_100ms == 100){Time_100ms = 0;L8_flag ^= 1;}
}
else{Time_100ms = 0;L8_flag = 0;
}

完整主函数 

/*头文件区域*/
#include <STC15F2K60S2.H>
#include <Key.h>
#include <Seg.h>
#include <Init.h>
#include <Led.h>
#include <onewire.h>
#include <ds1302.h>
#include <intrins.h>
/*参数变量区域*/
unsigned char Key_Slow,Seg_Slow;
unsigned char Seg_Pos;
unsigned char Key_Down,Key_Up,Key_Old,Key_Val;
//数组
unsigned char Seg_Buf[] = {10,10,10,10,10,10,10,10};
unsigned char Led_Buf[] = {0,0,0,0,0,0,0,0};
unsigned char Point[] = {0,0,0,0,0,0,0,0};
unsigned char Time[3] = {0x11,0x28,0x50};
//标志位
unsigned int Time_100ms;
unsigned char Seg_Mode;//0时间界面,1温度界面,2定时界面
unsigned char hour_disp = 11;//时钟参数
unsigned char minite_disp = 30;//分钟参数
unsigned char hour = 11;
unsigned char minite = 30;
float tempature;
bit temp_flag;
bit L8_flag;
/*按键函数区域*/
void Key_Proc(){unsigned char t1;if(Key_Slow) return;else Key_Slow = 1;Key_Val = Key_Read();Key_Down = Key_Val & (Key_Val ^ Key_Old);Key_Up = ~Key_Val & (Key_Val ^ Key_Old);Key_Old = Key_Val;switch(Key_Down){case 4:if(++Seg_Mode == 3) Seg_Mode = 0;minite_disp = minite;hour_disp = hour;break;case 5:if(Seg_Mode == 0){//在时间界面 按下时加一t1 = Time[0]/16;if(Time[0]%16 == 9){t1++;Time[0] = t1*16;}else if(Time[0] == 0x23) Time[0] = 0x00;else Time[0] = Time[0]+1;Time_Write(Time);}else if(Seg_Mode == 2){//在定时界面 按下时间参数加一hour_disp = hour_disp == 23?0:hour_disp+1;}break;case 8:if(Seg_Mode == 0){//在时间界面 按下分加一t1 = Time[1]/16;if(Time[1] == 0x59) Time[1] = 0x00;else if(Time[1]%16 == 9){t1++;Time[1] = t1*16;}else Time[1] = Time[1]+1;Time_Write(Time);}else if(Seg_Mode == 2){//在定时界面 按下分钟参数加一minite_disp = minite_disp ==59?0:minite_disp+1;}break;case 9:if(Seg_Mode == 0){//在时间界面 按下清零秒钟Time[2] = 0x00;Time_Write(Time);}else if(Seg_Mode == 2){//在定时界面 按下时间参数生效minite = minite_disp;hour = hour_disp;}break;}}
/*数码管函数区域*/
void Seg_Proc(){unsigned char hour1,minite1;if(Seg_Slow ) return;Seg_Slow = 1;Time_Read(Time);hour1 = Time[0]/16*10+Time[0]%16;minite1 = Time[1]/16*10+Time[1]%16;if((hour1 == hour)&&(minite1 == minite)){temp_flag = 1;//启动连续测温tempature = rd_tempature();}else temp_flag = 0;switch(Seg_Mode){case 0://时间界面Point[6] = 0;Seg_Buf[0] = Time[0]/16;Seg_Buf[1] = Time[0]%16;Seg_Buf[2] = 11;//-Seg_Buf[3] = Time[1]/16;Seg_Buf[4] = Time[1]%16;Seg_Buf[5] = 11;//-Seg_Buf[6] = Time[2]/16;Seg_Buf[7] = Time[2]%16;break;case 1://温度界面Seg_Buf[0] = 12;//CSeg_Buf[1] = 10;Seg_Buf[2] = 10;Seg_Buf[3] = 10;Seg_Buf[4] = 10;if(temp_flag){//启动测温Seg_Buf[5] = (unsigned char)tempature/10;Point[6] = 1;Seg_Buf[6] = (unsigned char)tempature%10;Seg_Buf[7] = (unsigned int)(tempature*10)%10;}else{Point[6] = 0;Seg_Buf[5] = 11;Seg_Buf[6] = 11;Seg_Buf[7] = 11;}break;case 2://参数界面Point[6] = 0;Seg_Buf[0] = 13;//ESeg_Buf[1] = 10;Seg_Buf[2] = 10;Seg_Buf[3] = hour_disp/10%10;Seg_Buf[4] = hour_disp%10;Seg_Buf[5] = 11;//-Seg_Buf[6] = minite_disp/10%10;Seg_Buf[7] = minite_disp%10;break;}
}/*Led函数区域*/
void Led_Proc(){Led_Buf[0] = (Seg_Mode == 0);Led_Buf[1] = (Seg_Mode == 1);Led_Buf[2] = (Seg_Mode == 2);Led_Buf[7] = L8_flag;
}
/*定时器0初始化函数区域*/
void Timer0_Init(void)		//1毫秒@12.000MHz
{AUXR |= 0x80;			//定时器时钟1T模式TMOD &= 0xF0;			//设置定时器模式TL0 = 0x20;				//设置定时初始值TH0 = 0xD1;				//设置定时初始值TF0 = 0;				//清除TF0标志TR0 = 1;				//定时器0开始计时ET0 = 1;EA = 1;
}
/*定时器0中断服务函数区域*/
void Timer0_Service() interrupt 1
{if(++Seg_Slow == 200) Seg_Slow = 0;if(++Key_Slow == 50) Key_Slow = 0;if(++Seg_Pos == 8) Seg_Pos = 0;Seg_Disp(Seg_Pos,Seg_Buf[Seg_Pos],Point[Seg_Pos]);Led_Disp(Seg_Pos,Led_Buf[Seg_Pos]);if(temp_flag){if(++Time_100ms == 100){Time_100ms = 0;L8_flag ^= 1;}}else{Time_100ms = 0;L8_flag = 0;}
}void Delay750ms(void)	//@12.000MHz
{unsigned char data i, j, k;_nop_();_nop_();i = 35;j = 51;k = 182;do{do{while (--k);} while (--j);} while (--i);
}/*主函数区域*/
void main(){Sys_Init();Timer0_Init();Time_Write(Time);rd_tempature();Delay750ms();while(1){Led_Proc();Key_Proc();Seg_Proc();}
}

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com