- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "lcd.h"
- #include "ds18b20.h"
- #include "rtc.h"
- #include "spi.h"
- #define size 10//数组大小
- #define N 4//滑动平均滤波计算平均值时所取的点数
- void Smooth(float data[]);
- float temprature;
- int sum;
- int main(void)
- {
- u8 t=0,count=0;
- short temperature;
-
- unsigned int t1,i;
- unsigned char c;
- unsigned char flag;
- int xx;
- /* 配置系统时钟为72M */
- SystemInit();
-
- delay_init(); //延时函数初始化
- // NVIC_Configuration();
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2
- uart_init(9600); //串口初始化为9600
- LED_Init(); //初始化与LED连接的硬件接口
- RTC_Init();
- LCD_Init();
- /* MAX6675 SPI 接口初始化 */
- SPI_MAX6675_Init();
-
- POINT_COLOR=BLUE;//设置字体为蓝色
- while(DS18B20_Init()) //DS18B20初始化
- {
- LCD_ShowString(60,130,200,16,16,"DS18B20 Error");
- delay_ms(200);
- LCD_Fill(60,130,239,130+16,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(60,150,200,16,16,"Temp: . C");
- while(1)
- {
- if(t%10==0)//每100ms读取一次
- {
- POINT_COLOR=BLUE;//设置字体为蓝色
- temperature=DS18B20_Get_Temp();
- // printf("%d",&temperature);
- if(temperature<0)
- {
- LCD_ShowChar(60+40,150,'-',16,0); //显示负号
- temperature=-temperature; //转为正数
- } else LCD_ShowChar(60+40,150,' ',16,0); //去掉负号
- LCD_ShowNum(60+40+8,150,temperature/10,2,16); //显示正数部分
- LCD_ShowNum(60+40+32,150,temperature%10,1,16); //显示小数部分
-
-
- MAX6675_CSL();
- c = MAX6675_ReadByte();
- i = c;
- i = i<<8;
- c = MAX6675_ReadByte();
- MAX6675_CSH();
-
- i = i|((unsigned int)c); //i是读出来的原始数据
- flag = i&0x04; //flag保存了热电偶的连接状态
- t1 = i<<1;
- t1 = t1>>4;
- temprature = t1*0.25;
-
- for(i=0;i<0x2fffff;i++)
- ; //max6675的转换时间是0.2秒左右,所以两次转换间隔不要太近
- for (count=0;count<N;count++)
- {
- sum+=(temprature*10);
- delay_ms(10);
- }
- xx=sum/N;
-
-
- LCD_ShowString(60,200,200,16,16,"Temp: . C");
- LCD_ShowNum(60+40+8,200,xx/10,2,16); //显示正数部分
- LCD_ShowNum(60+40+32,200,xx%10,1,16); //显示小数部分
- POINT_COLOR=RED;//设置字体为红色
- LCD_ShowNum(60,50,RealTime.year,4,16); //显示年部分
- LCD_ShowChar(95,50,'Y',16,0); //显示Y
- LCD_ShowNum(110,50,RealTime.mon,2,16); //显示月部分
- LCD_ShowChar(130,50,'M',16,0); //显示M
- LCD_ShowNum(145,50,RealTime.date,2,16); //显示日部分
- LCD_ShowChar(165,50,'D',16,0); //显示D
- LCD_ShowNum(60,70,RealTime.hour,4,16); //显示时部分
- LCD_ShowChar(95,70,'H',16,0); //显示H
- LCD_ShowNum(110,70,RealTime.min,2,16); //显示分部分
- LCD_ShowChar(130,70,'M',16,0); //显示M
- LCD_ShowNum(145,70,RealTime.sec,2,16); //显示秒部分
- LCD_ShowChar(165,70,'S',16,0); //显示S
- switch(RealTime.week)
- {
- case 0:
- LCD_ShowString(80,100,200,24,24,"Sunday");//星期
- break;
- case 1:
- LCD_ShowString(80,100,200,24,24,"Monday");//星期
- break;
-
- case 2:
- LCD_ShowString(80,100,200,24,24,"Tuesday");//星期
- break;
-
- case 3:
- LCD_ShowString(80,100,200,24,24,"Wednesday");//星期
- break;
-
- case 4:
- LCD_ShowString(80,100,200,24,24,"Thursday");//星期
- break;
-
- case 5:
- LCD_ShowString(80,100,200,24,24,"Friday");//星期
- break;
-
- case 6:
- LCD_ShowString(80,100,200,24,24,"Saturday");//星期
- break;
-
- default:
- break;
- }
-
-
-
-
-
-
-
-
-
- }
- delay_ms(10);
- t++;
- if(t==20)
- {
- t=0;
- LED0=!LED0;
- }
- }
- }
复制代码
Keil代码下载:
代码.7z
(234.21 KB, 下载次数: 29)
|