基于STM32单片机助眠机器人设计_第1页
基于STM32单片机助眠机器人设计_第2页
基于STM32单片机助眠机器人设计_第3页
基于STM32单片机助眠机器人设计_第4页
基于STM32单片机助眠机器人设计_第5页
已阅读5页,还剩45页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

当今社会正有越来越多的人被不同的睡眠问题所困扰着,2020年我国首次引入大数据对睡眠问题进行分析,分析结果显示我国平均睡眠时长为6.92小时,普遍入睡时间为深夜23点-24点之间。时至2022年《中国睡眠报告》调查显示,国民平均睡眠时长为7.4小时,近半数(47.55%)的民众睡眠时长不足8小时,16.79%的民众睡眠时长不足7小时,虽然和2020年相比民众睡眠有所改善但仍然有待提高。STMF103C8T6实物图功能介绍在确定STM32F103单片机休眠环境监控系统的硬件电路板焊接无误后,随其进行了实验。首先对MCU进行供电,初始化了LCD1602液晶显示屏以及ESP8266无线网络接口模块。在完成初始化工作后,对STM32F103单片机休眠环境监控系统中各传感器的功能进行了测试。参考文献DetectionandMonitoring[J].Sensors,2018,18(2).[27]

#include"delay.h"#include"sys.h"#include"usart.h"#include"SGP30.h"#include"beep.h"#include"oled_iic.h"#include"lux.h"#include"dht11.h"#include"key.h"#include"pulse.h"externintIBI;externintBPM;externintSignal;externunsignedcharQS;intyuzhi1=60;voiddisplay(void){OLED_ShowChar(0,0,'T');OLED_ShowChar(10,0,':');OLED_ShowChar(0,2,'S');OLED_ShowChar(10,2,':');OLED_ShowChar(0,4,'B'); OLED_ShowChar(10,4,'P'); OLED_ShowChar(20,4,'M'); OLED_ShowChar(30,4,':');/*OLED_ShowChar(60,4,'c');OLED_ShowChar(70,4,'/');OLED_ShowChar(80,4,'m');OLED_ShowChar(90,4,'i');OLED_ShowChar(100,4,'n');*/OLED_ShowChar(40,0,'C');OLED_ShowChar(40,2,'%'); OLED_ShowChar(0,6,'y');OLED_ShowChar(10,6,'u');OLED_ShowChar(20,6,'z');OLED_ShowChar(30,6,'h');OLED_ShowChar(40,6,'i');OLED_ShowChar(50,6,':');}intmain(void){ vu8key=0; u8Temperature,HUM; u16test_adc1,LUX; delay_init(); KEY_Init(); ADC1_Init(); BEEP_Init(); RELAY1_Init(); RELAY2_Init(); LED_Init(); TIM3_Init(71,2000); PWM_Init(7199,0); DHT11_Init(); OLED_Init(); OLED_Clear(); TIM3->CR1|=1<<0; OLED_ShowNum(60,6,yuzhi1,3 ,16); while(1) { display(); key=KEY_Scan(0); if(key) { switch(key) { caseKEY0_DOWN: if(yuzhi1==1) yuzhi1=1;elseyuzhi1=yuzhi1-1; OLED_ShowNum(60,6,yuzhi1,3,16); break; caseKEY1_DOWN: if(yuzhi1==100) yuzhi1=100;elseyuzhi1=yuzhi1+1; OLED_ShowNum(60,6,yuzhi1,3,16); break; }} DHT11_Read_Data(&Temperature,&HUM);//¶ÁÈ¡ÎÂʪ¶ÈÖµ OLED_ShowNum(20,0,Temperature,2,16); OLED_ShowNum(20,2,HUM,2,16); if(QS==1) { OLED_ShowNum(40,4,BPM,3,16); if(BPM<yuzhi1) { LED=0; RD=0; LD=1; PWMA=3600; } else { LED=1; RD=1; LD=0; PWMA=0; } QS=0; } delay_ms(20); } }#include"delay.h"staticu8fac_us=0; staticu16fac_ms=0; #ifSYSTEM_SUPPORT_OS systick#ifdef OS_CRITICAL_METHOD #definedelay_osrunning OSRunning #definedelay_ostickspersec OS_TICKS_PER_SEC#definedelay_osintnesting OSIntNesting #endif#ifdef CPU_CFG_CRITICAL_METHOD #definedelay_osrunning OSRunning #definedelay_ostickspersec OSCfg_TickRate_Hz #definedelay_osintnesting OSIntNestingCtr #endifvoiddelay_osschedlock(void){#ifdefCPU_CFG_CRITICAL_METHOD OS_ERRerr; OSSchedLock(&err); #else OSSchedLock(); #endif}voiddelay_osschedunlock(void){ #ifdefCPU_CFG_CRITICAL_METHOD OS_ERRerr; OSSchedUnlock(&err); #else OSSchedUnlock(); #endif}voiddelay_ostimedly(u32ticks){#ifdefCPU_CFG_CRITICAL_METHOD OS_ERRerr; OSTimeDly(ticks,OS_OPT_TIME_PERIODIC,&err); OSTimeDly(ticks); #endif}voidSysTick_Handler(void){ if(delay_osrunning==1) { OSIntEnter(); OSTimeTick(); OSIntExit(); }}#endif voiddelay_init(){#ifSYSTEM_SUPPORT_OS u32reload;#endif SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); fac_us=SystemCoreClock/8000000; #ifSYSTEM_SUPPORT_OS reload=SystemCoreClock/8000000; reload*=1000000/delay_ostickspersec; fac_ms=1000/delay_ostickspersec; SysTick->CTRL|=SysTick_CTRL_TICKINT_Msk; SysTick->LOAD=reload; SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;#else fac_ms=(u16)fac_us*1000; #endif} #ifSYSTEM_SUPPORT_OS voiddelay_us(u32nus){ u32ticks; u32told,tnow,tcnt=0; u32reload=SysTick->LOAD; ticks=nus*fac_us; tcnt=0; delay_osschedlock(); told=SysTick->VAL; while(1) { tnow=SysTick->VAL; if(tnow!=told) { if(tnow<told)tcnt+=told-tnow; elsetcnt+=reload-tnow+told; told=tnow; if(tcnt>=ticks)break; } }; delay_osschedunlock(); }voiddelay_ms(u16nms){ if(delay_osrunning&&delay_osintnesting==0) { if(nms>=fac_ms) { delay_ostimedly(nms/fac_ms); } nms%=fac_ms; } delay_us((u32)(nms*1000)); } voiddelay_us(u32nus){ u32temp; SysTick->LOAD=nus*fac_us; SysTick->VAL=0x00; SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; do { temp=SysTick->CTRL; }while((temp&0x01)&&!(temp&(1<<16))); SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; SysTick->VAL=0X00; ÷ }voiddelay_ms(u16nms){ u32temp; SysTick->LOAD=(u32)nms*fac_ms; SysTick->VAL=0x00; SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; //¿ªÊ¼µ¹Êý do { temp=SysTick->CTRL; }while((temp&0x01)&&!(temp&(1<<16))); SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; SysTick->VAL=0X00; }#endif;Amountofmemory(inbytes)allocatedforStack;Tailorthisvaluetoyourapplicationneeds;<h>StackConfiguration;<o>StackSize(inBytes)<0x0-0xFFFFFFFF:8>;</h>Stack_SizeEQU0x00000400AREASTACK,NOINIT,READWRITE,ALIGN=3Stack_MemSPACEStack_Size__initial_sp;<h>HeapConfiguration;<o>HeapSize(inBytes)<0x0-0xFFFFFFFF:8>;</h>Heap_SizeEQU0x00000200AREAHEAP,NOINIT,READWRITE,ALIGN=3__heap_baseHeap_MemSPACEHeap_Size__heap_limitPRESERVE8THUMB;VectorTableMappedtoAddress0atResetAREARESET,DATA,READONLYEXPORT__VectorsEXPORT__Vectors_EndEXPORT__Vectors_Size__VectorsDCD__initial_sp;TopofStackDCDReset_Handler;ResetHandlerDCDNMI_Handler;NMIHandlerDCDHardFault_Handler;HardFaultHandlerDCDMemManage_Handler;MPUFaultHandlerDCDBusFault_Handler;BusFaultHandlerDCDUsageFault_Handler;UsageFaultHandlerDCD0;ReservedDCD0;ReservedDCD0;ReservedDCD0;ReservedDCDSVC_Handler;SVCallHandlerDCDDebugMon_Handler;DebugMonitorHandlerDCD0;ReservedDCDPendSV_Handler;PendSVHandlerDCDSysTick_Handler;SysTickHandler;ExternalInterruptsDCDWWDG_IRQHandler;WindowWatchdogDCDPVD_IRQHandler;PVDthroughEXTILinedetectDCDTAMPER_IRQHandler;TamperDCDRTC_IRQHandler;RTCDCDFLASH_IRQHandler;FlashDCDRCC_IRQHandler;RCCDCDEXTI0_IRQHandler;EXTILine0DCDEXTI1_IRQHandler;EXTILine1DCDEXTI2_IRQHandler;EXTILine2DCDEXTI3_IRQHandler;EXTILine3DCDEXTI4_IRQHandler;EXTILine4DCDDMA1_Channel1_IRQHandler;DMA1Channel1DCDDMA1_Channel2_IRQHandler;DMA1Channel2DCDDMA1_Channel3_IRQHandler;DMA1Channel3DCDDMA1_Channel4_IRQHandler;DMA1Channel4DCDDMA1_Channel5_IRQHandler;DMA1Channel5DCDDMA1_Channel6_IRQHandler;DMA1Channel6DCDDMA1_Channel7_IRQHandler;DMA1Channel7DCDADC1_2_IRQHandler;ADC1&ADC2DCDUSB_HP_CAN1_TX_IRQHandler;USBHighPriorityorCAN1TXDCDUSB_LP_CAN1_RX0_IRQHandler;USBLowPriorityorCAN1RX0DCDCAN1_RX1_IRQHandler;CAN1RX1DCDCAN1_SCE_IRQHandler;CAN1SCEDCDEXTI9_5_IRQHandler;EXTILine9..5DCDTIM1_BRK_IRQHandler;TIM1BreakDCDTIM1_UP_IRQHandler;TIM1UpdateDCDTIM1_TRG_COM_IRQHandler;TIM1TriggerandCommutationDCDTIM1_CC_IRQHandler;TIM1CaptureCompareDCDTIM2_IRQHandler;TIM2DCDTIM3_IRQHandler;TIM3DCDTIM4_IRQHandler;TIM4DCDI2C1_EV_IRQHandler;I2C1EventDCDI2C1_ER_IRQHandler;I2C1ErrorDCDI2C2_EV_IRQHandler;I2C2EventDCDI2C2_ER_IRQHandler;I2C2ErrorDCDSPI1_IRQHandler;SPI1DCDSPI2_IRQHandler;SPI2DCDUSART1_IRQHandler;USART1DCDUSART2_IRQHandler;USART2DCDUSART3_IRQHandler;USART3DCDEXTI15_10_IRQHandler;EXTILine15..10DCDRTCAlarm_IRQHandler;RTCAlarmthroughEXTILineDCDUSBWakeUp_IRQHandler;USBWakeupfromsuspendDCDTIM8_BRK_IRQHandler;TIM8BreakDCDTIM8_UP_IRQHandler;TIM8UpdateDCDTIM8_TRG_COM_IRQHandler;TIM8TriggerandCommutationDCDTIM8_CC_IRQHandler;TIM8CaptureCompareDCDADC3_IRQHandler;ADC3DCDFSMC_IRQHandler;FSMCDCDSDIO_IRQHandler;SDIODCDTIM5_IRQHandler;TIM5DCDSPI3_IRQHandler;SPI3DCDUART4_IRQHandler;UART4DCDUART5_IRQHandler;UART5DCDTIM6_IRQHandler;TIM6DCDTIM7_IRQHandler;TIM7DCDDMA2_Channel1_IRQHandler;DMA2Channel1DCDDMA2_Channel2_IRQHandler;DMA2Channel2DCDDMA2_Channel3_IRQHandler;DMA2Channel3DCDDMA2_Channel4_5_IRQHandler;DMA2Channel4&Channel5__Vectors_End__Vectors_SizeEQU__Vectors_End-__VectorsAREA|.text|,CODE,READONLY;ResethandlerReset_HandlerPROCEXPORTReset_Handler[WEAK]IMPORT__mainIMPORTSystemInitLDRR0,=SystemInitBLXR0LDRR0,=__mainBXR0ENDP;DummyExceptionHandlers(infiniteloopswhichcanbemodified)NMI_HandlerPROCEXPORTNMI_Handler[WEAK]B.ENDPHardFault_Handler\PROCEXPORTHardFault_Handler[WEAK]B.ENDPMemManage_Handler\PROCEXPORTMemManage_Handler[WEAK]B.ENDPBusFault_Handler\PROCEXPORTBusFault_Handler[WEAK]B.ENDPUsageFault_Handler\PROCEXPORTUsageFault_Handler[WEAK]B.ENDPSVC_HandlerPROCEXPORTSVC_Handler[WEAK]B.ENDPDebugMon_Handler\PROCEXPORTDebugMon_Handler[WEAK]B.ENDPPendSV_HandlerPROCEXPORTPendSV_Handler[WEAK]B.ENDPSysTick_HandlerPROCEXPORTSysTick_Handler[WEAK]B.ENDPDefault_HandlerPROCEXPORTWWDG_IRQHandler[WEAK]EXPORTPVD_IRQHandler[WEAK]EXPORTTAMPER_IRQHandler[WEAK]EXPORTRTC_IRQHandler[WEAK]EXPORTFLASH_IRQHandler[WEAK]EXPORTRCC_IRQHandler[WEAK]EXPORTEXTI0_IRQHandler[WEAK]EXPORTEXTI1_IRQHandler[WEAK]EXPORTEXTI2_IRQHandler[WEAK]EXPORTEXTI3_IRQHandler[WEAK]EXPORTEXTI4_IRQHandler[WEAK]EXPORTDMA1_Channel1_IRQHandler[WEAK]EXPORTDMA1_Channel2_IRQHandler[WEAK]EXPORTDMA1_Channel3_IRQHandler[WEAK]EXPORTDMA1_Channel4_IRQHandler[WEAK]EXPORTDMA1_Channel5_IRQHandler[WEAK]EXPORTDMA1_Channel6_IRQHandler[WEAK]EXPORTDMA1_Channel7_IRQHandler[WEAK]EXPORTADC1_2_IRQHandler[WEAK]EXPORTUSB_HP_CAN1_TX_IRQHandler[WEAK]EXPORTUSB_LP_CAN1_RX0_IRQHandler[WEAK]EXPORTCAN1_RX1_IRQHandler[WEAK]EXPORTCAN1_SCE_IRQHandler[WEAK]EXPORTEXTI9_5_IRQHandler[WEAK]EXPORTTIM1_BRK_IRQHandler[WEAK]EXPORTTIM1_UP_IRQHandler[WEAK]EXPORTTIM1_TRG_COM_IRQHandler[WEAK]EXPORTTIM1_CC_IRQHandler[WEAK]EXPORTTIM2_IRQHandler[WEAK]EXPORTTIM3_IRQHandler[WEAK]EXPORTTIM4_IRQHandler[WEAK]EXPORTI2C1_EV_IRQHandler[WEAK]EXPORTI2C1_ER_IRQHandler[WEAK]EXPORTI2C2_EV_IRQHandler[WEAK]EXPORTI2C2_ER_IRQHandler[WEAK]EXPORTSPI1_IRQHandler[WEAK]EXPORTSPI2_IRQHandler[WEAK]EXPORTUSART1_IRQHandler[WEAK]EXPORTUSART2_IRQHandler[WEAK]EXPORTUSART3_IRQHandler[WEAK]EXPORTEXTI15_10_IRQHandler[WEAK]EXPORTRTCAlarm_IRQHandler[WEAK]EXPORTUSBWakeUp_IRQHandler[WEAK]EXPORTTIM8_BRK_IRQHandler[WEAK]EXPORTTIM8_UP_IRQHandler[WEAK]EXPORTTIM8_TRG_COM_IRQHandler[WEAK]EXPORTTIM8_CC_IRQHandler[WEAK]EXPORTADC3_IRQHandler[WEAK]EXPORTFSMC_IRQHandler[WEAK]EXPORTSDIO_IRQHandler[WEAK]EXPORTTIM5_IRQHandler[WEAK]EXPORTSPI3_IRQHandler[WEAK]EXPORTUART4_IRQHandler[WEAK]EXPORTUART5_IRQHandler[WEAK]EXPORTTIM6_IRQHandler[WEAK]EXPORTTIM7_IRQHandler[WEAK]EXPORTDMA2_Channel1_IRQHandler[WEAK]EXPORTDMA2_Channel2_IRQHandler[WEAK]EXPORTDMA2_Channel3_IRQHandler[WEAK]EXPO

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论