STM32杂交版(HAL库、音乐盒、闹钟、点阵屏、温湿度)

一、设计描述        

        本设计精心构建了一个以STM32MP157A高性能单片机为核心控制单元的综合性嵌入式系统。该系统巧妙融合了蜂鸣器、数码管显示器、点阵屏、温湿度传感器、LED指示灯以及按键等多种外设模块,形成了一个功能丰富、操作便捷的杂交版智能设备。通过串口通信,用户可以灵活地切换系统的工作模式,轻松实现闹钟、音乐盒播放及温湿度监测与调控等基本功能。

核心硬件

  • 主控单元:采用STM32MP157A单片机,凭借其强大的处理能力和丰富的外设接口,为系统提供了坚实的硬件基础。

软件平台

  • 开发工具:利用STM32CUBEIDE这一直观易用的集成开发环境,极大地提升了软件编程与调试的效率,确保了系统软件的稳定可靠。

系统功能亮点

  1. 模式灵活切换:通过串口通信,用户可以轻松地在闹钟、音乐盒播放及温湿度监测三种模式之间自由切换,满足不同场景下的使用需求。

  2. 动态信息显示:点阵屏作为系统的信息展示窗口,能够根据当前的工作模式显示相应的汉字(如“钟”代表闹钟模式,“音”代表音乐盒模式,“传”可视为温湿度监测的简化标识),为用户提供了直观的操作反馈。

  3. 按键交互体验:设计中充分考虑了用户的交互体验,通过按键即可在各模式下执行对应的功能操作,如音乐盒的速度与音量调节、歌曲切换、暂停/播放控制,以及闹钟的时间调整、设置多个闹钟、关闭闹钟等。

  4. 温湿度智能调控:系统内置温湿度传感器,能够实时监测环境状况,并通过串口接收用户指令调节温湿度的上下限阈值。一旦环境参数超出设定范围,LED指示灯将亮起作为边界提示,帮助用户及时采取措施。

二、基本配置信息

         音乐盒在之前做过所以配置不做改变:STM32音乐盒

        

三、STM32CUBEIDE配置

1、定时器--100ms

2、PWM配置(蜂鸣器 -- PB6)

3. 串口配置

注意针脚

4. IIC配置(温湿度,数码管,点阵屏)

5. GPIO配置(LED和按键)

6. NVIC

四、程序编写

(1)音乐盒代码

        音乐盒在之前已经写过,所以这里不再重复之前的操作,我们将串口和模式转换加进去。

         STM32音乐盒

        串口音乐控制函数


//串口音乐控制函数
void music_kz(){if(EN_music == 1)//启动play_music(list,Low_volume);else__HAL_TIM_SET_COMPARE(&htim4,TIM_CHANNEL_1,0);//设置音量if(strcmp("music volume increase",(char *)uart4_data)==0){uart4_data[0] = '0';Low_volume = Low_volume + Low_volume_cnt;if(Low_volume >= 10)Low_volume = 10;}if(strcmp("music volume reduction",(char *)uart4_data)==0){Low_volume = Low_volume - Low_volume_cnt;if(Low_volume <= 0)Low_volume = 0;}if(strcmp("music speed increase",(char *)uart4_data)==0){uart4_data[0] = '0';music_speed_i++;music_speed_i = music_speed_kz(music_speed_i);}if(strcmp("music speed reduction",(char *)uart4_data)==0){uart4_data[0] = '0';music_speed_i--;music_speed_i = music_speed_kz(music_speed_i);}if(strcmp("music next song",(char *)uart4_data)==0){uart4_data[0] = '0';list++;if(list > list_max){list = list_max;}}if(strcmp("music previous song",(char *)uart4_data)==0){list--;uart4_data[0] = '0';if(list < 0){list = 0;}}if(strcmp("music start",(char *)uart4_data)==0){EN_music = 1;}if(strcmp("music stop",(char *)uart4_data)==0){EN_music = 0;}}

按键模式控制

用mode变量代表模式,后面三个按键同理。


void EXTI0_IRQHandler(void)
{/* USER CODE BEGIN EXTI0_IRQn 0 */if(HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_0) == 0 && mode == 0)//确保数据稳定{//每次按下解决 音量�??????? Low_volume_cntLow_volume = Low_volume + Low_volume_cnt;if(Low_volume >= 10)Low_volume = 0;}if(HAL_GPIO_ReadPin(GPIOG,GPIO_PIN_0)==GPIO_PIN_RESET && mode == 1) {shi_clock++;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;if(shi_clock>=24){shi_clock=0;}miao_shi_clock=miao_clock/10;miao_ge_clock=miao_clock%10;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;buf[0]=smg_number[shi_shi_clock];buf[1]=smg_number[shi_ge_clock];buf[3]=smg_number[fen_shi_clock];buf[4]=smg_number[fen_ge_clock];buf[6]=smg_number[miao_shi_clock];buf[7]=smg_number[miao_ge_clock];}/* USER CODE END EXTI0_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);/* USER CODE BEGIN EXTI0_IRQn 1 *//* USER CODE END EXTI0_IRQn 1 */
}

(2)模式切换

        mode变量切换


void uart_mode(){if(strcmp("mode = music",(char *)uart4_data)==0){mode = 0;}if(strcmp("mode = clock",(char *)uart4_data)==0){mode = 1;}if(strcmp("mode = sensor",(char *)uart4_data)==0){mode = 2;}
}

点阵屏字库


uint8_t DZP_data[6][34]={{0xAA,0x55,0xFD,0xFF,0xFE,0xFF,0xC0,0x07,0xFF,0xFF,0xF7,0xDF,0xFB,0xBF,0x00,0x01,0xFF,0xFF,0xE0,0x0F,0xEF,0xEF,0xEF,0xEF,0xE0,0x0F,0xEF,0xEF,0xEF,0xEF,0xE0,0x0F,0xEF,0xEF},//音{0xAA,0x55,0xEF,0xDF,0xEF,0xDF,0xC3,0xDF,0xDF,0xDF,0xBE,0x03,0x42,0xDB,0xEE,0xDB,0xEE,0xDB,0x02,0xDB,0xEE,0x03,0xEE,0xDB,0xEF,0xDF,0xEB,0xDF,0xE7,0xDF,0xEF,0xDF,0xFF,0xDF},//钟//1//{0xAA,0x55,0xF7,0xBF,0xF7,0xBF,0xF7,0xBF,0xEC,0x07,0xEF,0xBF,0xCF,0x7F,0xC8,0x01,0xAF,0x7F,0x6E,0xFF,0xEC,0x07,0xEF,0xF7,0xEE,0xEF,0xEF,0x5F,0xEF,0xBF,0xEF,0xDF,0xEF,0xDF}//传//2//};

点阵屏显示

		if(mode_n != mode){mode_n = mode;for(int i = 0; i<34;i++){//printf("afgsbgafdffag");HAL_I2C_Master_Transmit(&hi2c1, 0xA0 , (uint8_t*)&DZP_data[mode][i], 1, 300);HAL_Delay(2);}}

(3)闹钟代码编写

        1. 基础变量

         main.c


//数码管闹钟基础变量
extern int buf[8];
extern int shi_shi;
extern int shi_ge ;
extern int fen_shi;
extern int fen_ge ;
extern int miao_shi ;
extern int miao_ge ;extern int miao ;
extern int shi ;
extern int fen;
//闹钟保存数组
extern int alarm_clock_array[20][4];
extern int alarm_clock_array_cnt;

        stm32mp1xx_it.c 基础变量

//数码管闹钟基础设置
int smg_number[10] = {0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xE0,0xFE,0xF6};
int buf[8] = {0};//闹钟保存数组
int alarm_clock_array[20][4] = {0};
int alarm_clock_array_cnt = 0;
//实时时钟信息
int shi_shi = 0;
int shi_ge = 0;
int fen_shi = 0;
int fen_ge = 0;
int miao_shi = 0;
int miao_ge = 0;
int miao = 0;
int shi = 0;
int fen = 0;int EN_clock = 0;//闹钟设置使能
extern int en_clock;//用于控制闹钟响铃//闹钟设置信息
int shi_shi_clock = 0;
int shi_ge_clock = 0;
int fen_shi_clock = 0;
int fen_ge_clock = 0;
int miao_shi_clock = 0;
int miao_ge_clock = 0;
int miao_clock = 0, shi_clock = 0, fen_clock = 0;

        2. TIM2定时器


void TIM2_IRQHandler(void)
{/* USER CODE BEGIN TIM2_IRQn 0 */if(EN_music == 1)time_100ms_cnt++;elsetime_100ms_cnt = time_100ms_cnt;	//其余状�?�不计数if(time_100ms_cnt >= Beat_speed_n * Beat_num){	//这个音节结束time_100ms_cnt = 0;flag = 1;	//发�?�音节结束信�???????}//数码�????static int smg_time_100ms = 0;smg_time_100ms++;if(smg_time_100ms>=10){miao++;smg_time_100ms = 0;}if (miao>=60){miao=0;fen++;if(fen>=60){fen=0;shi++;if(shi>=24){shi=0;}}}if(miao >= 60){miao = miao-60;fen++;}if(fen>=60){fen = fen-60;shi ++;}if(shi>= 24){shi = shi -24;}miao_shi=miao/10;miao_ge=miao%10;fen_shi=fen/10;fen_ge=fen%10;shi_shi=shi/10;shi_ge=shi%10;if(EN_clock == 0){buf[0]=smg_number[shi_shi];buf[1]=smg_number[shi_ge];buf[3]=smg_number[fen_shi];buf[4]=smg_number[fen_ge];buf[6]=smg_number[miao_shi];buf[7]=smg_number[miao_ge];HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_RESET);//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);//HAL_GPIO_WritePin(GPIOI, GPIO_PIN_11|GPIO_PIN_10, GPIO_PIN_RESET);}else{HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_SET);//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);//HAL_GPIO_WritePin(GPIOI, GPIO_PIN_11|GPIO_PIN_10, GPIO_PIN_SET);}/* USER CODE END TIM2_IRQn 0 */HAL_TIM_IRQHandler(&htim2);/* USER CODE BEGIN TIM2_IRQn 1 *//* USER CODE END TIM2_IRQn 1 */
}

        3. 按键控制设置闹钟和保存闹钟        


void EXTI9_IRQHandler(void)
{/* USER CODE BEGIN EXTI9_IRQn 0 */if(HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_9) == 0 && mode == 0){//确保数据稳定EN_music = !EN_music;}if(HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_9) == 0 && mode == 1 ){//确保数据稳定if(EN_clock == 1){//闹钟设置成功alarm_clock_array[alarm_clock_array_cnt][0] = shi_clock;alarm_clock_array[alarm_clock_array_cnt][1] = fen_clock;alarm_clock_array[alarm_clock_array_cnt][2] = miao_clock;alarm_clock_array[alarm_clock_array_cnt][3] = 3;	//默认播放第三首音�????alarm_clock_array_cnt++;if(alarm_clock_array_cnt >= 20) alarm_clock_array_cnt = 0;EN_clock = 0;}else if(EN_clock == 0){//设置闹钟shi_shi_clock = shi_shi;shi_ge_clock = shi_ge;fen_shi_clock = fen_shi;fen_ge_clock = fen_ge;miao_shi_clock = 0;miao_ge_clock = 0;miao_clock = 0;shi_clock = shi;fen_clock = fen;EN_clock = 1;}}/* USER CODE END EXTI9_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);/* USER CODE BEGIN EXTI9_IRQn 1 *//* USER CODE END EXTI9_IRQn 1 */
}

        4. 时分按键+


void EXTI0_IRQHandler(void)
{/* USER CODE BEGIN EXTI0_IRQn 0 */if(HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_0) == 0 && mode == 0)//确保数据稳定{//每次按下解决 音量�??????? Low_volume_cntLow_volume = Low_volume + Low_volume_cnt;if(Low_volume >= 10)Low_volume = 0;}if(HAL_GPIO_ReadPin(GPIOG,GPIO_PIN_0)==GPIO_PIN_RESET && mode == 1) {shi_clock++;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;if(shi_clock>=24){shi_clock=0;}miao_shi_clock=miao_clock/10;miao_ge_clock=miao_clock%10;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;buf[0]=smg_number[shi_shi_clock];buf[1]=smg_number[shi_ge_clock];buf[3]=smg_number[fen_shi_clock];buf[4]=smg_number[fen_ge_clock];buf[6]=smg_number[miao_shi_clock];buf[7]=smg_number[miao_ge_clock];}/* USER CODE END EXTI0_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);/* USER CODE BEGIN EXTI0_IRQn 1 *//* USER CODE END EXTI0_IRQn 1 */
}/*** @brief This function handles EXTI line1 interrupt.*/
void EXTI1_IRQHandler(void)
{/* USER CODE BEGIN EXTI1_IRQn 0 */if(HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_1) == 0 && mode == 0)//确保数据稳定{music_speed_i++;music_speed_i = music_speed_kz(music_speed_i);}if(HAL_GPIO_ReadPin(GPIOG,GPIO_PIN_1)==GPIO_PIN_RESET && mode == 1) {fen_clock++;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;if(fen_clock>=60){fen_clock=0;shi_clock++;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;if(shi_clock>=24){shi_clock=0;}}miao_shi_clock=miao_clock/10;miao_ge_clock=miao_clock%10;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;buf[0]=smg_number[shi_shi_clock];buf[1]=smg_number[shi_ge_clock];buf[3]=smg_number[fen_shi_clock];buf[4]=smg_number[fen_ge_clock];buf[6]=smg_number[miao_shi_clock];buf[7]=smg_number[miao_ge_clock];}/* USER CODE END EXTI1_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);/* USER CODE BEGIN EXTI1_IRQn 1 *//* USER CODE END EXTI1_IRQn 1 */
}/*** @brief This function handles EXTI line2 interrupt.*/
void EXTI2_IRQHandler(void)
{/* USER CODE BEGIN EXTI2_IRQn 0 */if(HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_2) == 0 && mode == 0)//确保数据稳定{list++;if(list > list_max){list = 0;}}if(HAL_GPIO_ReadPin(GPIOG,GPIO_PIN_2)==GPIO_PIN_RESET && mode == 1) {//在此处关闭闹�????en_clock = 0;}/* USER CODE END EXTI2_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);/* USER CODE BEGIN EXTI2_IRQn 1 *//* USER CODE END EXTI2_IRQn 1 */
}

        5. 时钟相加函数(将后三的时分秒加入左三的对应时分秒)

