完整word版嵌入式系统课程设计温度检测报警系统.docx

上传人:b****6 文档编号:6981425 上传时间:2023-01-14 格式:DOCX 页数:16 大小:48.04KB
下载 相关 举报
完整word版嵌入式系统课程设计温度检测报警系统.docx_第1页
第1页 / 共16页
完整word版嵌入式系统课程设计温度检测报警系统.docx_第2页
第2页 / 共16页
完整word版嵌入式系统课程设计温度检测报警系统.docx_第3页
第3页 / 共16页
完整word版嵌入式系统课程设计温度检测报警系统.docx_第4页
第4页 / 共16页
完整word版嵌入式系统课程设计温度检测报警系统.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

完整word版嵌入式系统课程设计温度检测报警系统.docx

《完整word版嵌入式系统课程设计温度检测报警系统.docx》由会员分享,可在线阅读,更多相关《完整word版嵌入式系统课程设计温度检测报警系统.docx(16页珍藏版)》请在冰豆网上搜索。

完整word版嵌入式系统课程设计温度检测报警系统.docx

完整word版嵌入式系统课程设计温度检测报警系统

嵌入式系统课程设计

 

姓名:

班级:

学号:

 

目录:

1.系统要求

2.设计方案

三.程序流程图

四.软件设计

五.课程总结与个人体会

 

一、系统要求

使用STM32F103作为主控CPU设计一个温度综合测控系统,具体要求:

1、使用热敏电阻或者内部集成的温度传感器检测环境温度,每0.1秒检测一次温度,对检测到的温度进行数字滤波(可以使用平均法)。

记录当前的温度值和时间。

2、使用计算机,通过串行通信获取STM32F103检测到的温度和所对应的时间。

3、使用计算机进行时间的设定。

4、使用计算机进行温度上限值和下限值的设定。

5、若超过上限值或者低于下限值,则STM32进行报警提示。

 

2、设计方案

本次课程设计的要求是使用STM32F103设计一个温度测控系统,这款单片机集成了很多的片上资源,功能十分强大,我使用了以下部分来完成课程设计的要求:

1、STM32F103内置了3个12位A/D转换模块,最快转换时间为1us。

本次课程设计要求进行温度测定,于是使用了其中一个ADC对片上温度传感器的内部信号源进行转换。

当有多个通道需要采集信号时,可以把ADC配置为按一定的顺序来对各个通道进行扫描转换,本设计只采集一个通道的信号,所以不使用扫描转换模式。

本设计需要循环采集电压值,所以使用连续转换模式。

2、本次课程设计还使用到了DMA。

DMA是一种高速的数据传输操作,允许在外部设备和储存器之间利用系统总线直接读写数据,不需要微处理器干预。

使能ADC的DMA接口后,DMA控制器把转换值从ADC数据寄存器(ADC_DR)中转移到变量ADC_ConvertedValue中,当DMA传输完成后,在main函数中使用的ADC_ConvertedValue的内容就是ADC转换值了。

3、STM32内部的温度传感器和ADCx_IN16输入通道相连接,此通道把传感器输出的电压值转换成数字值。

STM内部的温度传感器支持的温度范围:

-40到125摄氏度。

利用下列公式得出温度

温度(°C)={(V25-VSENSE)/Avg_Slope}+25

式中V25是VSENSE在25摄氏度时的数值(典型值为1.42V)

Avg_Slope是温度与VSENSE曲线的平均斜率(典型值为4.3mV/C)

利用均值法对转换后的温度进行滤波,将得到的温度通过串口输出。

4、本设计采用了USART1作为串行通信接口,来进行时间、温度的传输,以及进行时间和温度上下限的设定。

5、当温度超过上下限时,开发板上的灯会相应亮起作为警报,使用了GPIO配置引脚。

6、时间计时使用了systick时钟,并配置其中断,由此进行一秒定时,实现时钟的实时显示。

7、时间设定部分参考了一个两位数字读取的函数,在进入主循环前设定参数,从而避免了在串口中断中输入只能一次性输入所有参数的弊端。

 

3、程序流程图

 

4、软件设计

用到的库文件:

stm32f10x_adc.h,stm32f10x_dma.h,stm32f10x_flash.h,stm32f10x_gpio.h,stm32f10x_rcc.h,stm32f10x_usart.h,misc.h

自己编写的文件:

main.c,stm32f10x_it.c,stm32f10x_it.h

 

main文件:

#include"stm32f10x.h"

#include"stdarg.h"

#include"stdio.h"

#defineADC1_DR_Address((uint32_t)0x4001244C)

extern__IOu16ADC_ConvertedValue;

extern__IOu16calculated_temp;

__IOu16Current_Temp;

