/*往W25Q128写入数据*/ #include "system.h" #include "W25Q128_Ins.h" #include "USART.h" #include "rtc.h" #include "SysTick.h" #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; u16 current_minute=0; u16 total_minute=0; /* 六个阶段:每个阶段4个小时 初始值(十倍存储) : 温度:25 湿度:70 光照:10 */ u8 total[]={0xEE,0XEE,0x01,0x04,0x00,0x00,0xFA,0x02,0xBC,0x00,0x64,0x00,0x64,0x00,0x64,0xFF,0xFF,0xFF, 0xEE,0XEE,0x02,0x04,0x00,0x00,0xFA,0x02,0xBC,0x00,0x64,0x00,0x64,0x00,0x64,0xFF,0xFF,0xFF, 0xEE,0XEE,0x03,0x04,0x00,0x00,0xFA,0x02,0xBC,0x00,0x64,0x00,0x64,0x00,0x64,0xFF,0xFF,0xFF, 0xEE,0XEE,0x04,0x04,0x00,0x00,0xFA,0x02,0xBC,0x00,0x64,0x00,0x64,0x00,0x64,0xFF,0xFF,0xFF, 0xEE,0XEE,0x05,0x04,0x00,0x00,0xFA,0x02,0xBC,0x00,0x64,0x00,0x64,0x00,0x64,0xFF,0xFF,0xFF, 0xEE,0XEE,0x06,0x04,0x00,0x00,0xFA,0x02,0xBC,0x00,0x64,0x00,0x64,0x00,0x64,0xFF,0xFF,0xFF}; void Array(u8* n,u8 *hour,u8* min,u16* tem,u16* hum,u16* red,u16 *blue,u16* white) { *hour=(total[3 + 18 * (*n - 1)]); *min=(total[4 + 18 * (*n - 1)]); *tem=(total[5 + 18 * (*n - 1)]<<8|total[6 + 18 * (*n - 1)]);//温度 *hum=(total[7 + 18 * (*n - 1)]<<8|total[8 + 18 * (*n - 1)]);//湿度 *red=(total[9 + 18 * (*n - 1)]<<8|total[10 + 18 * (*n - 1)]);//红光 *blue=(total[11 + 18 * (*n - 1)]<<8|total[12+ 18* (*n - 1)]);//蓝光 *white=(total[13 + 18 * (*n - 1)]<<8|total[14 + 18 * (*n - 1)]);//白光 } uint8_t ArrayRead[108]; uint8_t ArrayWrite[108]; 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);//把读出来的数据赋值给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]); } } void Analysis(u8* n,u16 *i,u8*rs485_rx_buf)//(阶段号,数组值序号,)解析函数 { *n=rs485_rx_buf[3]; *i=rs485_rx_buf[4]; if(*i==2) { total[3 + 18 * (*n - 1)]=rs485_rx_buf[5];//时 } if(*i==3) { total[4 + 18 * (*n - 1)]=rs485_rx_buf[5];//分 } if (*i>=4 && *i<=8) // 温湿度红蓝白光 { total[(2 * (*i) - 3) + 18 * (*n - 1)]=rs485_rx_buf[5]; total[(2 * (*i) - 2) + 18 * (*n - 1)]=rs485_rx_buf[6]; } } void Batch_synchronization(u8 *n,u8*rs485_rx_buf)//批量同步 { *n=rs485_rx_buf[3]; u8 i=4; for( i=4;i<16;i++) { total[(i-1)+ 18 * (*n - 1)]=rs485_rx_buf[i]; } } u8 timelong_Compare() { RTC_Get(&chour,&cminute);//获得当前小时与分钟 current_minute = chour * 60 + cminute; total_minute = total[18 * now_stage - 15] * 60 + total[18 * now_stage - 14]; if (current_minute >= total_minute) { RTC_synchronization_ins(2023,9,1,0,00,00); 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; }