//通过输入不同的n,返回shi fen miao
int clock_compute(int time_shi,int time_fen,int time_miao,int add_shi,int add_fen,int add_miao,int n){time_miao = time_miao + add_miao;time_fen = time_fen + time_miao/60;time_miao = time_miao % 60;time_fen = time_fen + add_fen;time_shi = time_shi + time_fen / 60;time_fen = time_fen%60;time_shi = time_shi + add_shi;time_shi = time_shi%24;if(n == 0) return time_shi;if(n == 1) return time_fen;if(n == 2) return time_miao;return -1;
}

        6. 提取对应字符串后两位数字


// 函数定义:从字符串中提取两位数字
int extract_two_digits(const char *str, const char *prefix, int *value) {char *pos = strstr(str, prefix); // 查找前缀的位�?????if (pos == NULL) return 0; // 如果没找到前�?????,返�?????0表示失败// 跳过前缀的长度,找到数字�?????始的位置pos += strlen(prefix);// �?????查接下来的两个字符是否是数字if (pos[0] >= '0' && pos[0] <= '9' && pos[1] >= '0' && pos[1] <= '9') {// 转换字符为数�?????*value = (pos[0] - '0') * 10 + (pos[1] - '0');return 1; // 成功提取,返�?????1}return 0; // 提取失败,返�?????0
}

        7. 串口设置目前时钟,定时闹钟,延时闹钟


//判断是否到底闹钟
int en_clock = 0;//用于控制闹钟响铃
int en_clock_cnt = 0;
int clock_end[3] = {0};//记录闹钟无人时关闭的时间
//串口设置闹钟
void uart_clock(){int ci = 0;int ci_n = 0;//ci = number_char_come(uart4_data,(uint8_t *)"clock shi = ",2);ci = extract_two_digits((char *)uart4_data, (char *)"clock shi = ", &ci_n);if(ci == 1){uart4_data[0] = '1';shi = ci_n;}//ci = number_char_come(uart4_data,(uint8_t *)"clock fen = ",2);ci = extract_two_digits((char *)uart4_data, (char *)"clock fen = ", &ci_n);if(ci == 1){uart4_data[0] = '1';fen = ci_n;}//ci = number_char_come(uart4_data,(uint8_t *)"clock miao = ",2);ci = extract_two_digits((char *)uart4_data, (char *)"clock miao = ", &ci_n);if(ci == 1){uart4_data[0] = '1';miao = ci_n;}//设置�?????个多少时间后的闹�?????//ci = number_char_come(uart4_data,(uint8_t *)"clock delay shi = ",2);ci = extract_two_digits((char *)uart4_data, "clock delay shi = ", &ci_n);if(ci == 1){uart4_data[0] = '1';alarm_clock_array[alarm_clock_array_cnt][0] = clock_compute(shi,fen,miao,ci_n,0,0,0);alarm_clock_array[alarm_clock_array_cnt][1] = clock_compute(shi,fen,miao,ci_n,0,0,1);alarm_clock_array[alarm_clock_array_cnt][2] = clock_compute(shi,fen,miao,ci_n,0,0,2);alarm_clock_array_cnt++;}//ci = number_char_come(uart4_data,(uint8_t *)"clock delay fen = ",2);ci = extract_two_digits((char *)uart4_data, "clock delay fen = ", &ci_n);if(ci == 1){uart4_data[0] = '1';alarm_clock_array[alarm_clock_array_cnt][0] = clock_compute(shi,fen,miao,0,ci_n,0,0);alarm_clock_array[alarm_clock_array_cnt][1] = clock_compute(shi,fen,miao,0,ci_n,0,1);alarm_clock_array[alarm_clock_array_cnt][2] = clock_compute(shi,fen,miao,0,ci_n,0,2);alarm_clock_array_cnt++;}ci = extract_two_digits((char *)uart4_data, "clock delay miao = ", &ci_n);if(ci == 1){uart4_data[0] = '1';alarm_clock_array[alarm_clock_array_cnt][0] = clock_compute(shi,fen,miao,0,0,ci_n,0);alarm_clock_array[alarm_clock_array_cnt][1] = clock_compute(shi,fen,miao,0,0,ci_n,1);alarm_clock_array[alarm_clock_array_cnt][2] = clock_compute(shi,fen,miao,0,0,ci_n,2);alarm_clock_array_cnt++;}// time shi = 12;fen = 10;miao = 12;music = 1;ci = 0;ci = ci + extract_two_digits((char *)uart4_data, "time shi = ", &alarm_clock_array[alarm_clock_array_cnt][0]);ci = ci + extract_two_digits((char *)uart4_data, ";fen = ", &alarm_clock_array[alarm_clock_array_cnt][1]);ci = ci + extract_two_digits((char *)uart4_data, ";miao = ", &alarm_clock_array[alarm_clock_array_cnt][2]);//ci = ci + extract_two_digits((char *)uart4_data, ";music = ", &alarm_clock_array[alarm_clock_array_cnt][2]);if(ci == 3){//完美对应uart4_data[0] = '1';ci = extract_two_digits((char *)uart4_data, ";music = ", &alarm_clock_array[alarm_clock_array_cnt][3]);if(ci > list_max && ci<0) //如果大于音乐总数alarm_clock_array[alarm_clock_array_cnt][3] = 3;//默认�?????3alarm_clock_array_cnt++;}if(strcmp("clock delay list",(char *)uart4_data)==0){uart4_data[0] = '0';for(int i = 0; i< alarm_clock_array_cnt;i++){if(alarm_clock_array[i][0] != -1 && alarm_clock_array[i][1] != -1 && alarm_clock_array[i][2] != -1)printf("%d : time -> %d/%d/%d  \r\n",i,	alarm_clock_array[i][0],alarm_clock_array[i][1],alarm_clock_array[i][2]);}}//读取关闭第几位闹�?????//ci = number_char_come(uart4_data,(uint8_t *)"clock stop list = ",2);ci = extract_two_digits((char *)uart4_data, "clock stop list = ", &ci_n);if(ci == 1){alarm_clock_array[ci_n][0] = -1;alarm_clock_array[ci_n][1] = -1;alarm_clock_array[ci_n][2] = -1;}//关闭闹钟if(strcmp("clock stop stop",(char *)uart4_data)==0){en_clock = 0;}if(alarm_clock_array_cnt >= 20) alarm_clock_array_cnt = 0;
}

        8. 闹钟实现和停止(数码管显示)