unsignedcharsec=0,min=0,hour=0;

typedefstruct

{

inttm_sec;

inttm_min;

inttm_hour;

}rtc_time;

rtc_timesystmtime;

__IOu16upper_bound;

__IOu16lower_bound;

//staticuint8_tUSART_Scanf(uint32_tvalue);

voidTime_Regulate(rtc_time*tm);

 

unsignedintTimingDelay=0;

unsignedintKEY_ON;

unsignedintKEY_OFF;

voidDelay(u32count)

{

u32i=0;

for(;i

}

voidLED_GPIO_Config()

{

GPIO_InitTypeDefGPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);//使能PD端口时钟

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11;//LED0-->PD.8端口配置

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//推挽输出

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//IO速度50MHz

GPIO_Init(GPIOD,&GPIO_InitStructure);//根据设定参数初始化GPIOB.5

}

voidSysTick_Init()

{

if(SysTick_Config(SystemCoreClock/1000))

{

while

(1);

}

SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭滴答定时器

//SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;//开启滴答定时器

}

voidDelay_ms(__IOu32nTime)

{

TimingDelay=nTime;

SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;//打开

while(TimingDelay!

=0);

}

voidRCC_Config(void)//配置时钟

{

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);//DMA

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1|RCC_APB2Periph_GPIOC,ENABLE);//ADC1andGPIOC

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA,ENABLE);//USART

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);//使能PD端口时钟LED

}

voidGPIO_Config(void)

{

GPIO_InitTypeDefGPIO_InitStructure;

/***ConfigPA.01(ADC1)***/

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;

GPIO_Init(GPIOC,&GPIO_InitStructure);

/***ConfigLED***/

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//推挽输出

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//IO速度50MHz

GPIO_Init(GPIOD,&GPIO_InitStructure);//根据设定参数初始化GPIOB.5

/***ConfigUSART***/

/*ConfigureUSART1Tx(PA.09)asalternatefunctionpush-pull*/

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

GPIO_Init(GPIOA,&GPIO_InitStructure);

/*ConfigureUSART1Rx(PA.10)asinputfloating*/

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA,&GPIO_InitStructure);

}

voidDMA_Config(void)

{

/*DMAchannel1configuration*/

DMA_InitTypeDefDMA_InitStructure;

DMA_DeInit(DMA1_Channel1);

DMA_InitStructure.DMA_PeripheralBaseAddr=ADC1_DR_Address;/*ADC?

?

*/

DMA_InitStructure.DMA_MemoryBaseAddr=(u32)&ADC_ConvertedValue;

DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;

DMA_InitStructure.DMA_BufferSize=16;

DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Disable;

DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;

DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord;

DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;

DMA_InitStructure.DMA_Priority=DMA_Priority_High;

DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;

DMA_Init(DMA1_Channel1,&DMA_InitStructure);

/*EnableDMAchannel1*/

DMA_Cmd(DMA1_Channel1,ENABLE);

}

 

voidADC1_Config(void)

{ADC_InitTypeDefADC_InitStructure;

ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;

ADC_InitStructure.ADC_ScanConvMode=ENABLE;

ADC_InitStructure.ADC_ContinuousConvMode=ENABLE;

ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel=1;

ADC_Init(ADC1,&ADC_InitStructure);

/*ADC1regularchannel16configuration*/

ADC_RegularChannelConfig(ADC1,ADC_Channel_16,1,ADC_SampleTime_55Cycles5);

ADC_TempSensorVrefintCmd(ENABLE);

ADC_DMACmd(ADC1,ENABLE);

ADC_Cmd(ADC1,ENABLE);

ADC_ResetCalibration(ADC1);

while(ADC_GetResetCalibrationStatus(ADC1));

ADC_StartCalibration(ADC1);

while(ADC_GetCalibrationStatus(ADC1));

ADC_SoftwareStartConvCmd(ADC1,ENABLE);

}

voidUSART1_Config(void)

{

USART_InitTypeDefUSART_InitStructure;

USART_InitStructure.USART_BaudRate=9600;

USART_InitStructure.USART_WordLength=USART_WordLength_8b;

USART_InitStructure.USART_StopBits=USART_StopBits_1;

USART_InitStructure.USART_Parity=USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;

USART_Init(USART1,&USART_InitStructure);

//USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//接收使能

//USART_ITConfig(USART1,USART_IT_TXE,ENABLE);//发送使能

USART_Cmd(USART1,ENABLE);//启动串口

}

staticuint8_tUSART_Scanf(uint32_tvalue)//字符串读取函数

