资源描述:
《STM32温度报警传感器代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、主函数、main.c#include"led.h"#include"delay.h"#include"sys.h"#include"usart.h"#include"lcd.h"#include"ds18b20.h"#include"key.h"#include#include#includeinttemp_low=22;inttemp_high=32;intzanshi_low=0;intzanshi_hign=0;voidTIM3_Int_Init(u16a
2、rr,u16psc){TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;NVIC_InitTypeDefNVIC_InitStructure;RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);//时钟使能TIM_TimeBaseStructure.TIM_Period=arr;//设置在下一个更新事件装入活动的自动重装载寄存器周期的值计数到5000为500msTIM_TimeBaseStructure.TIM_Prescaler
3、=psc;//设置用来作为TIMx时钟频率除数的预分频值10Khz的计数频率TIM_TimeBaseStructure.TIM_ClockDivision=0;//设置时钟分割:TDTS=Tck_timTIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;//TIM向上计数模式TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);//根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位T
4、IM_ITConfig(//使能或者失能指定的TIM中断TIM3,//TIM2TIM_IT_Update,ENABLE//使能);NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;//TIM3中断NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;//先占优先级0级NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;//从优先级3级NVIC_InitStructure.NVIC_
5、IRQChannelCmd=ENABLE;//IRQ通道被使能NVIC_Init(&NVIC_InitStructure);//根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器TIM_Cmd(TIM3,ENABLE);//使能TIMx外设}u8flag=0;intmain(void){u8t=0;u8shuzu[20];u8keyvalue=0;u8gaibianshui=0;shorttemperature;delay_init();//延时函数初始化uart_init(9600);//串口初始
6、化为9600NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组2LED_Init();//初始化与LED连接的硬件接口TIM3_Int_Init(9999,7199);//10Khz的计数频率,计数到5000为500msLCD_Init();POINT_COLOR=RED;//设置字体为红色LCD_ShowString(0,50,200,16,16,"STM32test");LCD_ShowString(0,70,200,16,16,"name:zhan
7、gqiqi");//LCD_ShowString(0,90,200,16,16,"Max32CMin26C");memset(shuzu,0,20);sprintf(shuzu,"Maxis%2dC,Minis%2dC",temp_high,temp_low);LCD_ShowString(0,90,200,16,16,shuzu);while(DS18B20_Init())//DS18B20初始化{LCD_ShowString(0,130,200,16,16,"DS18B20Error");delay_ms(200)
8、;LCD_Fill(0,130,239,130+16,WHITE);delay_ms(200);}POINT_COLOR=BLUE;//设置字体为蓝色LCD_ShowString(0,110,260,16,16,"Thetemperatureis:.Cnow");LCD_ShowChar(0+25*8,110,',',16,0);