void mcu_init(void) { mcu_arch_init(); #ifdef PERIPHERALS_AUTO_INIT sys_time_init(); #ifdef USE_LED led_init(); #endif /* for now this means using spektrum */ #if defined RADIO_CONTROL & defined RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT & defined RADIO_CONTROL_BIND_IMPL_FUNC RADIO_CONTROL_BIND_IMPL_FUNC(); #endif #ifdef USE_UART0 uart0_init(); #endif #ifdef USE_UART1 uart1_init(); #endif #ifdef USE_UART2 uart2_init(); #endif #ifdef USE_UART3 uart3_init(); #endif #ifdef USE_UART4 uart4_init(); #endif #ifdef USE_UART5 uart5_init(); #endif #ifdef USE_I2C0 i2c0_init(); #endif #ifdef USE_I2C1 i2c1_init(); #endif #ifdef USE_I2C2 i2c2_init(); #endif #ifdef USE_ADC adc_init(); #endif #ifdef USE_USB_SERIAL VCOM_init(); #endif #if USE_SPI #if SPI_MASTER #if USE_SPI0 spi0_init(); #endif #if USE_SPI1 spi1_init(); #endif #if USE_SPI2 spi2_init(); #endif #if USE_SPI3 spi3_init(); #endif spi_init_slaves(); #endif // SPI_MASTER #if SPI_SLAVE #if USE_SPI0_SLAVE spi0_slave_init(); #endif #if USE_SPI1_SLAVE spi1_slave_init(); #endif #if USE_SPI2_SLAVE spi2_slave_init(); #endif #if USE_SPI3_SLAVE spi3_slave_init(); #endif #endif // SPI_SLAVE #endif // USE_SPI #ifdef USE_DAC dac_init(); #endif #else INFO("PERIPHERALS_AUTO_INIT not enabled! Peripherals (including sys_time) need explicit initialization.") #endif /* PERIPHERALS_AUTO_INIT */ }
void uart_init(u32 bound) { uart4_init(bound); uart5_init(bound); }
int main(void) { u16 times=0,i=0; NORMALTIME cur_time; //设置RTC的时间用 //Flash_Write(0x08041000,(u8 *)IndCalib,sizeof(IndCalib)); Flash_Read(0x08041000,(u8 *)IndCalib,sizeof(IndCalib)); delay_init(); //延时函数初始化 NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级 uart1_init(115200); //上位机通信模块 uart2_init(9600); //风速传感器模块 A2 A3 要转为232 //uart3_init(19200); //SD卡模块 (兼职风向-因为3有重映射功能) uart4_init(9600); //称重模块 uart5_init(9600); //AD模块 LED_Init(); //LED端口初始化 KEY_Init(); //初始化与按键连接的硬件接口 SD_init(); OPEN_SD_POWER; CLOSE_SD_POWER; OPEN_SD_POWER; CLOSE_SD_POWER; OPEN_SD_POWER; cur_time.tm_year = 2016; //2016-1900 cur_time.tm_mon = 5; cur_time.tm_mday = 29; cur_time.tm_hour = 23; cur_time.tm_min = 56; cur_time.tm_sec = 2; RTC_Init(cur_time);// while(DS18B20_Init())//初始化DS18B20,兼检测18B20 { printf("DS18B20 Check Failed!"); printf("Please Check! "); } printf("DS18B20 Ready! "); while(1) { if(IS_BUT_DN) { BEEP = 0; } else { BEEP = 1; g_PaOffset= -g_Pa; g_IndValOffset[0]= -Volt2Distance(0,g_IndVal[0]); g_IndValOffset[1]= -Volt2Distance(1,g_IndVal[1]); g_IndValOffset[2]= -Volt2Distance(2,g_IndVal[2]); g_IndValOffset[3]= -Volt2Distance(3,g_IndVal[3]); } if(times%60==0) { windSpeedDirFlag++; sendWindSpeedCmd(); //串口2 带232 //printf("3\r\n"); if(5 == windSpeedDirFlag) { windSpeedDirFlag = 0; } //printf("4\r\n"); //风速的反应慢 一秒钟最多发一次指令 不然传感器要疯掉 if(0 == windSpeedDirFlag) { uart3_init(19200); //SD卡模块 (兼职风向-因为3有重映射功能) g_uart3_used_for_SD = 1; // 日期 时间 位移1, 2, 3, 4 |拉力| 温度 |SD|风速|风向 sprintf(CmdStr,"#01,%02d-%02d-%02d,%02d:%02d:%02d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%1d,%04d,%04d!\r\n", cur_time.tm_year,cur_time.tm_mon,cur_time.tm_mday, cur_time.tm_hour,cur_time.tm_min,cur_time.tm_sec, dateSendtoPC[0],dateSendtoPC[1],dateSendtoPC[2],dateSendtoPC[3], dateSendtoPC[4], dateSendtoPC[6],dateSendtoPC[7],dateSendtoPC[8],dateSendtoPC[9], g_Temper,lastSDerr,g_WindSpeed,g_WindDir); //printf("7\r\n"); lastSDerr = write_string_to_files(CmdStr); } else { //printf("8\r\n"); uart3_init2(9600); //SD卡的usart3 重映射到 PB10 和PB11口 来读风向 g_uart3_used_for_SD = 0; send_byte_to_usart3(0x02);//初始化完后第一个字节会发不成功 sendWindDirCmd();//串口3 } //printf("11\r\n"); cur_time = Time_GetTime(); } if(times%10==0) { //sendWeightLoad1Cmd(); //称重标定代码 //printf("12\r\n"); switch(PC_Wcmd) { case 0x30: //printf("13\r\n"); BEEP = 1; sendWeightZeroCmd(); BEEP = 0; PC_Wcmd = 0; break; case 0x40: //printf("14\r\n"); BEEP = 1; sendWeightLoad1Cmd(); PC_Wcmd = 0; BEEP = 0; break; case 0x41: //printf("15\r\n"); BEEP = 1; sendWeightLoad2Cmd(g_weightCalib[0],g_weightCalib[1]); PC_Wcmd = 0; BEEP = 0; break; default: //printf("16\r\n"); //sendWeightLoad2Cmd(0x27,0x10); sendWeightCmd(); //串口4 break; } BLED3=1; sendADCmd(); //串口5 BLED3=0; dateSendtoPC[0] = g_IndVal[0]; dateSendtoPC[1] = g_IndVal[1]; dateSendtoPC[2] = g_IndVal[2]; dateSendtoPC[3] = g_IndVal[3]; dateSendtoPC[4] = g_PaOffset + g_Pa; dateSendtoPC[6] = g_IndValOffset[0] + Volt2Distance(0,g_IndVal[0]); dateSendtoPC[7] = g_IndValOffset[1] + Volt2Distance(1,g_IndVal[1]); dateSendtoPC[8] = g_IndValOffset[2] + Volt2Distance(2,g_IndVal[2]); dateSendtoPC[9] = g_IndValOffset[3] + Volt2Distance(3,g_IndVal[3]); } switch(PC_cmd) { case 1: BLED2 = 1; // 日期 时间 位移1, 2, 3, 4 |拉力| 温度 |SD|风速|风向 sprintf(CmdStr,"#01,%02d-%02d-%02d,%02d:%02d:%02d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%d,%04d,%04d!\r\n", cur_time.tm_year,cur_time.tm_mon,cur_time.tm_mday, cur_time.tm_hour,cur_time.tm_min,cur_time.tm_sec, dateSendtoPC[0],dateSendtoPC[1],dateSendtoPC[2],dateSendtoPC[3], dateSendtoPC[4], dateSendtoPC[6],dateSendtoPC[7],dateSendtoPC[8],dateSendtoPC[9], g_Temper,lastSDerr,g_WindSpeed,g_WindDir); send_string_to_usart1(CmdStr); BLED2 = 0; PC_cmd = 0; break; case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: BEEP = 1; sprintf(CmdStr,"#%02x",PC_cmd); for(i=0;i<21;i++) { sprintf(CmdStr,"%s,%+05d",CmdStr,IndCalib[PC_cmd-0x10][i]); } sprintf(CmdStr,"%s!\r\n",CmdStr); send_string_to_usart1(CmdStr); PC_cmd = 0; BEEP = 0; break; case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: sprintf(CmdStr,"#%02x",PC_cmd-0x10); for(i=0;i<21;i++) { sprintf(CmdStr,"%s,%+05d",CmdStr,IndCalib[PC_cmd-0x20][i]); } sprintf(CmdStr,"%s!\r\n",CmdStr); send_string_to_usart1(CmdStr); PC_cmd = 0; break; } times++; delay_ms(10); } }