{

uint32_tindex=0;

uint32_ttmp[2]={0,0};

while(index<2)

{

/*LoopuntilRXNE=1*/

while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET)

{

}

tmp[index++]=(USART_ReceiveData(USART1));

if((tmp[index-1]<0x30)||(tmp[index-1]>0x39))

{

printf("\n\r请输入有效数字0到9-->:

");

index--;

}

}

 

index=(tmp[1]-0x30)+((tmp[0]-0x30)*10);

/*Checks*/

if(index>value)

{

printf("\n\r请输入有效数字0到%d",value);

return0xFF;

}

returnindex;

}

 

voidTime_Regulate(rtc_time*tm)//时间设定函数

{

uint32_tTmp_HH=0xFF,Tmp_MI=0xFF,Tmp_SS=0xFF;

uint32_tTmp_up=0xff,Tmp_low=0xff;

printf("\r\n设定温度范围");

printf("\r\n输入温度上限:

");

while(Tmp_up==0xFF)

{

Tmp_up=USART_Scanf(99);

}

printf("\n\r温度上限为%0.2dC\n\r",Tmp_up);

upper_bound=Tmp_up;

//-------------------

printf("\r\n输入温度下限:

");

while(Tmp_low==0xFF)

{

Tmp_low=USART_Scanf(99);

}

printf("\n\r温度下限为%0.2dC\n\r",Tmp_low);

lower_bound=Tmp_low;

printf("\r\n设定时间");

Tmp_HH=0xFF;

printf("\r\n设定小时:

");

while(Tmp_HH==0xFF)

{

Tmp_HH=USART_Scanf(23);

}

printf("\n\r设定小时为%d\n\r",Tmp_HH);

tm->tm_hour=Tmp_HH;

Tmp_MI=0xFF;

printf("\r\n设定分钟:

");

while(Tmp_MI==0xFF)

{

Tmp_MI=USART_Scanf(59);

}

printf("\n\r设定分钟为%d\n\r",Tmp_MI);

tm->tm_min=Tmp_MI;

Tmp_SS=0xFF;

printf("\r\n设定秒:

");

while(Tmp_SS==0xFF)

{

Tmp_SS=USART_Scanf(59);

}

printf("\n\r设定秒为%d\n\r",Tmp_SS);

tm->tm_sec=Tmp_SS;

}

intfputc(intch,FILE*f)//重定向函数

{

USART_SendData(USART1,(unsignedchar)ch);

//while(!

(USART1->SR&USART_FLAG_TXE));

while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!

=SET);

return(ch);

}

/*****************************主函数***********************************************/

intmain(void)

{

#ifdefDEBUG

#endif

SysTick_Init();

LED_GPIO_Config();

RCC_Config();

GPIO_Config();

DMA_Config();

ADC1_Config();

USART1_Config();

Delay(5000);

Time_Regulate(&systmtime);

GPIO_SetBits(GPIOD,GPIO_Pin_8);

GPIO_SetBits(GPIOD,GPIO_Pin_9);

GPIO_SetBits(GPIOD,GPIO_Pin_10);

GPIO_SetBits(GPIOD,GPIO_Pin_11);

sec=systmtime.tm_sec;

min=systmtime.tm_min;

hour=systmtime.tm_hour;

while

(1)

{

sec++;

if(sec==60)

{sec=0;min++;

if(min==60)

{

min=0;hour++;

if(hour==24)

{

hour=0;

}

}

}

printf("\r\n当前时间:

%d:

%d:

%d\r\n",hour,min,sec);

printf("\r\n当前温度:

%02dC温度上限:

%02dC温度下限:

%02dC\r\n",Average_Temp,upper_bound,lower_bound);

GPIO_SetBits(GPIOD,GPIO_Pin_8);

GPIO_SetBits(GPIOD,GPIO_Pin_9);

GPIO_SetBits(GPIOD,GPIO_Pin_10);

GPIO_SetBits(GPIOD,GPIO_Pin_11);

if(((int)Current_Temp)>((int)upper_bound))

{

GPIO_ResetBits(GPIOD,GPIO_Pin_8);

}

elseif(((int)Current_Temp)<((int)lower_bound))

{

GPIO_ResetBits(GPIOD,GPIO_Pin_11);

}

else{

GPIO_SetBits(GPIOD,GPIO_Pin_8);

GPIO_SetBits(GPIOD,GPIO_Pin_9);

GPIO_SetBits(GPIOD,GPIO_Pin_10);

GPIO_SetBits(GPIOD,GPIO_Pin_11);}

Delay_ms(1000);

}

}

 

stm32f10x_it.c文件:

/*Includes------------------------------------------------------------------*/

#include"stm32f10x_it.h"

/*Privatefunctions---------------------------------------------------------*/

voiddisplay(void)

{

unsignedcharad_data,ad_value_max,ad_value_min;

ad_data=Current_

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工作范文 > 行政公文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1