完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
设计介绍
这是一个简单的故障设计检测的,使用到模块的有STM32C8T6,LCD1602液晶显示器,显示的检测以及设置的阈值,阈值可以通过设置,当测得的阈值超过阈值时,蜂鸣会报警,以及一个心率传感器需要参考的朋友可以在文章底部点击下载源码和原理图。 main.c中中的代码如下: #include "main.h" #include "stm32f1xx_hal.h" #include "rtc.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* USER CODE BEGIN Includes */ #include "LCD1602.h" #include "MEMORY.h" /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ extern void RTC_CalendarShow(void); void police_dispose(void); void display(void); void key_scan(void); extern unsigned int xinlv; void dis_play(void); extern void Sensor(void); char Read_ADC=0; uint16_t ADC_Dat=0; uint8_t key1_flag = 0,key2_flag = 0,key3_flag = 0; uint8_t sec1=0,sec2=0,memory_flag=0; static uint8_t state=0; uint8_t s0,HH,LL; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Error_Handler(void); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ #define key1 HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0) #define key2 HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1) #define key3 HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_10) #define beep_write_0 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_RESET) #define beep_write_1 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_SET) #define led1_0 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_RESET) #define led1_1 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_SET) #define led2_0 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_RESET) #define led2_1 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_SET) /* USER CODE END 0 */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_RTC_Init(); MX_USART1_UART_Init(); MX_TIM3_Init(); MX_TIM2_Init(); /* USER CODE BEGIN 2 */ HAL_Delay(20); LCD1602_cls(); HAL_TIM_Base_Start_IT(&htim3); //启动定时器 //HAL_TIM_Base_Start_IT(&htim2); led2_0; // Write_flsh_byte(0x08009000,153); // Write_flsh_byte(0x0800A000,41); // read_memory();//flash初始化 HH= readFlash(0x08009000); LL= readFlash(0x0800A000); printf("before %d%d",HH,LL); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ police_dispose(); display(); if(memory_flag) { memory_flag=0; Write_flsh_byte(0x08009000,HH); Write_flsh_byte(0x0800A000,LL); } /* USER CODE END 3 */ } } /** System Clock Configuration */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit; /**Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE |RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.LSEState = RCC_LSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /**Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC; PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } /**Enables the Clock Security System */ HAL_RCC_EnableCSS(); /**Configure the Systick interrupt time */ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); /**Configure the Systick */ HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); /* SysTick_IRQn interrupt configuration */ HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); } /* USER CODE BEGIN 4 */ void display(void) { RTC_CalendarShow();// 第一行显示 LCD1602_write(0,0xC0);//第一行显示 if(state==1&&s0) { LCD1602_writebyte((unsigned char *)"High:"); LCD1602_writebyte((unsigned char *)" "); LCD1602_writebyte((unsigned char *)"Low:"); LCD1602_write(1,0x30+LL/100%10); LCD1602_write(1,0x30+LL/10%10); LCD1602_write(1,0x30+LL%10); } else if(state==2&&s0) { LCD1602_writebyte((unsigned char *)"High:"); LCD1602_write(1,0x30+HH/100%10); LCD1602_write(1,0x30+HH/10%10); LCD1602_write(1,0x30+HH%10); LCD1602_writebyte((unsigned char *)" "); LCD1602_writebyte((unsigned char *)"Low:"); LCD1602_writebyte((unsigned char *)" "); } else { LCD1602_writebyte((unsigned char *)"High:"); LCD1602_write(1,0x30+HH/100%10); LCD1602_write(1,0x30+HH/10%10); LCD1602_write(1,0x30+HH%10); LCD1602_writebyte((unsigned char *)" "); LCD1602_writebyte((unsigned char *)"Low:"); LCD1602_write(1,0x30+LL/100%10); LCD1602_write(1,0x30+LL/10%10); LCD1602_write(1,0x30+LL%10); } } void police_dispose(void) { if(xinlv>HH||((xinlv HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0); HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_11); HAL_Delay(500); } else { led1_1; beep_write_0; } } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1777 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1621 浏览 1 评论
1080 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
728 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1678 浏览 2 评论
1938浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
731浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
570浏览 3评论
595浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
554浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 04:34 , Processed in 0.828121 second(s), Total 76, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号