diff --git a/HARDWARE/Relays.c b/HARDWARE/Relays.c index fe9387a..8d07a9e 100644 --- a/HARDWARE/Relays.c +++ b/HARDWARE/Relays.c @@ -22,23 +22,23 @@ void HC595_Pin_Init(void){ //BKP_ITConfig(DISABLE); /* 禁止TAMPER 中断*/ } -void Relays_Init(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); - - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - GPIO_ResetBits(GPIOB,GPIO_Pin_0);//接压缩机 - delay_ms(20); - -// printf("relays_init!!!\r\n"); - -} +//void Relays_Init(void) +//{ +// GPIO_InitTypeDef GPIO_InitStructure; +// +// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); +// +// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; +// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; +// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; +// GPIO_Init(GPIOB, &GPIO_InitStructure); +// +// GPIO_ResetBits(GPIOB,GPIO_Pin_0);//接压缩机 +// delay_ms(20); +// +//// printf("relays_init!!!\r\n"); +// +//} void HC595_Send_Data(u8 data) { u8 i = 0; diff --git a/HARDWARE/rs485.c b/HARDWARE/rs485.c index d1d273d..0110a27 100644 --- a/HARDWARE/rs485.c +++ b/HARDWARE/rs485.c @@ -6,7 +6,7 @@ -u8 sendbuf[29]={0xEE,0xB5,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +u8 sendbuf[27]={0xEE,0xB5,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFC,0xFF,0xFF};//发送给串口屏的实时数据 u8 sendbuf_crc[20]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; @@ -370,16 +370,9 @@ void RS485_1_Send_Data_1(u8 *buf,u8 len) //len:发送的字节数(为了和本代码的接收匹配,这里建议不要超过64个字节) void RS485_1_Send_Data_2(void)//上传温湿度二氧化碳 { - - u8 a; - - RS485_1_TX_EN=1; //设置为发送模式 - -// sendbuf[3]=RS485_RX_BUF[3]; -// sendbuf[4]=RS485_RX_BUF[4];//温度 -// sendbuf[5]=RS485_RX_BUF[5]; -// sendbuf[6]=RS485_RX_BUF[6];//湿度 - + + u8 a; + RS485_1_TX_EN=1; //设置为发送模式 if(T<=500) { @@ -396,7 +389,6 @@ void RS485_1_Send_Data_2(void)// sendbuf[4]=TEM2; sendbuf[5]=HUM1; sendbuf[6]=HUM2; - RED_LIGHT=total[9 + 18 * (now_stage - 1)]<<8|total[10 + 18 * (now_stage - 1)]; BLUE_LIGHT=total[11 + 18 * (now_stage - 1)]<<8|total[12 + 18 * (now_stage - 1)]; WHITE_LIGHT=total[13 + 18 * (now_stage - 1)]<<8|total[14+ 18 * (now_stage - 1)]; @@ -415,7 +407,6 @@ void RS485_1_Send_Data_2(void)// white_light1=total[13 + 18 * (now_stage - 1)]; white_light2=total[14 + 18 * (now_stage - 1)]; } - sendbuf[7]=red_light1; sendbuf[8]=red_light2;//红光 sendbuf[9]=blue_light1; @@ -429,7 +420,6 @@ void RS485_1_Send_Data_2(void)// CO2_1=RS485_RX_BUF[19]; CO2_2=RS485_RX_BUF[20]; } - sendbuf[13]=CO2_1; sendbuf[14]=CO2_2; if(now_stage<7) @@ -477,17 +467,23 @@ void RS485_1_Send_Data_2(void)// // { // printf("%x ",sendbuf[i]); // } - - + sendbuf[0]=0xEE; + sendbuf[1]=0xB5; + sendbuf[2]=0x05; + sendbuf[23]=0xFF; + sendbuf[24]=0xFC; + sendbuf[25]=0xFF; + sendbuf[26]=0xFF; + printf("%x\r\n",sendbuf[0]); for(a=0;a<27;a++) //循环发送数据 { while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); USART_SendData(USART1,sendbuf[a]); + if(a==0)printf("%x\r\n",sendbuf[0]); } while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); - //RS485_RX_CNT=0; - + //RS485_RX_CNT=0; RS485_1_TX_EN=0; //设置为接收模式 } diff --git a/HARDWARE/rtc.c b/HARDWARE/rtc.c index 379b920..9c95b3b 100644 --- a/HARDWARE/rtc.c +++ b/HARDWARE/rtc.c @@ -84,8 +84,8 @@ u8 RTC_Init(void) RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); //使能PWR和BKP外设时钟 PWR_BackupAccessCmd(ENABLE); //使能后备寄存器访问 -// if (BKP_ReadBackupRegister(BKP_DR1) != 0x5050) //从指定的后备寄存器中读出数据:读出了与写入的指定数据不相乎 -// { + if (BKP_ReadBackupRegister(BKP_DR1) != 0x5050) //从指定的后备寄存器中读出数据:读出了与写入的指定数据不相乎 + { BKP_DeInit(); //复位备份区域 // 使用外部晶振 RCC_HSEConfig(RCC_HSE_ON); @@ -112,14 +112,14 @@ u8 RTC_Init(void) RTC_ExitConfigMode(); //退出配置模式 BKP_WriteBackupRegister(BKP_DR1, 0X5050); //向指定的后备寄存器中写入用户程序数据 -// } -// else//系统继续计时 -// { + } + else//系统继续计时 + { -// RTC_WaitForSynchro(); //等待最近一次对RTC寄存器的写操作完成 -// RTC_ITConfig(RTC_IT_SEC, ENABLE); //使能RTC秒中断 -// RTC_WaitForLastTask(); //等待最近一次对RTC寄存器的写操作完成 -// } + RTC_WaitForSynchro(); //等待最近一次对RTC寄存器的写操作完成 + RTC_ITConfig(RTC_IT_SEC, ENABLE); //使能RTC秒中断 + RTC_WaitForLastTask(); //等待最近一次对RTC寄存器的写操作完成 + } RTC_NVIC_Config();//RCT中断分组设置 RTC_Get(&a,&b);//更新时间 diff --git a/HARDWARE/write.c b/HARDWARE/write.c index 177fbb4..79d1a62 100644 --- a/HARDWARE/write.c +++ b/HARDWARE/write.c @@ -7,6 +7,8 @@ #include "myfreertos.h" extern u8 RS485_RX_BUF[128];// //extern u8 buf[51]; +extern u8 store_stage; +u8 read_stage=1;//从flash读取出来的阶段号 extern u8 now_stage; extern u8 chour; extern u8 cminute; @@ -49,15 +51,22 @@ void Write_Init(void) W25QXX_Init(); W25QXX_Erase_Sector(0x000000); + delay_ms(150); W25QXX_Write_NoCheck(total,0x000000,108);//把数据写入flash + W25QXX_Write_NoCheck(&store_stage,0x00006D,1);//把当前运行阶段写入flash W25QXX_Read(ArrayRead,0x000000,108);//把数据读出来 - + } void Read_Init(void) { W25QXX_Init(); W25QXX_Read(ArrayRead,0x000000,108);//把数据读出来 - bufcut_Init(total,ArrayRead,0,109); + bufcut_Init(total,ArrayRead,0,109);//把读出来的数据赋值给total数组 + W25QXX_Read(&read_stage,0x00006D,1); + now_stage=read_stage;//读出来的阶段赋值给当前阶段 + printf("%d\r\n",now_stage); + printf("\r\n"); + printf("\r\n"); for(int i=0;i<108;i++) { printf("%d ",ArrayRead[i]); @@ -109,14 +118,20 @@ u8 timelong_Compare() current_minute = chour * 60 + cminute; total_minute = total[18 * now_stage - 15] * 60 + total[18 * now_stage - 14]; - if (current_minute >= total_minute) { + if (current_minute >= total_minute) + { RTC_synchronization_ins(2023,9,1,0,00,00); - if (now_stage == 6) { + if (now_stage == 6) + { + store_stage=1; + Write_Init(); return 1; } + store_stage=now_stage + 1; + Write_Init(); return now_stage + 1; } - + store_stage=now_stage; return now_stage; } diff --git a/OBJ/LED.axf b/OBJ/LED.axf index 0eb1a0c..b4abf12 100644 Binary files a/OBJ/LED.axf and b/OBJ/LED.axf differ diff --git a/OBJ/LED.build_log.htm b/OBJ/LED.build_log.htm index 2bc6c72..3d10a91 100644 --- a/OBJ/LED.build_log.htm +++ b/OBJ/LED.build_log.htm @@ -29,7 +29,7 @@ Project File Date: 11/19/2023 Build target 'LED' compiling main.c... linking... -Program Size: Code=25516 RO-data=292 RW-data=496 ZI-data=12824 +Program Size: Code=26140 RO-data=368 RW-data=496 ZI-data=12824 FromELF: creating hex file... "..\OBJ\LED.axf" - 0 Error(s), 0 Warning(s). @@ -44,7 +44,7 @@ Package Vendor: Keil D:\MDK5\ARM\Keil\STM32F1xx_DFP\2.3.0\Device\Include