void init(void){ GPIO_init(); USART_init(); CAN_Config(); SysTick_init(); accelerometer_init(); ADC_init(); TIM4_init(); TIM2_init(); }
int main(void) { u8 dip_config; SystemInit(); // Init USB for Master Nodes #if defined(RX4) || defined(RX5) || defined(RX6) Set_System(); Set_USBClock(); USB_Interrupts_Config(); USB_Init(); #endif dip_config = Read_DIP_Configuration(); // USART1初始化,波特率115200,单次8比特,无奇偶校验,1停止位:用于上位机下发命令 USART1_init(dip_config); // 串口监听 TIM4_init(); //InitMPU6050(); SPI1_init(); TIM3_init(); GPIO_Configuration(); DW1000_init(dip_config); EXTI_init(); #ifdef TX TIM2_init(); // LS Poll Cycle #endif RX_mode_enable(); DEBUG1(("=====Init Done, with DIP config: %02X=====\r\n", dip_config)); while(1) { ; } }
void neomaple_hard_init(uint8_t *buffer) { WS2812_buffer = buffer; GPIO_init(); DMA_init(); TIM2_init(); }
int main(void){ u8 keyFlag = 0x0; char temp_str[20]; //USART_InitTypeDef USART_InitStructure; //NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; //����AFIOʱ�� RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //����USARTx_TxΪ������������ GPIO_InitStructure.GPIO_Pin = GPIO_TxPin; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); //���� USARTx_Rx Ϊ�������� GPIO_InitStructure.GPIO_Pin = GPIO_RxPin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //�������ã� ������ 115200 ����λ 8 ֹͣλ 1 ��żλ NONE USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //��ʼ������ USART_Init(USART1, &USART_InitStructure); //Usart1 NVIC ���� NVIC_InitStructure.NVIC_IRQChannel |= USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//��ռ���ȼ�3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //�����ȼ�3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ��ʹ�� NVIC_Init(&NVIC_InitStructure); //����ָ���IJ�����ʼ��VIC�Ĵ��� USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//�������ڽ����ж� //�������� USART_Cmd(USART1, ENABLE); //SystemInit(); //ϵͳinit����ʹ����������configuration�������������г�ʼ���е����� RCC_Configuration(); NVIC_Configuration(); //ʹ��APB2��������ʱ��, ��������û�����䣬ǰ�����õ�ȫ��ʧЧ�����������趨��IO�� RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); //����AFIOʱ�� RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //����USARTx_TxΪ������������ GPIO_InitStructure.GPIO_Pin = GPIO_TxPin; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); //���� USARTx_Rx Ϊ�������� GPIO_InitStructure.GPIO_Pin = GPIO_RxPin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //�������ã� ������ 115200 ����λ 8 ֹͣλ 1 ��żλ NONE USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //��ʼ������ USART_Init(USART1, &USART_InitStructure); //Usart1 NVIC ���� NVIC_InitStructure.NVIC_IRQChannel |= USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//��ռ���ȼ�3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //�����ȼ�3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ��ʹ�� NVIC_Init(&NVIC_InitStructure); //����ָ���IJ�����ʼ��VIC�Ĵ��� USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//�������ڽ����ж� //�������� USART_Cmd(USART1, ENABLE); //usart1_init(); led_init(); key_init(); TIM2_init(); tcp_state = 0x00; while(1){ /* if(tcp_state > 0) { sprintf(temp_str, "%d", rx_total); strcat((char *)temp_str, "-"); Uart1_PutString(temp_str, strlen(temp_str)); Uart1_PutString("pealse press key1 to update", 28); tcp_state = 0; } if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 0){//���� Delay(0xAA200); if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 0){ Uart1_PutString("updating....", 13); iap_write_appbin(appxaddr,USART_RX_BUF ,rx_total); Uart1_PutString("updated. please press key2 to start new app", 44); Uart1_PutString("pealse press key1 to update", 28); } } if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1) == 0){//���� Delay(0xAA200); if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1) == 0){ Uart1_PutString("starting ....", 14); iap_load_app(appxaddr); Uart1_PutString("start up ....", 14); } } */ /**/ if(tcp_state > 0) { //total += count; sprintf(temp_str, "%d", rx_total); strcat((char *)temp_str, "-"); Uart1_PutString(temp_str, strlen(temp_str)); //Uart1_PutString(USART_RX_BUF, count); Uart1_PutString("over---", 8); tcp_state = 0; rx_total = 0; } /**/ /** if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 0){ Delay(0xAA200); if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 0){ if(keyFlag > 0){ GPIO_Write(GPIOB, 0x0000); keyFlag = 0; }else{ GPIO_Write(GPIOB, 0xffff); keyFlag = 1; } } } **/ } }
//================================================================================== //================================================================================== //================================================================================== int main() { bool ver = 0; uint8_t cnt_link = 0; PLL_init(); GPIO_init(); TIM1_init(); TIM2_init(); TIM3_init(); UART_init(); WDT_init(); EEPROM_init(); SysTick_Config(SystemCoreClock/800);//~10 ms time.t1=5; time.t2=5; time.t3=5; time.t4=5; delay_ms(100); Segment[0]=0xFF; Segment[1]=0xFF; Segment[2]=0xFF; Segment[3]=0xFF; Segment[4]=0xFF; Segment[5]=0xFF; Segment[6]=0x7F; ALARM_ON; delay_ms(100); ALARM_OFF; delay_ms(1000); // // while(1) { if( TX_st ) { TX_st = 0; if( cnt_link < LINK_COUNT ) { link_PKBA(); ++cnt_link; } else { PKDU.error = true; cnt_link = 0; } } if( RX_ok && !PKDU.error ) { uint8_t cnt_byte = 0, sum = 0; while( cnt_byte < RX_FRAME_SIZE ) { sum += ArrayRX_PKBA[cnt_byte]; ++cnt_byte; } sum += 0xAA; if( !sum ) { StatusPKBA.reg0 = ArrayRX_PKBA[0]; StatusPKBA.reg1 = ArrayRX_PKBA[1]; StatusPKBA.Error = (ArrayRX_PKBA[3]<<8) | ArrayRX_PKBA[2]; StatusPKBA.RabReg0 = ArrayRX_PKBA[4]; StatusPKBA.UGen = (ArrayRX_PKBA[6]<<8) | ArrayRX_PKBA[5]; StatusPKBA.IGen = (ArrayRX_PKBA[8]<<8) | ArrayRX_PKBA[7]; StatusPKBA.DT = ArrayRX_PKBA[9]; StatusPKBA.DM = ArrayRX_PKBA[10]; StatusPKBA.TM = ArrayRX_PKBA[11]; StatusPKBA.NDiz = (ArrayRX_PKBA[13]<<8) | ArrayRX_PKBA[12]; StatusPKBA.TBapEx = ArrayRX_PKBA[14]; StatusPKBA.TBapIn = ArrayRX_PKBA[15]; StatusPKBA.Led1 = ArrayRX_PKBA[16]; StatusPKBA.Led2 = ArrayRX_PKBA[17]; if( !ver ) { ver = true; show_ver(); delay_ms( 1500 ); Segment[ 0 ] = 0; Segment[ 1 ] = 0; Segment[ 2 ] = 0; Segment[ 3 ] = 0; Segment[ 4 ] = 0; } cnt_link=0; } RX_ok=0; } __nop(); Set_Error(); if(!PKDU.error) ShowParam(); if((PKDU.StatusKN>>4)&1) { maska_err = 0; StatusPKBA.Error=0; PKDU.error=false; cnt_link = 0; } if(((PKDU.StatusKN>>5)&1) && ((PKDU.StatusKN>>6)&1)) { Segment[0] = 0xFF; Segment[1] = 0xFF; Segment[2] = 0xFF; Segment[3] = 0xFF; Segment[4] = 0xFF; Segment[5] = 0xFF; Segment[6] = 0x7F; while(((PKDU.StatusKN>>5)&1)&&((PKDU.StatusKN>>6)&1)) IWDG_ReloadCounter(); } ControlZvonok(); write_hour(); IWDG_ReloadCounter(); } }