void alarm_clock(){//时钟显示(数码管)static int pos = 0;HAL_I2C_Mem_Write(&hi2c1,0x70,0X10+pos, 1, (uint8_t*)&buf[pos],1,100);HAL_Delay(1);pos++;if(pos == 3 && pos == 6) pos++;if(pos == 8) pos = 0;uart_clock();//调用串口控制for(int j=0;j<alarm_clock_array_cnt && en_clock == 0;j++){//int cnt_clock = 0;if(alarm_clock_array[j][0] == shi && alarm_clock_array[j][1] == fen && alarm_clock_array[j][2] == miao) {en_clock_cnt = j;en_clock = 1;clock_end[0] = clock_compute(shi,fen,miao,0,0,30,0);clock_end[1] = clock_compute(shi,fen,miao,0,0,30,1);clock_end[2] = clock_compute(shi,fen,miao,0,0,30,2);break;}}//当闹钟响�?????30Sif(shi == clock_end[0] && fen == clock_end[1] && miao == clock_end[2]){en_clock = 0;//关闭闹钟//EN_music = 1;}if(en_clock == 1 ){motor(10);HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);}else{HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6, GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);}}

(4)温湿度代码编写

        1. 温湿度基础变量     


uint8_t add1=0xFE,add2=0xE5,add3=0xE3;
//0xFE复位 0xE5启动湿度转换 0xE3启动温度转换
uint16_t RH_Code,RH_Code_low=0,RH_Code_high=0;
uint16_t Temp_Code,Temp_Code_low=0,Temp_Code_high=0;int humidity_min = 50;//能仍受最低干燥程度
int temperature_max = 50;//能仍受的最高温度
int en_t = 0; //温度使能
int en_r = 0; //湿度使能

        2. 温湿度计算


//计算出温湿度
void Temperature_humidity(){//湿度HAL_I2C_Master_Transmit(&hi2c1, 0x80, &add2, 1,100);//写命�??????? ox40里面写命�??????? 0xe5 启动湿度转换HAL_I2C_Master_Receive(&hi2c1, 0x81, &RH_Code, 1, 100);//读命�??????? �???????0x40读取出湿度的数据 存入变量RH_CODEHAL_Delay(30);//进行高低字节转换RH_Code_low=(RH_Code & 0xff);RH_Code_high=(RH_Code >> 8)& 0xff;RH_Code=(RH_Code_low << 8)+RH_Code_high;//温度HAL_I2C_Master_Transmit(&hi2c1, 0x80, &add3, 1,100);HAL_I2C_Master_Receive(&hi2c1, 0x81, &Temp_Code, 1, 100);//读命�??????? �???????0x40读取出温度的数据 存入变量Temp_CODEHAL_Delay(30);//进行高低字节转换Temp_Code_low=(Temp_Code & 0xff);Temp_Code_high=(Temp_Code >> 8)& 0xff;Temp_Code=(Temp_Code_low << 8)+Temp_Code_high;Temp_Code=17572*Temp_Code/65535-4685;//扩大�???????百�??RH_Code=125*RH_Code/65536-6;//计算出湿度�??//printf("Temp_Code = \r%d.%d     RH_Code = %d%%\n",Temp_Code/100,Temp_Code%100,RH_Code%100);//串口输出温湿�???????HAL_Delay(2);
}

        3. 温湿度串口控制


void uart_sensor(){int tr=0;int tr_i = 0;tr = extract_two_digits((char *)uart4_data, "sensor  humidity_min = ", &tr_i);if(tr != 0){humidity_min = tr_i;}tr = extract_two_digits((char *)uart4_data, "sensor  temperature_max = ", &tr_i);if(tr != 0){temperature_max = tr_i;}if(strcmp("sensor temperature start",(char *)uart4_data)==0){en_t = 1;}if(strcmp("sensor humidity start",(char *)uart4_data)==0){en_r = 1;}if(strcmp("sensor temperature stop",(char *)uart4_data)==0){en_t = 0;}if(strcmp("sensor humidity stop",(char *)uart4_data)==0){en_r = 0;}if(strcmp("sensor list",(char *)uart4_data)==0){uart4_data[0] = '0';printf("Temp_Code = \r%d.%d     RH_Code = %d%%\r\n",Temp_Code/100,Temp_Code%100,RH_Code%100);printf("sensor en_t : %d\r\n",en_t);printf("sensor en_r : %d\r\n",en_r);printf("sensor temperature_max : %d\r\n",temperature_max);printf("sensor humidity_min : %d\r\n",humidity_min);}if(strcmp("sensor Temp_Code RH_Code",(char *)uart4_data)==0){uart4_data[0] = '0';printf("Temp_Code = \r%d.%d     RH_Code = %d%%\n",Temp_Code/100,Temp_Code%100,RH_Code%100);}}

        4. 温湿度主函数


void sensor(){static int iii = 0;if(iii == 0){HAL_I2C_Master_Transmit(&hi2c1, 0x80, &add1, 1, 100);HAL_Delay(2);iii++;}Temperature_humidity();uart_sensor();if(RH_Code < humidity_min && en_r == 1){//motor(10);HAL_GPIO_WritePin(GPIOI, GPIO_PIN_11, GPIO_PIN_SET);}else{HAL_GPIO_WritePin(GPIOI, GPIO_PIN_11, GPIO_PIN_RESET);}if(Temp_Code/100 >= temperature_max && en_t == 1){HAL_GPIO_WritePin(GPIOI, GPIO_PIN_10, GPIO_PIN_SET);}else{HAL_GPIO_WritePin(GPIOI, GPIO_PIN_10, GPIO_PIN_RESET);}
}

(5)主函数


void end_main(){tone_init(); //初始化音量频�??????list_max = music_init();//更新乐谱HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);	//启动蜂鸣器定时器HAL_TIM_Base_Start_IT(&htim2);		  	//启动定时�??????2HAL_TIM_Base_Start_IT(&htim3);		  	//启动定时�??????2//1 使能串口空闲中断__HAL_UART_ENABLE_IT(&huart4,UART_IT_IDLE);//2.使能串口中断接收数据HAL_UART_Receive_IT(&huart4,rx_buf,sizeof(rx_buf));int mode_n = 1;while(1){music_kz();alarm_clock();uart_mode();sensor();if(mode_n != mode){mode_n = mode;for(int i = 0; i<34;i++){//printf("afgsbgafdffag");HAL_I2C_Master_Transmit(&hi2c1, 0xA0 , (uint8_t*)&DZP_data[mode][i], 1, 300);HAL_Delay(2);}}}
}

五、总代码

main.c

/* USER CODE BEGIN Header */
/********************************************************************************* @file           : main.c* @brief          : Main program body******************************************************************************* @attention** <h2><center>&copy; Copyright (c) 2024 STMicroelectronics.* All rights reserved.</center></h2>** This software component is licensed by ST under BSD 3-Clause license,* the "License"; You may not use this file except in compliance with the* License. You may obtain a copy of the License at:*                        opensource.org/licenses/BSD-3-Clause********************************************************************************/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */#include <string.h>uint8_t rx_buf[200]={0};	//接收不定长数
uint8_t uart4_data[200] = {0};extern int mode;	//模式
/* USER CODE END Includes *//* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD *//* USER CODE END PTD *//* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD *//* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM *//* USER CODE END PM *//* Private variables ---------------------------------------------------------*/
I2C_HandleTypeDef hi2c1;TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim3;
TIM_HandleTypeDef htim4;UART_HandleTypeDef huart4;/* USER CODE BEGIN PV *//* USER CODE END PV *//* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_I2C1_Init(void);
static void MX_TIM2_Init(void);
static void MX_TIM4_Init(void);
static void MX_UART4_Init(void);
static void MX_TIM3_Init(void);
/* USER CODE BEGIN PFP *//* USER CODE END PFP *//* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 *///重写标准输出函数
int __io_putchar(int ch)
{HAL_UART_Transmit(&huart4, (uint8_t *)&ch, 1, 10);return ch;
}// 自定义空闲中断处理函�????????
void uart4_idle_func(void)
{int len = 0;//判定 是否为空闲中�????????if(  __HAL_UART_GET_FLAG(&huart4, UART_FLAG_IDLE) == SET ){// 清除空闲中断标志,因为是自己定义的函数 系统不会清标__HAL_UART_CLEAR_IDLEFLAG(&huart4);// 计算接收数据的长len = sizeof(rx_buf) - huart4.RxXferCount;//第二个参数是 还剩下的空间// 打印接收到时数据  数据处理//printf("uart rx len = %d, data: %s\r\n",len, rx_buf);// 使用strcpy复制字符�????????strcpy((char *)uart4_data, (char *)rx_buf);printf("%s instructions success\r\n", uart4_data);// 准备接收下一次数�?????????memset(rx_buf,0,len); // 清理接收容器//重置接收指针 剩余容器大小huart4.pRxBuffPtr = rx_buf;huart4.RxXferCount = sizeof(rx_buf);}
}//控制马达
void motor(int d){HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_6);//HAL_Delay(d);
}// 音乐
// 音乐盒基�??????变量
extern int time_100ms_cnt; //0.1s计数�??????
extern int Beat_speed;		//节拍速度,代表半个节拍需要多少个0.1s
extern int Beat_speed_n;	//实际执行的节拍数extern int Beat_num;		//这个�??????个音�??????要多少个 半拍
extern int flag; 			//当其等于 1 时,表示�??????个音结束
extern int EN_music ;				//使能信号,用于开启整个音乐盒
extern int list ;			//音乐列表
extern int list_max ;		//音乐总数
extern int Low_volume ;		//音量大小
extern int Low_volume_cnt;
extern int music_speed_i; 	//音乐播放速度模式保存
extern int music_speed_kz(int i);int tone[3][8];
//初始化高中低音频�??????
void tone_init(){tone[1][0] = 0;	//不执行音�??????tone[1][1] = 191;tone[1][2] = 170;tone[1][3] = 151;tone[1][4] = 143;tone[1][5] = 127;tone[1][6] = 113;tone[1][7] = 101;// 低音 (Low)for (int i = 0; i < 8; i++) {tone[0][i] = tone[1][i] * 2; // 只是低音 近似的�??}// 高音 (High)for (int i = 0; i < 8; i++) {tone[2][i] = tone[1][i] / 2; // 只是高音  近似的�??}
}#define MAX_unit_num 200 //�????????大乐谱数�????????
//创建结构体保存乐�????????
struct music_unit{char name[50];		//乐谱名称int unit[MAX_unit_num];		//发什么音int unit_HL[MAX_unit_num];	//发高音或者其�????????int time[MAX_unit_num];		//发音时间//int time_4[MAX_unit_num];	//判断是否�????????1/4�????????int num;			//记录有多少个
}music[25];//创建乐谱 返回有多少首音乐
int music_init(){int cnt = 0;//第一首音�???????? 生日快乐strcpy(music[0].name, "生日快乐"); 				// 使用strcpy复制字符�???????? 给音乐命�????????int music0_unit[29] = {0,0, 5,5,6,5,1,7, 5,5,6,5,2,1,5,5,6,3,1,7, 6,4,4,3,1,2,1,0,0};		//基础乐谱int music0_time[29] = {1,1, 1,1,2,2,2,3, 1,1,2,2,2,3,2,2,2,2,2,2, 2,2,2,2,2,2,3,1,1};		//乐谱节拍music[0].num = 29;										//乐谱总数int music0_unit_HL[29] = {1,1,0,0,0,0,1,0, 0,0,0,0,1,1,0,0,1,1,1,0, 0,1,1,1,1,1,1,1,1}; 	//乐谱全为中音//第二首音�???????? �????????闪一闪亮晶晶cnt++;strcpy(music[1].name, "�????????闪一闪亮晶晶"); 					// 使用strcpy复制字符�???????? 给音乐命�????????int music1_unit[44] = {0,1,1,5,5,6,6,5, 4,4,3,3,2,2,1,5,5,4,4,3,3,2, 5,5,4,4,3,3,2,1,1,5,5,6,6,5, 4,4,3,3,2,2,1,0};		//基础乐谱int music1_time[44] = {2,2,2,2,2,2,2,3, 2,2,2,2,2,2,3,2,2,2,2,2,2,3, 2,2,2,2,2,2,3,2,2,2,2,2,2,3, 2,2,2,2,2,2,3,2};		//乐谱节拍int music1_unit_HL[44] ={1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1}; 		//乐谱全为中音music[1].num = 44;											//乐谱总数//第三首音�???????? 两只老虎cnt++;strcpy(music[2].name, "两只老虎"); 					// 使用strcpy复制字符�???????? 给音乐命�????????int music2_unit[38] = {0,1,2,3,1, 1,2,3,1, 3,4,5,5, 3,4,5,5,5,6,5,4, 3,1,5,6, 5,4,3,1, 1,5,1,1,1,5,1,1, 0};		//基础乐谱int music2_time[38] = {2,1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,0,0,0,0, 1,1,0,0, 0,0,1,1, 1,1,1,2,1,1,1,2, 2};		//乐谱节拍int music2_unit_HL[38] ={1,1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1, 1,1,1,1, 1,0,1,1,1,0,1,1, 1}; 		//乐谱�????????   中音music[2].num = 38;											//乐谱总数//第四首音�???????? 青花瓷片�????????cnt++;strcpy(music[3].name, "青花瓷片"); 					// 使用strcpy复制字符�???????? 给音乐命�????????int music3_unit[100] = {0,0,0,0, 0,5,5,3, 2,3,6,2, 3,5,3,2, 2,5,5,3,2,3,5,2, 3,5,2,1, 1,1,2,3, 5,6,5,4, 5,3,3,2,2,2,1,2, 1,1,2,1, 2,3,5,3, 3,3,5,5, 3,2,3,6,2,3,5,3, 2,2,5,5, 3,2,3,5, 2,3,5,2, 1,1,1,2,3,5,6,5, 4,5,3,3, 2,2,5,3, 2,2,2,1, 1,0,0,0};		//基础乐谱int music3_time[100] = {0,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,2, 0,0,0,0,0,0,1,0, 0,0,0,2, 0,0,0,0, 0,0,0,0, 0,0,0,0,2,0,0,0, 0,0,0,0, 0,1,0,0, 2,0,0,0, 0,0,0,1,0,0,0,0, 2,0,0,0, 0,0,0,1, 0,0,0,0, 2,0,0,0,0,0,0,0, 0,0,0,0, 0,2,0,1, 0,0,0,1, 2,1,1,1};		//乐谱节拍for(int i =0;i<100;i++)music3_time[i] = music3_time[i]+1;int music3_unit_HL[100] ={ 1,1,1,1, 1,1,1,1, 1,1,0,1, 1,1,1,1, 1,1,1,1,1,1,0,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,0,1,1,1,1, 1,1,1,1, 1,1,1,0, 1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1, 1,1,0,1, 1,1,1,1, 1,1,1,1}; 		//乐谱�????????   中音music[3].num = 100;											//乐谱总数for (int i = 0; i < MAX_unit_num; i++) {//将乐谱保存进结构�????????if(i<music[0].num){//确保数据正确music[0].unit[i] =music0_unit[i];music[0].unit_HL[i] =music0_unit_HL[i];music[0].time[i] =music0_time[i];}//将乐谱保存进结构�????????if(i<music[1].num){//确保数据正确music[1].unit[i] =music1_unit[i];music[1].unit_HL[i] =music1_unit_HL[i];music[1].time[i] =music1_time[i];}//将乐谱保存进结构�????????if(i<music[2].num){//确保数据正确music[2].unit[i] =music2_unit[i];music[2].unit_HL[i] =music2_unit_HL[i];music[2].time[i] =music2_time[i];}//将乐谱保存进结构�????????if(i<music[3].num){//确保数据正确music[3].unit[i] =music3_unit[i];music[3].unit_HL[i] =music3_unit_HL[i];music[3].time[i] =music3_time[i];}}return cnt;
}//播放�???? N首音�???? 音量�???? X 0 - 100
void play_music(int n, int x){static int ni = 0; 		//用于判断 是否换了音乐static int cnt = 0;		//记录播放到哪�????�???? 音节if(ni != n ){//如果音乐换了ni = n;cnt = 0;__HAL_TIM_SET_COMPARE(&htim4,TIM_CHANNEL_1,0);//设置音量HAL_Delay(1000);//}//int value = tone[music[n].unit_HL[cnt]][music[n].unit[cnt]];	//获取频率if(flag == 1){	//接受到一个音节结�????flag = 0;	//复位Beat_num = music[n].time[cnt]; 				//这个音需要多少个半拍//LED_BEEP(music[n].unit[cnt]);				//LED随音节变动�?�变�????if(music[n].time[cnt] == 0){//如果�???? 1/4�????Beat_speed_n = Beat_speed /2;}else{//如果没有1/4�????Beat_speed_n = Beat_speed;}//if(value != 0)//如果有频率�?�执行,没有者只更新 时间�????__HAL_TIM_SET_AUTORELOAD(&htim4,value);		//自动加载频率�????cnt ++; 	//可进行下�????次音�????if(cnt >= music[n].num){ //如果�????个音节播放完�????cnt = 0;//重新播放//__HAL_TIM_SET_COMPARE(&htim4,TIM_CHANNEL_1,0);//设置音量//HAL_Delay(500);//}}//__HAL_TIM_SET_COMPARE(&htim4,TIM_CHANNEL_1,x * (value/100));//设置音量__HAL_TIM_SET_COMPARE(&htim4,TIM_CHANNEL_1,(value/10)*x);//设置音量
}//串口音乐控制函数
void music_kz(){if(EN_music == 1)//启动play_music(list,Low_volume);else__HAL_TIM_SET_COMPARE(&htim4,TIM_CHANNEL_1,0);//设置音量if(strcmp("music volume increase",(char *)uart4_data)==0){uart4_data[0] = '0';Low_volume = Low_volume + Low_volume_cnt;if(Low_volume >= 10)Low_volume = 10;}if(strcmp("music volume reduction",(char *)uart4_data)==0){Low_volume = Low_volume - Low_volume_cnt;if(Low_volume <= 0)Low_volume = 0;}if(strcmp("music speed increase",(char *)uart4_data)==0){uart4_data[0] = '0';music_speed_i++;music_speed_i = music_speed_kz(music_speed_i);}if(strcmp("music speed reduction",(char *)uart4_data)==0){uart4_data[0] = '0';music_speed_i--;music_speed_i = music_speed_kz(music_speed_i);}if(strcmp("music next song",(char *)uart4_data)==0){uart4_data[0] = '0';list++;if(list > list_max){list = list_max;}}if(strcmp("music previous song",(char *)uart4_data)==0){list--;uart4_data[0] = '0';if(list < 0){list = 0;}}if(strcmp("music start",(char *)uart4_data)==0){EN_music = 1;}if(strcmp("music stop",(char *)uart4_data)==0){EN_music = 0;}}//数码管闹�?????
extern int buf[8];
extern int shi_shi;
extern int shi_ge ;
extern int fen_shi;
extern int fen_ge ;
extern int miao_shi ;
extern int miao_ge ;extern int miao ;
extern int shi ;
extern int fen;
//闹钟保存数组
extern int alarm_clock_array[20][4];
extern int alarm_clock_array_cnt;//通过输入不同的n,返回shi fen miao
int clock_compute(int time_shi,int time_fen,int time_miao,int add_shi,int add_fen,int add_miao,int n){time_miao = time_miao + add_miao;time_fen = time_fen + time_miao/60;time_miao = time_miao % 60;time_fen = time_fen + add_fen;time_shi = time_shi + time_fen / 60;time_fen = time_fen%60;time_shi = time_shi + add_shi;time_shi = time_shi%24;if(n == 0) return time_shi;if(n == 1) return time_fen;if(n == 2) return time_miao;return -1;
}//将字符解成数�?????
int char_number(uint8_t c){if(c >= '0' && c <= '9')return c-'0';elsereturn -1;
}// zfc 为当前传入字符串
// zfc_n为比较字符串
// num为如果两字符串最初相等,则取字符串后面多少位的数�?????
int number_char_come(uint8_t zfc[200], uint8_t zfc_n[200], int num){size_t len = strlen((char *)zfc_n);//无符号整数类�?????int cnt = 0;for(int i = 0;i < len;i++){if(zfc[i] != zfc_n[i]) return -1; //不相�?????else cnt++;}if(cnt != len)	 return -1;//两字符串不等size_t shen_len = strlen((char *)zfc) - len;//剩余字符串长�?????size_t hig_num = 0;//用以保存实际有效位数if(shen_len > num) hig_num = num;else hig_num = shen_len;//int number[200];int number1 = 0;int multiplier = 1; // 用于计算10的幂的变�?????for(int i = len + hig_num - 1; i >= len;i--){//number[i-len] = char_number(zfc[i]);if(char_number(zfc[i])== -1) {printf("\r\r\r number error\r\n");return -1;}multiplier = multiplier*10;number1 = number1 + char_number(zfc[i])*multiplier;}return number1;}// 函数定义:从字符串中提取两位数字
int extract_two_digits(const char *str, const char *prefix, int *value) {char *pos = strstr(str, prefix); // 查找前缀的位�?????if (pos == NULL) return 0; // 如果没找到前�?????,返�?????0表示失败// 跳过前缀的长度,找到数字�?????始的位置pos += strlen(prefix);// �?????查接下来的两个字符是否是数字if (pos[0] >= '0' && pos[0] <= '9' && pos[1] >= '0' && pos[1] <= '9') {// 转换字符为数�?????*value = (pos[0] - '0') * 10 + (pos[1] - '0');return 1; // 成功提取,返�?????1}return 0; // 提取失败,返�?????0
}//判断是否到底闹钟
int en_clock = 0;//用于控制闹钟响铃
int en_clock_cnt = 0;
int clock_end[3] = {0};//记录闹钟无人时关闭的时间
//串口设置闹钟
void uart_clock(){int ci = 0;int ci_n = 0;//ci = number_char_come(uart4_data,(uint8_t *)"clock shi = ",2);ci = extract_two_digits((char *)uart4_data, (char *)"clock shi = ", &ci_n);if(ci == 1){uart4_data[0] = '1';shi = ci_n;}//ci = number_char_come(uart4_data,(uint8_t *)"clock fen = ",2);ci = extract_two_digits((char *)uart4_data, (char *)"clock fen = ", &ci_n);if(ci == 1){uart4_data[0] = '1';fen = ci_n;}//ci = number_char_come(uart4_data,(uint8_t *)"clock miao = ",2);ci = extract_two_digits((char *)uart4_data, (char *)"clock miao = ", &ci_n);if(ci == 1){uart4_data[0] = '1';miao = ci_n;}//设置�?????个多少时间后的闹�?????//ci = number_char_come(uart4_data,(uint8_t *)"clock delay shi = ",2);ci = extract_two_digits((char *)uart4_data, "clock delay shi = ", &ci_n);if(ci == 1){uart4_data[0] = '1';alarm_clock_array[alarm_clock_array_cnt][0] = clock_compute(shi,fen,miao,ci_n,0,0,0);alarm_clock_array[alarm_clock_array_cnt][1] = clock_compute(shi,fen,miao,ci_n,0,0,1);alarm_clock_array[alarm_clock_array_cnt][2] = clock_compute(shi,fen,miao,ci_n,0,0,2);alarm_clock_array_cnt++;}//ci = number_char_come(uart4_data,(uint8_t *)"clock delay fen = ",2);ci = extract_two_digits((char *)uart4_data, "clock delay fen = ", &ci_n);if(ci == 1){uart4_data[0] = '1';alarm_clock_array[alarm_clock_array_cnt][0] = clock_compute(shi,fen,miao,0,ci_n,0,0);alarm_clock_array[alarm_clock_array_cnt][1] = clock_compute(shi,fen,miao,0,ci_n,0,1);alarm_clock_array[alarm_clock_array_cnt][2] = clock_compute(shi,fen,miao,0,ci_n,0,2);alarm_clock_array_cnt++;}ci = extract_two_digits((char *)uart4_data, "clock delay miao = ", &ci_n);if(ci == 1){uart4_data[0] = '1';alarm_clock_array[alarm_clock_array_cnt][0] = clock_compute(shi,fen,miao,0,0,ci_n,0);alarm_clock_array[alarm_clock_array_cnt][1] = clock_compute(shi,fen,miao,0,0,ci_n,1);alarm_clock_array[alarm_clock_array_cnt][2] = clock_compute(shi,fen,miao,0,0,ci_n,2);alarm_clock_array_cnt++;}// time shi = 12;fen = 10;miao = 12;music = 1;ci = 0;ci = ci + extract_two_digits((char *)uart4_data, "time shi = ", &alarm_clock_array[alarm_clock_array_cnt][0]);ci = ci + extract_two_digits((char *)uart4_data, ";fen = ", &alarm_clock_array[alarm_clock_array_cnt][1]);ci = ci + extract_two_digits((char *)uart4_data, ";miao = ", &alarm_clock_array[alarm_clock_array_cnt][2]);//ci = ci + extract_two_digits((char *)uart4_data, ";music = ", &alarm_clock_array[alarm_clock_array_cnt][2]);if(ci == 3){//完美对应uart4_data[0] = '1';ci = extract_two_digits((char *)uart4_data, ";music = ", &alarm_clock_array[alarm_clock_array_cnt][3]);if(ci > list_max && ci<0) //如果大于音乐总数alarm_clock_array[alarm_clock_array_cnt][3] = 3;//默认�?????3alarm_clock_array_cnt++;}if(strcmp("clock delay list",(char *)uart4_data)==0){uart4_data[0] = '0';for(int i = 0; i< alarm_clock_array_cnt;i++){if(alarm_clock_array[i][0] != -1 && alarm_clock_array[i][1] != -1 && alarm_clock_array[i][2] != -1)printf("%d : time -> %d/%d/%d  \r\n",i,	alarm_clock_array[i][0],alarm_clock_array[i][1],alarm_clock_array[i][2]);}}//读取关闭第几位闹�?????//ci = number_char_come(uart4_data,(uint8_t *)"clock stop list = ",2);ci = extract_two_digits((char *)uart4_data, "clock stop list = ", &ci_n);if(ci == 1){alarm_clock_array[ci_n][0] = -1;alarm_clock_array[ci_n][1] = -1;alarm_clock_array[ci_n][2] = -1;}//关闭闹钟if(strcmp("clock stop stop",(char *)uart4_data)==0){en_clock = 0;}if(alarm_clock_array_cnt >= 20) alarm_clock_array_cnt = 0;
}
void smg_xians(){}void alarm_clock(){static int pos = 0;HAL_I2C_Mem_Write(&hi2c1,0x70,0X10+pos, 1, (uint8_t*)&buf[pos],1,100);HAL_Delay(1);pos++;if(pos == 3 && pos == 6) pos++;if(pos == 8) pos = 0;uart_clock();//调用串口控制for(int j=0;j<alarm_clock_array_cnt && en_clock == 0;j++){//int cnt_clock = 0;if(alarm_clock_array[j][0] == shi && alarm_clock_array[j][1] == fen && alarm_clock_array[j][2] == miao) {en_clock_cnt = j;en_clock = 1;clock_end[0] = clock_compute(shi,fen,miao,0,0,30,0);clock_end[1] = clock_compute(shi,fen,miao,0,0,30,1);clock_end[2] = clock_compute(shi,fen,miao,0,0,30,2);break;}}//当闹钟响�?????30Sif(shi == clock_end[0] && fen == clock_end[1] && miao == clock_end[2]){en_clock = 0;//关闭闹钟//EN_music = 1;}if(en_clock == 1 ){motor(10);HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);}else{HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6, GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);}}uint8_t add1=0xFE,add2=0xE5,add3=0xE3;
//0xFE复位 0xE5启动湿度转换 0xE3启动温度转换
uint16_t RH_Code,RH_Code_low=0,RH_Code_high=0;
uint16_t Temp_Code,Temp_Code_low=0,Temp_Code_high=0;int humidity_min = 50;//能仍受的�?????低干燥程�?????
int temperature_max = 50;//能仍受的�?????高温�?????
int en_t = 0; //温度使能
int en_r = 0; //湿度使能//计算出温湿度
void Temperature_humidity(){//湿度HAL_I2C_Master_Transmit(&hi2c1, 0x80, &add2, 1,100);//写命�??????? ox40里面写命�??????? 0xe5 启动湿度转换HAL_I2C_Master_Receive(&hi2c1, 0x81, &RH_Code, 1, 100);//读命�??????? �???????0x40读取出湿度的数据 存入变量RH_CODEHAL_Delay(30);//进行高低字节转换RH_Code_low=(RH_Code & 0xff);RH_Code_high=(RH_Code >> 8)& 0xff;RH_Code=(RH_Code_low << 8)+RH_Code_high;//温度HAL_I2C_Master_Transmit(&hi2c1, 0x80, &add3, 1,100);HAL_I2C_Master_Receive(&hi2c1, 0x81, &Temp_Code, 1, 100);//读命�??????? �???????0x40读取出温度的数据 存入变量Temp_CODEHAL_Delay(30);//进行高低字节转换Temp_Code_low=(Temp_Code & 0xff);Temp_Code_high=(Temp_Code >> 8)& 0xff;Temp_Code=(Temp_Code_low << 8)+Temp_Code_high;Temp_Code=17572*Temp_Code/65535-4685;//扩大�???????百�??RH_Code=125*RH_Code/65536-6;//计算出湿度�??//printf("Temp_Code = \r%d.%d     RH_Code = %d%%\n",Temp_Code/100,Temp_Code%100,RH_Code%100);//串口输出温湿�???????HAL_Delay(2);
}void uart_sensor(){int tr=0;int tr_i = 0;tr = extract_two_digits((char *)uart4_data, "sensor  humidity_min = ", &tr_i);if(tr != 0){humidity_min = tr_i;}tr = extract_two_digits((char *)uart4_data, "sensor  temperature_max = ", &tr_i);if(tr != 0){temperature_max = tr_i;}if(strcmp("sensor temperature start",(char *)uart4_data)==0){en_t = 1;}if(strcmp("sensor humidity start",(char *)uart4_data)==0){en_r = 1;}if(strcmp("sensor temperature stop",(char *)uart4_data)==0){en_t = 0;}if(strcmp("sensor humidity stop",(char *)uart4_data)==0){en_r = 0;}if(strcmp("sensor list",(char *)uart4_data)==0){uart4_data[0] = '0';printf("Temp_Code = \r%d.%d     RH_Code = %d%%\r\n",Temp_Code/100,Temp_Code%100,RH_Code%100);printf("sensor en_t : %d\r\n",en_t);printf("sensor en_r : %d\r\n",en_r);printf("sensor temperature_max : %d\r\n",temperature_max);printf("sensor humidity_min : %d\r\n",humidity_min);}if(strcmp("sensor Temp_Code RH_Code",(char *)uart4_data)==0){uart4_data[0] = '0';printf("Temp_Code = \r%d.%d     RH_Code = %d%%\n",Temp_Code/100,Temp_Code%100,RH_Code%100);}}void sensor(){static int iii = 0;if(iii == 0){HAL_I2C_Master_Transmit(&hi2c1, 0x80, &add1, 1, 100);HAL_Delay(2);iii++;}Temperature_humidity();uart_sensor();if(RH_Code < humidity_min && en_r == 1){//motor(10);HAL_GPIO_WritePin(GPIOI, GPIO_PIN_11, GPIO_PIN_SET);}else{HAL_GPIO_WritePin(GPIOI, GPIO_PIN_11, GPIO_PIN_RESET);}if(Temp_Code/100 >= temperature_max && en_t == 1){HAL_GPIO_WritePin(GPIOI, GPIO_PIN_10, GPIO_PIN_SET);}else{HAL_GPIO_WritePin(GPIOI, GPIO_PIN_10, GPIO_PIN_RESET);}
}uint8_t DZP_data[6][34]={{0xAA,0x55,0xFD,0xFF,0xFE,0xFF,0xC0,0x07,0xFF,0xFF,0xF7,0xDF,0xFB,0xBF,0x00,0x01,0xFF,0xFF,0xE0,0x0F,0xEF,0xEF,0xEF,0xEF,0xE0,0x0F,0xEF,0xEF,0xEF,0xEF,0xE0,0x0F,0xEF,0xEF},//�?//0//{0xAA,0x55,0xEF,0xDF,0xEF,0xDF,0xC3,0xDF,0xDF,0xDF,0xBE,0x03,0x42,0xDB,0xEE,0xDB,0xEE,0xDB,0x02,0xDB,0xEE,0x03,0xEE,0xDB,0xEF,0xDF,0xEB,0xDF,0xE7,0xDF,0xEF,0xDF,0xFF,0xDF},//�?//1//{0xAA,0x55,0xF7,0xBF,0xF7,0xBF,0xF7,0xBF,0xEC,0x07,0xEF,0xBF,0xCF,0x7F,0xC8,0x01,0xAF,0x7F,0x6E,0xFF,0xEC,0x07,0xEF,0xF7,0xEE,0xEF,0xEF,0x5F,0xEF,0xBF,0xEF,0xDF,0xEF,0xDF}//�?//2//};void uart_mode(){if(strcmp("mode = music",(char *)uart4_data)==0){mode = 0;}if(strcmp("mode = clock",(char *)uart4_data)==0){mode = 1;}if(strcmp("mode = sensor",(char *)uart4_data)==0){mode = 2;}
}
void end_main(){tone_init(); //初始化音量频�??????list_max = music_init();//更新乐谱HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);	//启动蜂鸣器定时器HAL_TIM_Base_Start_IT(&htim2);		  	//启动定时�??????2HAL_TIM_Base_Start_IT(&htim3);		  	//启动定时�??????2//1 使能串口空闲中断__HAL_UART_ENABLE_IT(&huart4,UART_IT_IDLE);//2.使能串口中断接收数据HAL_UART_Receive_IT(&huart4,rx_buf,sizeof(rx_buf));int mode_n = 1;while(1){music_kz();alarm_clock();uart_mode();sensor();if(mode_n != mode){mode_n = mode;for(int i = 0; i<34;i++){//printf("afgsbgafdffag");HAL_I2C_Master_Transmit(&hi2c1, 0xA0 , (uint8_t*)&DZP_data[mode][i], 1, 300);HAL_Delay(2);}}}
}
/* USER CODE END 0 *//*** @brief  The application entry point.* @retval int*/
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();/* USER CODE BEGIN Init *//* USER CODE END Init */if(IS_ENGINEERING_BOOT_MODE()){/* Configure the system clock */SystemClock_Config();}/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_I2C1_Init();MX_TIM2_Init();MX_TIM4_Init();MX_UART4_Init();MX_TIM3_Init();/* USER CODE BEGIN 2 */end_main();/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 *///printf("afsgbhdn\t\n");//HAL_Delay(500);}/* USER CODE END 3 */
}/*** @brief System Clock Configuration* @retval None*/
void SystemClock_Config(void)
{RCC_OscInitTypeDef RCC_OscInitStruct = {0};RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};/** Initializes the RCC Oscillators according to the specified parameters* in the RCC_OscInitTypeDef structure.*/RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;RCC_OscInitStruct.HSIState = RCC_HSI_ON;RCC_OscInitStruct.HSICalibrationValue = 16;RCC_OscInitStruct.HSIDivValue = RCC_HSI_DIV1;RCC_OscInitStruct.LSIState = RCC_LSI_ON;RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;RCC_OscInitStruct.PLL2.PLLState = RCC_PLL_NONE;RCC_OscInitStruct.PLL3.PLLState = RCC_PLL_NONE;RCC_OscInitStruct.PLL4.PLLState = RCC_PLL_NONE;if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK){Error_Handler();}/** RCC Clock Config*/RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_ACLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2|RCC_CLOCKTYPE_PCLK3|RCC_CLOCKTYPE_PCLK4|RCC_CLOCKTYPE_PCLK5;RCC_ClkInitStruct.AXISSInit.AXI_Clock = RCC_AXISSOURCE_HSI;RCC_ClkInitStruct.AXISSInit.AXI_Div = RCC_AXI_DIV1;RCC_ClkInitStruct.MCUInit.MCU_Clock = RCC_MCUSSOURCE_HSI;RCC_ClkInitStruct.MCUInit.MCU_Div = RCC_MCU_DIV1;RCC_ClkInitStruct.APB4_Div = RCC_APB4_DIV1;RCC_ClkInitStruct.APB5_Div = RCC_APB5_DIV1;RCC_ClkInitStruct.APB1_Div = RCC_APB1_DIV1;RCC_ClkInitStruct.APB2_Div = RCC_APB2_DIV1;RCC_ClkInitStruct.APB3_Div = RCC_APB3_DIV1;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct) != HAL_OK){Error_Handler();}
}/*** @brief I2C1 Initialization Function* @param None* @retval None*/
static void MX_I2C1_Init(void)
{/* USER CODE BEGIN I2C1_Init 0 *//* USER CODE END I2C1_Init 0 *//* USER CODE BEGIN I2C1_Init 1 *//* USER CODE END I2C1_Init 1 */hi2c1.Instance = I2C1;hi2c1.Init.Timing = 0x10707DBC;hi2c1.Init.OwnAddress1 = 0;hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;hi2c1.Init.OwnAddress2 = 0;hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;if (HAL_I2C_Init(&hi2c1) != HAL_OK){Error_Handler();}/** Configure Analogue filter*/if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK){Error_Handler();}/** Configure Digital filter*/if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK){Error_Handler();}/* USER CODE BEGIN I2C1_Init 2 *//* USER CODE END I2C1_Init 2 */}/*** @brief TIM2 Initialization Function* @param None* @retval None*/
static void MX_TIM2_Init(void)
{/* USER CODE BEGIN TIM2_Init 0 *//* USER CODE END TIM2_Init 0 */TIM_ClockConfigTypeDef sClockSourceConfig = {0};TIM_MasterConfigTypeDef sMasterConfig = {0};/* USER CODE BEGIN TIM2_Init 1 *//* USER CODE END TIM2_Init 1 */htim2.Instance = TIM2;htim2.Init.Prescaler = 6400-1;htim2.Init.CounterMode = TIM_COUNTERMODE_UP;htim2.Init.Period = 1000-1;htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;if (HAL_TIM_Base_Init(&htim2) != HAL_OK){Error_Handler();}sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK){Error_Handler();}sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK){Error_Handler();}/* USER CODE BEGIN TIM2_Init 2 *//* USER CODE END TIM2_Init 2 */}/*** @brief TIM3 Initialization Function* @param None* @retval None*/
static void MX_TIM3_Init(void)
{/* USER CODE BEGIN TIM3_Init 0 *//* USER CODE END TIM3_Init 0 */TIM_ClockConfigTypeDef sClockSourceConfig = {0};TIM_MasterConfigTypeDef sMasterConfig = {0};/* USER CODE BEGIN TIM3_Init 1 *//* USER CODE END TIM3_Init 1 */htim3.Instance = TIM3;htim3.Init.Prescaler = 6399;htim3.Init.CounterMode = TIM_COUNTERMODE_UP;htim3.Init.Period = 10000-1;htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;if (HAL_TIM_Base_Init(&htim3) != HAL_OK){Error_Handler();}sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK){Error_Handler();}sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK){Error_Handler();}/* USER CODE BEGIN TIM3_Init 2 *//* USER CODE END TIM3_Init 2 */}/*** @brief TIM4 Initialization Function* @param None* @retval None*/
static void MX_TIM4_Init(void)
{/* USER CODE BEGIN TIM4_Init 0 *//* USER CODE END TIM4_Init 0 */TIM_ClockConfigTypeDef sClockSourceConfig = {0};TIM_MasterConfigTypeDef sMasterConfig = {0};TIM_OC_InitTypeDef sConfigOC = {0};/* USER CODE BEGIN TIM4_Init 1 *//* USER CODE END TIM4_Init 1 */htim4.Instance = TIM4;htim4.Init.Prescaler = 639;htim4.Init.CounterMode = TIM_COUNTERMODE_UP;htim4.Init.Period = 100-1;htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;if (HAL_TIM_Base_Init(&htim4) != HAL_OK){Error_Handler();}sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK){Error_Handler();}if (HAL_TIM_PWM_Init(&htim4) != HAL_OK){Error_Handler();}sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK){Error_Handler();}sConfigOC.OCMode = TIM_OCMODE_PWM1;sConfigOC.Pulse = 0;sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1) != HAL_OK){Error_Handler();}/* USER CODE BEGIN TIM4_Init 2 *//* USER CODE END TIM4_Init 2 */HAL_TIM_MspPostInit(&htim4);}/*** @brief UART4 Initialization Function* @param None* @retval None*/
static void MX_UART4_Init(void)
{/* USER CODE BEGIN UART4_Init 0 *//* USER CODE END UART4_Init 0 *//* USER CODE BEGIN UART4_Init 1 *//* USER CODE END UART4_Init 1 */huart4.Instance = UART4;huart4.Init.BaudRate = 115200;huart4.Init.WordLength = UART_WORDLENGTH_8B;huart4.Init.StopBits = UART_STOPBITS_1;huart4.Init.Parity = UART_PARITY_NONE;huart4.Init.Mode = UART_MODE_TX_RX;huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;huart4.Init.OverSampling = UART_OVERSAMPLING_16;huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;if (HAL_UART_Init(&huart4) != HAL_OK){Error_Handler();}if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK){Error_Handler();}if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK){Error_Handler();}if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK){Error_Handler();}/* USER CODE BEGIN UART4_Init 2 *//* USER CODE END UART4_Init 2 */}/*** @brief GPIO Initialization Function* @param None* @retval None*/
static void MX_GPIO_Init(void)
{GPIO_InitTypeDef GPIO_InitStruct = {0};/* GPIO Ports Clock Enable */__HAL_RCC_GPIOF_CLK_ENABLE();__HAL_RCC_GPIOC_CLK_ENABLE();__HAL_RCC_GPIOI_CLK_ENABLE();__HAL_RCC_GPIOG_CLK_ENABLE();__HAL_RCC_GPIOB_CLK_ENABLE();__HAL_RCC_GPIOE_CLK_ENABLE();/*Configure GPIO pin Output Level */HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1|GPIO_PIN_6, GPIO_PIN_RESET);/*Configure GPIO pin Output Level */HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);/*Configure GPIO pin Output Level */HAL_GPIO_WritePin(GPIOI, GPIO_PIN_11|GPIO_PIN_10, GPIO_PIN_RESET);/*Configure GPIO pins : PF1 PF6 */GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_6;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);/*Configure GPIO pin : PC7 */GPIO_InitStruct.Pin = GPIO_PIN_7;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);/*Configure GPIO pins : PI11 PI10 */GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_10;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);/*Configure GPIO pins : PG2 PG0 PG1 */GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_0|GPIO_PIN_1;GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;GPIO_InitStruct.Pull = GPIO_PULLUP;HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);/*Configure GPIO pin : PE9 */GPIO_InitStruct.Pin = GPIO_PIN_9;GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;GPIO_InitStruct.Pull = GPIO_PULLUP;HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);/* EXTI interrupt init*/HAL_NVIC_SetPriority(EXTI0_IRQn, 3, 0);HAL_NVIC_EnableIRQ(EXTI0_IRQn);HAL_NVIC_SetPriority(EXTI1_IRQn, 3, 0);HAL_NVIC_EnableIRQ(EXTI1_IRQn);HAL_NVIC_SetPriority(EXTI2_IRQn, 3, 0);HAL_NVIC_EnableIRQ(EXTI2_IRQn);HAL_NVIC_SetPriority(EXTI9_IRQn, 2, 0);HAL_NVIC_EnableIRQ(EXTI9_IRQn);}/* USER CODE BEGIN 4 *//* USER CODE END 4 *//*** @brief  This function is executed in case of error occurrence.* @retval None*/
void Error_Handler(void)
{/* USER CODE BEGIN Error_Handler_Debug *//* User can add his own implementation to report the HAL error return state */__disable_irq();while (1){}/* USER CODE END Error_Handler_Debug */
}#ifdef  USE_FULL_ASSERT
/*** @brief  Reports the name of the source file and the source line number*         where the assert_param error has occurred.* @param  file: pointer to the source file name* @param  line: assert_param error line source number* @retval None*/
void assert_failed(uint8_t *file, uint32_t line)
{/* USER CODE BEGIN 6 *//* User can add his own implementation to report the file name and line number,ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) *//* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT *//************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

stm32mp1xx_it.c

/* USER CODE BEGIN Header */
/********************************************************************************* @file    stm32mp1xx_it.c* @brief   Interrupt Service Routines.******************************************************************************* @attention** <h2><center>&copy; Copyright (c) 2024 STMicroelectronics.* All rights reserved.</center></h2>** This software component is licensed by ST under BSD 3-Clause license,* the "License"; You may not use this file except in compliance with the* License. You may obtain a copy of the License at:*                        opensource.org/licenses/BSD-3-Clause********************************************************************************/
/* USER CODE END Header *//* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32mp1xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes *//* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
int mode = 0;	//模式
extern void uart4_idle_func(void);
extern void smg_xians();
// 音乐盒基�?????变量
int time_100ms_cnt = 0; //0.1s计数�?????
int Beat_speed = 5;		//节拍速度,代表半个节拍需要多少个0.1s
int Beat_speed_n = 0;	//实际执行的节拍数int Beat_num = 2;		//这个�?????个音�?????要多少个 半拍
int flag = 0; 			//当其等于 1 时,表示�?????个音结束
int EN_music = 0;				//使能信号,用于开启整个音乐盒
int list = 0;			//音乐列表
int list_max = 0;		//音乐总数
int Low_volume = 5;		//音量大小
int Low_volume_cnt = 3;	//音量大小增加�?????
int music_speed_i = 0; 	//音乐播放速度模式保存
// 音乐播放速度控制函数
int music_speed_kz(int i){//倍数计算公式 1 + (1 - (新的节拍速度 / 原来的节拍�?�度))switch(i){case 0:{Beat_speed = 5;	//0.5s半个节拍,正�?????+�??????�度break;}case 1:{Beat_speed = 4;	//1.2倍数break;}case 2:{Beat_speed = 3;	//约等�??????? 1.5倍数break;}case 3:{Beat_speed = 1;	//约等�??????? 2 倍数break;}case 4:{Beat_speed = 6;	//约等�??????? 0.8 倍数break;}case 5:{Beat_speed = 7;	//约等�??????? 0.6 倍数break;}default:{Beat_speed = 5;	//0.5s半个节拍,正常�?�度i=0;break;}}return i;
}//数码管闹�????
int smg_number[10] = {0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xE0,0xFE,0xF6};
int buf[8] = {0};//闹钟保存数组
int alarm_clock_array[20][4] = {0};
int alarm_clock_array_cnt = 0;
//实时时钟信息
int shi_shi = 0;
int shi_ge = 0;
int fen_shi = 0;
int fen_ge = 0;
int miao_shi = 0;
int miao_ge = 0;
int miao = 0;
int shi = 0;
int fen = 0;int EN_clock = 0;//闹钟设置使能
extern int en_clock;//用于控制闹钟响铃//闹钟设置信息
int shi_shi_clock = 0;
int shi_ge_clock = 0;
int fen_shi_clock = 0;
int fen_ge_clock = 0;
int miao_shi_clock = 0;
int miao_ge_clock = 0;
int miao_clock = 0, shi_clock = 0, fen_clock = 0;/* USER CODE END TD *//* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD *//* USER CODE END PD *//* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM *//* USER CODE END PM *//* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV *//* USER CODE END PV *//* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP *//* USER CODE END PFP *//* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 *//* USER CODE END 0 *//* External variables --------------------------------------------------------*/
extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim3;
extern UART_HandleTypeDef huart4;
/* USER CODE BEGIN EV *//* USER CODE END EV *//******************************************************************************/
/*           Cortex-M4 Processor Interruption and Exception Handlers          */
/******************************************************************************/
/*** @brief This function handles Non maskable interrupt.*/
void NMI_Handler(void)
{/* USER CODE BEGIN NonMaskableInt_IRQn 0 *//* USER CODE END NonMaskableInt_IRQn 0 *//* USER CODE BEGIN NonMaskableInt_IRQn 1 */while (1){}/* USER CODE END NonMaskableInt_IRQn 1 */
}/*** @brief This function handles Hard fault interrupt.*/
void HardFault_Handler(void)
{/* USER CODE BEGIN HardFault_IRQn 0 *//* USER CODE END HardFault_IRQn 0 */while (1){/* USER CODE BEGIN W1_HardFault_IRQn 0 *//* USER CODE END W1_HardFault_IRQn 0 */}
}/*** @brief This function handles Memory management fault.*/
void MemManage_Handler(void)
{/* USER CODE BEGIN MemoryManagement_IRQn 0 *//* USER CODE END MemoryManagement_IRQn 0 */while (1){/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 *//* USER CODE END W1_MemoryManagement_IRQn 0 */}
}/*** @brief This function handles Pre-fetch fault, memory access fault.*/
void BusFault_Handler(void)
{/* USER CODE BEGIN BusFault_IRQn 0 *//* USER CODE END BusFault_IRQn 0 */while (1){/* USER CODE BEGIN W1_BusFault_IRQn 0 *//* USER CODE END W1_BusFault_IRQn 0 */}
}/*** @brief This function handles Undefined instruction or illegal state.*/
void UsageFault_Handler(void)
{/* USER CODE BEGIN UsageFault_IRQn 0 *//* USER CODE END UsageFault_IRQn 0 */while (1){/* USER CODE BEGIN W1_UsageFault_IRQn 0 *//* USER CODE END W1_UsageFault_IRQn 0 */}
}/*** @brief This function handles System service call via SWI instruction.*/
void SVC_Handler(void)
{/* USER CODE BEGIN SVCall_IRQn 0 *//* USER CODE END SVCall_IRQn 0 *//* USER CODE BEGIN SVCall_IRQn 1 *//* USER CODE END SVCall_IRQn 1 */
}/*** @brief This function handles Debug monitor.*/
void DebugMon_Handler(void)
{/* USER CODE BEGIN DebugMonitor_IRQn 0 *//* USER CODE END DebugMonitor_IRQn 0 *//* USER CODE BEGIN DebugMonitor_IRQn 1 *//* USER CODE END DebugMonitor_IRQn 1 */
}/*** @brief This function handles Pendable request for system service.*/
void PendSV_Handler(void)
{/* USER CODE BEGIN PendSV_IRQn 0 *//* USER CODE END PendSV_IRQn 0 *//* USER CODE BEGIN PendSV_IRQn 1 *//* USER CODE END PendSV_IRQn 1 */
}/*** @brief This function handles System tick timer.*/
void SysTick_Handler(void)
{/* USER CODE BEGIN SysTick_IRQn 0 *//* USER CODE END SysTick_IRQn 0 */HAL_IncTick();/* USER CODE BEGIN SysTick_IRQn 1 *//* USER CODE END SysTick_IRQn 1 */
}/******************************************************************************/
/* STM32MP1xx Peripheral Interrupt Handlers                                    */
/* Add here the Interrupt Handlers for the used peripherals.                  */
/* For the available peripheral interrupt handler names,                      */
/* please refer to the startup file (startup_stm32mp1xx.s).                    */
/******************************************************************************//*** @brief This function handles EXTI line0 interrupt.*/
void EXTI0_IRQHandler(void)
{/* USER CODE BEGIN EXTI0_IRQn 0 */if(HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_0) == 0 && mode == 0)//确保数据稳定{//每次按下解决 音量�??????? Low_volume_cntLow_volume = Low_volume + Low_volume_cnt;if(Low_volume >= 10)Low_volume = 0;}if(HAL_GPIO_ReadPin(GPIOG,GPIO_PIN_0)==GPIO_PIN_RESET && mode == 1) {shi_clock++;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;if(shi_clock>=24){shi_clock=0;}miao_shi_clock=miao_clock/10;miao_ge_clock=miao_clock%10;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;buf[0]=smg_number[shi_shi_clock];buf[1]=smg_number[shi_ge_clock];buf[3]=smg_number[fen_shi_clock];buf[4]=smg_number[fen_ge_clock];buf[6]=smg_number[miao_shi_clock];buf[7]=smg_number[miao_ge_clock];}/* USER CODE END EXTI0_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);/* USER CODE BEGIN EXTI0_IRQn 1 *//* USER CODE END EXTI0_IRQn 1 */
}/*** @brief This function handles EXTI line1 interrupt.*/
void EXTI1_IRQHandler(void)
{/* USER CODE BEGIN EXTI1_IRQn 0 */if(HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_1) == 0 && mode == 0)//确保数据稳定{music_speed_i++;music_speed_i = music_speed_kz(music_speed_i);}if(HAL_GPIO_ReadPin(GPIOG,GPIO_PIN_1)==GPIO_PIN_RESET && mode == 1) {fen_clock++;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;if(fen_clock>=60){fen_clock=0;shi_clock++;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;if(shi_clock>=24){shi_clock=0;}}miao_shi_clock=miao_clock/10;miao_ge_clock=miao_clock%10;fen_shi_clock=fen_clock/10;fen_ge_clock=fen_clock%10;shi_shi_clock=shi_clock/10;shi_ge_clock=shi_clock%10;buf[0]=smg_number[shi_shi_clock];buf[1]=smg_number[shi_ge_clock];buf[3]=smg_number[fen_shi_clock];buf[4]=smg_number[fen_ge_clock];buf[6]=smg_number[miao_shi_clock];buf[7]=smg_number[miao_ge_clock];}/* USER CODE END EXTI1_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);/* USER CODE BEGIN EXTI1_IRQn 1 *//* USER CODE END EXTI1_IRQn 1 */
}/*** @brief This function handles EXTI line2 interrupt.*/
void EXTI2_IRQHandler(void)
{/* USER CODE BEGIN EXTI2_IRQn 0 */if(HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_2) == 0 && mode == 0)//确保数据稳定{list++;if(list > list_max){list = 0;}}if(HAL_GPIO_ReadPin(GPIOG,GPIO_PIN_2)==GPIO_PIN_RESET && mode == 1) {//在此处关闭闹�????en_clock = 0;}/* USER CODE END EXTI2_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);/* USER CODE BEGIN EXTI2_IRQn 1 *//* USER CODE END EXTI2_IRQn 1 */
}/*** @brief This function handles TIM2 global interrupt.*/
void TIM2_IRQHandler(void)
{/* USER CODE BEGIN TIM2_IRQn 0 */if(EN_music == 1)time_100ms_cnt++;elsetime_100ms_cnt = time_100ms_cnt;	//其余状�?�不计数if(time_100ms_cnt >= Beat_speed_n * Beat_num){	//这个音节结束time_100ms_cnt = 0;flag = 1;	//发�?�音节结束信�???????}//数码�????static int smg_time_100ms = 0;smg_time_100ms++;if(smg_time_100ms>=10){miao++;smg_time_100ms = 0;}if (miao>=60){miao=0;fen++;if(fen>=60){fen=0;shi++;if(shi>=24){shi=0;}}}if(miao >= 60){miao = miao-60;fen++;}if(fen>=60){fen = fen-60;shi ++;}if(shi>= 24){shi = shi -24;}miao_shi=miao/10;miao_ge=miao%10;fen_shi=fen/10;fen_ge=fen%10;shi_shi=shi/10;shi_ge=shi%10;if(EN_clock == 0){buf[0]=smg_number[shi_shi];buf[1]=smg_number[shi_ge];buf[3]=smg_number[fen_shi];buf[4]=smg_number[fen_ge];buf[6]=smg_number[miao_shi];buf[7]=smg_number[miao_ge];HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_RESET);//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);//HAL_GPIO_WritePin(GPIOI, GPIO_PIN_11|GPIO_PIN_10, GPIO_PIN_RESET);}else{HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_SET);//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);//HAL_GPIO_WritePin(GPIOI, GPIO_PIN_11|GPIO_PIN_10, GPIO_PIN_SET);}/* USER CODE END TIM2_IRQn 0 */HAL_TIM_IRQHandler(&htim2);/* USER CODE BEGIN TIM2_IRQn 1 *//* USER CODE END TIM2_IRQn 1 */
}/*** @brief This function handles TIM3 global interrupt.*/
void TIM3_IRQHandler(void)
{/* USER CODE BEGIN TIM3_IRQn 0 */smg_xians();/* USER CODE END TIM3_IRQn 0 */HAL_TIM_IRQHandler(&htim3);/* USER CODE BEGIN TIM3_IRQn 1 *//* USER CODE END TIM3_IRQn 1 */
}/*** @brief This function handles UART4 global interrupt.*/
void UART4_IRQHandler(void)
{/* USER CODE BEGIN UART4_IRQn 0 */uart4_idle_func();/* USER CODE END UART4_IRQn 0 */HAL_UART_IRQHandler(&huart4);/* USER CODE BEGIN UART4_IRQn 1 *//* USER CODE END UART4_IRQn 1 */
}/*** @brief This function handles EXTI line9 interrupt.*/
void EXTI9_IRQHandler(void)
{/* USER CODE BEGIN EXTI9_IRQn 0 */if(HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_9) == 0 && mode == 0){//确保数据稳定EN_music = !EN_music;}if(HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_9) == 0 && mode == 1 ){//确保数据稳定if(EN_clock == 1){//闹钟设置成功alarm_clock_array[alarm_clock_array_cnt][0] = shi_clock;alarm_clock_array[alarm_clock_array_cnt][1] = fen_clock;alarm_clock_array[alarm_clock_array_cnt][2] = miao_clock;alarm_clock_array[alarm_clock_array_cnt][3] = 3;	//默认播放第三首音�????alarm_clock_array_cnt++;if(alarm_clock_array_cnt >= 20) alarm_clock_array_cnt = 0;EN_clock = 0;}else if(EN_clock == 0){//设置闹钟shi_shi_clock = shi_shi;shi_ge_clock = shi_ge;fen_shi_clock = fen_shi;fen_ge_clock = fen_ge;miao_shi_clock = 0;miao_ge_clock = 0;miao_clock = 0;shi_clock = shi;fen_clock = fen;EN_clock = 1;}}/* USER CODE END EXTI9_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);/* USER CODE BEGIN EXTI9_IRQn 1 *//* USER CODE END EXTI9_IRQn 1 */
}/*** @brief This function handles RCC wake-up interrupt.*/
void RCC_WAKEUP_IRQHandler(void)
{/* USER CODE BEGIN RCC_WAKEUP_IRQn 0 *//* USER CODE END RCC_WAKEUP_IRQn 0 */HAL_RCC_WAKEUP_IRQHandler();/* USER CODE BEGIN RCC_WAKEUP_IRQn 1 *//* USER CODE END RCC_WAKEUP_IRQn 1 */
}/* USER CODE BEGIN 1 *//* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

        串口指令集

mode = music
mode = clock
mode = sensormusic volume increase
music volume reduction
music speed increase
music speed reduction
music next song
music previous song
music start
music stopclock shi = 
clock fen = 
clock miao = 
clock delay shi = 
clock delay fen = 
clock delay miao = time shi = ;fen = ;miao = 
clock delay list
clock stop list = 
clock stop stopsensor  humidity_min = 
sensor  temperature_max = 
sensor temperature start
sensor humidity start
sensor temperature stop
sensor humidity stop
sensor list
sensor Temp_Code RH_Code

六、部分效果展示

STM32杂交版

七、总结

        本设计是一个高度集成的基于STM32MP157A单片机的多功能系统,通过整合蜂鸣器、数码管、点阵屏、温湿度传感器、LED灯、按键等多种模块,实现了丰富的交互与功能。系统利用STM32CUBEIDE作为开发平台,充分发挥了STM32MP157A单片机的高性能与灵活性,展现了其在嵌入式系统设计中的广泛应用潜力。

设计总结:

  1. 模块化设计:本设计采用了模块化设计思路,将不同功能模块(如闹钟、音乐盒、温湿度监测)独立设计后整合在一起,不仅提高了系统的可维护性和可扩展性,还使得各个模块的功能实现更加清晰明了。

  2. 灵活的模式切换:通过串口通信实现不同模式(闹钟、音乐盒、温湿度监测)之间的灵活切换,使得用户可以根据需要轻松选择所需功能,提高了系统的用户友好性和实用性。

  3. 多样化的显示与交互:点阵屏在不同模式下显示不同的汉字(如“钟”、“音”、“传”),直观展示了当前的工作模式,增强了用户体验。同时,按键和串口控制相结合的方式,使得用户可以通过多种途径对系统进行操作,如调节音乐播放速度、音量、切换歌曲,调整闹钟时间、设置多个闹钟等,极大地丰富了系统的交互方式。

  4. 温湿度监测与调节:系统集成了温湿度传感器,能够实时监测环境温湿度,并通过串口调节温湿度上下限,当温湿度超出设定范围时,通过LED灯进行边界提示,实现了对环境的智能监测与调节。

  5. 高效的开发平台:采用STM32CUBEIDE作为开发平台,利用其强大的代码编辑、编译、调试功能,以及丰富的库函数和示例项目,极大地提高了开发效率,降低了开发难度。

  6. 综合应用能力的展现:本设计不仅展示了STM32MP157A单片机在嵌入式系统设计中的强大功能,还体现了设计者在硬件选型、电路设计、软件编程、系统调试等方面的综合应用能力。

综上所述,本设计是一个集多功能性、灵活性、用户友好性于一体的嵌入式系统,充分展示了STM32MP157A单片机在复杂系统设计中的广泛应用前景和潜力。通过本设计的实施,不仅加深了对嵌入式系统设计的理解,还提升了解决实际问题的能力。

参考资料:

        1. STM32简易音乐播放器(HAL库)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/375122.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何解决 PostgreSQL 中由于索引不当导致的性能下降问题?

文章目录 如何解决 PostgreSQL 中由于索引不当导致的性能下降问题一、常见的索引不当情况&#xff08;一&#xff09;缺失关键索引&#xff08;二&#xff09;过多的冗余索引&#xff08;三&#xff09;不合适的索引类型 二、如何发现索引不当的问题&#xff08;一&#xff09;…

docker-2

27.构建python应用镜像-dockerfile实践项目 1.基于官方的镜像&#xff0c;构建python代码运行环境 dockerfile 2.运行镜像&#xff0c;开启一个读写的容器空间&#xff08;定制操作&#xff0c;将代码丢进去&#xff0c;运行调试&#xff09; 3.提交这个变化的容器层数据&#…

生产英特尔CPU处理器繁忙的一天

早晨&#xff1a;准备与检查 7:00 AM - 起床与准备 工厂员工们早早起床&#xff0c;快速洗漱并享用早餐。为了在一天的工作中保持高效&#xff0c;他们会进行一些晨间锻炼&#xff0c;保持头脑清醒和身体活力。 8:00 AM - 到达工厂 员工们到达英特尔的半导体制造工厂&#…

数据库使用SSL加密连接

简介 数据库开通SSL加密连接是确保数据传输过程中安全性的关键措施&#xff0c;它通过加密数据、验证服务器身份、保护敏感信息、维护数据完整性和可靠性&#xff0c;同时满足行业标准和法规要求&#xff0c;进而提升用户体验和信任度&#xff0c;为企业的数据安全和业务连续性…

javaweb中的请求与响应--基于postman工具的应用(附带postman的详细安装步骤)

一、前言 后端的第一天感觉难度就上来了&#xff0c;可能是基础太过薄弱了吧。目前看视频已经有点跟不上了&#xff0c;果然15天想要拿下还是太勉强了点。30天还差不多。不知道读者们有没有好好的去学这方面的知识&#xff0c;没有什么是学不会的&#xff0c;关键是坚持。 Po…

Ubuntu22.04安装NIVIDIA显卡驱动总结

1.首先在安装驱动时需要判断系统有无GPU以及GPU的型号 可以参考这篇文章&#xff1a; https://blog.51cto.com/u_13171517/8814753#:~:textubuntu%20%E7%B3%BB%E7%BB%9F%20%E6%80%8E%E4%B9%88%E5%88%A4%E6%96%AD%E7%B3%BB%E7%BB%9F%E6%9C%89%E6%B2%A1%E6%9C%89GPU%201%20%E6%…

STM32实战篇:闪灯 × 流水灯 × 蜂鸣器

IO引脚初始化 即开展某项活动之前所做的准备工作&#xff0c;对于一个IO引脚来说&#xff0c;在使用它之前必须要做一些参数配置&#xff08;例如&#xff1a;选择工作模式、速率&#xff09;的工作&#xff08;即IO引脚的初始化&#xff09;。 IO引脚初始化流程 1、使能IO引…

乐观锁原理

乐观锁是一种并发控制的方法&#xff0c;主要用于多线程环境下&#xff0c;用于保证数据的一致性。其核心思想是&#xff1a;"在多个事务中乐观地读取数据&#xff0c;在提交时再验证是否有冲突&#xff0c;如果没有&#xff0c;则提交&#xff1b;如果有&#xff0c;则回…

每天五分钟深度学习:向量化技术在神经网络中的应用

本文重点 向量化技术,简而言之,就是利用矩阵运算(而非传统的for循环)来执行大规模的计算任务。这种技术依赖于单指令多数据(SIMD)架构,允许一个指令同时对多个数据元素执行相同的操作。例如,在向量化加法中,不再需要逐个元素进行加法操作,而是可以一次性对整个向量执…

Android使用AndServer在安卓设备上搭建服务端(Java)(Kotlin)两种写法

一直都是通过OkHttp远程服务端进行数据交互&#xff0c;突发奇想能不能也通过OkHttp在局域网的情况下对两个安卓设备或者手机进行数据交互呢&#xff1f; 这样一方安卓设备要当做服务端与另一个安卓设备通过OkHttp进行数据交互即可 当然还可以通过 socket 和 ServerSocket 通…

EasyExcel批量读取Excel文件数据导入到MySQL表中

1、EasyExcel简介 官网&#xff1a;EasyExcel官方文档 - 基于Java的Excel处理工具 | Easy Excel 官网 2、代码实战 首先引入jar包 <dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.3.2</v…

PMP–知识卡片--项目管理五大过程组

记忆 五大“项目管理过程组”&#xff1a;启动&#xff0c;规划&#xff0c;执行&#xff0c;监控&#xff0c;收尾 五个领域&#xff0c;十个字&#xff0c;形象理解&#xff0c;理解逻辑&#xff1a;先启动→再规划→再执行→要监控→最后收尾 定义 经典项目管理场景将项目…

“闭门造车”之多模态思路浅谈:自回归学习与生成

©PaperWeekly 原创 作者 | 苏剑林 单位 | 科学空间 研究方向 | NLP、神经网络 这篇文章我们继续来闭门造车&#xff0c;分享一下笔者最近对多模态学习的一些新理解。 在前文《“闭门造车”之多模态思路浅谈&#xff1a;无损》中&#xff0c;我们强调了无损输入对于理想的…

mac生成.dmg压缩镜像文件

mac生成.dmg压缩镜像文件 背景准备内容步骤1&#xff0c;找一个文件夹2&#xff0c;制作application替身1&#xff0c;终端方式2&#xff0c;黄金右手方式 3&#xff0c;.app文件放入文件夹4&#xff0c;制作.dmg压缩镜像文件5&#xff0c;安装.dmg 总结 背景 为绕开App Store…

Go语言---并发编程之channel(双channel,单channel)以及应用实例(生产者消费者、打印机模型)

Channel goroutine 运行在相同的地址空间&#xff0c;因此访问共享内存必须做好同步。goroutine 通过通信来共享内存&#xff0c;而不是其享内存来通信。 引用类型 channel 是CSP 模式的具体实现,用于多个 goroutine 通讯。其内部实现了同步&#xff0c;确保并发安全。 chan…

FastAPI 学习之路(三十四)数据库多表操作

之前我们分享的是基于单个表的数据库表的操作&#xff0c;我们在设计数据库的时候也设计了跨表&#xff0c;我们可以看下数据库的设计 class User(Base):__tablename__ "users"id Column(Integer, primary_keyTrue, indexTrue)email Column(String(10), uniqueTr…

Python:Python基础知识(注释、命名、数据类型、运算符)

.注释 Python有两种注释方法&#xff1a;单行注释和多行注释。单行注释以#开头&#xff0c;多行注释以三个单引号 或三个双引号 """ 开头和结尾。 2.命名规则 命名规则: 大小写字母、数字、下划线和汉字等字符及组合&#xff1b; 注意事项: 大小写敏感、首…

ESP32FreeRTOS开发笔记:1.双核并行

ESP32 的 Arduino 框架内部集成了 FreeRTOS&#xff0c;允许开发者利用其多任务处理功能。在代码中&#xff0c;xTaskCreatePinnedToCore 函数是 FreeRTOS 提供的 API&#xff0c;用于创建任务并指定任务在哪个核心上运行。 FreeRTOS 是一个流行的实时操作系统内核&#xff0c;…

JavaSE学习笔记之内部类、枚举类和基本类型包装类

今天我们继续复习Java相关的知识&#xff0c;和大家分享有关内部类等方面的知识&#xff0c;希望大家喜欢。 目录​​​​​​​ 内部类 成员内部类 ​编辑 静态内部类 局部内部类 匿名内部类 枚举类 定义方法 基本类型包装类 自动装箱和拆箱 内部类 成员内部类 成…

《Windows API每日一练》9.1.5 自定义资源

自定义资源&#xff08;Custom Resources&#xff09;是在 Windows 程序中使用的一种资源类型&#xff0c;用于存储应用程序特定的数据、图像、音频、二进制文件等。通过自定义资源&#xff0c;开发者可以将应用程序所需的各种资源文件集中管理和存储&#xff0c;便于在程序中访…