int main(void){ // u8 d4[5]; // d4[0]='a'; // d4[1]='b'; // d4[2]='c'; // d4[3]='d'; // d4[4]='\0'; RCC_Config(); GPIO_Config(); USART_Config(); NVIC_Config(); while(1){ // printf("×Ö·û´®Êä³ö d4=%s\r\n",d4); printf("Use_EPH_Sum=%d\r\n", GPS_Information.Use_EPH_Sum); printf("MSL_Al=%lf\r\n", GPS_Information.MSL_Altitude); printf("Longitude=%s\r\n", GPS_Information.Longitude); printf("Latitude=%s\r\n", GPS_Information.Latitude); printf("NS_Ind=%c\r\n", GPS_Information.NS_Indicator); printf("Speed=%lf\r\n", GPS_Information.Speed); printf("EW_Ind=%c\r\n", GPS_Information.EW_Indicator); printf("Course=%lf\r\n", GPS_Information.Course); printf("PDOP=%lf\r\n", GPS_Information.PDOP); printf("HDOP=%lf\r\n", GPS_Information.HDOP); printf("VDOP=%lf\r\n", GPS_Information.VDOP); } }
/* ------------------------------------------------------------------------- * 函数名称: * 函数功能: * 输入形参: * 返回值: --------------------------------------------------------------------------- */ void Board_Init(void) { u8 i; //系统时钟配置 SystemInit(); //延时函数初始化 delay_init(72); //定时器1初始化 TIM1_config(); //舵机初始化 Motor_Init(); Servo_Init(); //串口配置 USART_Config(); //串口中断配置 NVIC_Config(); //LED初始化 LED_Init(); //按键初始化 KEY_Init(); //等待电调中间值确定 for(i=0;i<3;i++) { delay_ms(1000); } }
int main(void) { int order; SysTick_Init(); NVIC_Config(); LedBlink_Init(); uart_init(); printf("###########################################################################\r\n "); printf("Using USART2 As serial port, Baurd: 57600, TX: GPIO PD5, RX: GPIO PD6\r\n\r\n"); printf("Please select testcase to run...\r\n"); print_test_cases(); while(1) { Delay(200); for (order = TEST_START; order < TEST_END; order++) { // c = GetChar(); // if (c) { // printf("Get char: %c\r\n", c); // } // c = c - '0'; printf("\r\n=======================================================\r\n"); test_funcs[order](); //break; } while(1); } }
void init() { SystemInit(); // Init the LEDs GPIO_Config(); // For FreeRTOS NVIC_Config(); // Init for debuging USART_Config(); // LED Controller Init LEDDecoderInit(); // Open CRC for emWin CRC_Init(); // LCD STM324xG_LCD_Init(); sEE_Init(); // Touch Screen TSC_Config(); // emWin GUI_Init(); // File System file_system_init(); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* CAN Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE); /* NVIC Configuration */ NVIC_Config(); /* Configures LED 1..4 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* CAN transmit at 125Kb/s and receive by polling in loopback mode */ TestRx = CAN_Polling(); if (TestRx != FAILED) { /* OK */ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); } else { /* KO */ /* Turn on LED3 */ STM_EVAL_LEDOn(LED3); } /* CAN transmit at 500Kb/s and receive by interrupt in loopback mode */ TestRx = CAN_Interrupt(); if (TestRx != FAILED) { /* OK */ /* Turn on LED4 */ STM_EVAL_LEDOn(LED4); } else { /* KO */ /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); } /* Infinite loop */ while (1) { } }
/*系统初始化*/ void Init_sys(void) { RCC_Config(); NVIC_Config(); GPIO_Config(); USART_Config(); SPI_Config(SPI1); app_tim(); //应用程序的定时器配置 }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* Configures LED 1..4 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDOff(LED1); DFLASH /* NVIC configuration */ NVIC_Config(); RCC_Configuration(); GPIO_Configuration(); USART_InitStructure.USART_BaudRate = 19200; 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); USART_Cmd(USART1, ENABLE); Debug("\nZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz!!!!!!!!!!!!!!!!!!!!"); DFLASH /* CAN configuration */ CAN_Config(); Delay(); CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE); /* Infinite loop */ short int x,led; while(1) { x++; if (x == 0) { if (led) { STM_EVAL_LEDOn(LED1); Delay(); } else { STM_EVAL_LEDOff(LED1); TxMessage.Data[0]++; CAN_Transmit(CANx, &TxMessage); Delay(); } led ^= 1; } }//END While }//END main
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* NVIC configuration */ NVIC_Config(); /* USARTx configuration ------------------------------------------------------*/ /* USARTx configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - Two Stop Bit - Odd parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_2; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Enable the EVAL_COM1 Transmit interrupt: this interrupt is generated when the EVAL_COM1 transmit data register is empty */ USART_ITConfig(EVAL_COM1, USART_IT_TXE, ENABLE); /* Wait until EVAL_COM1 send the TxBuffer */ while(TxCounter < NbrOfDataToTransfer) {} /* The software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the last frame’s end of transmission*/ while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET) {} /* Enable the EVAL_COM1 Receive interrupt: this interrupt is generated when the EVAL_COM1 receive data register is not empty */ USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); /* Wait until EVAL_COM1 receive the RxBuffer */ while(RxCounter < NbrOfDataToRead) {} while (1) { } }
int main(void) { volatile unsigned long int i, j; unsigned char pozycja=1; bool aktualizacja=TRUE; unsigned char *menu[5] = {"Info\0", "Logo\0", "Negatyw\0", "Animacja\0"}; //konfiguracja systemu RCC_Config(); GPIO_Config(); NVIC_Config(); /*Tu nalezy umiescic ewentualne dalsze funkcje konfigurujace system*/ GPIO_ResetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); LCDN_HwConfig(); LCDN_Init(); LCDN_Clear(); while (1) { /*Tu nalezy umiescic glowny kod programu*/ GPIO_WriteBit(GPIOB, GPIO_Pin_15, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_15))); if (!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) && (pozycja>1)){ pozycja--; aktualizacja=TRUE; } if (!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1) && (pozycja<4)){ pozycja++; aktualizacja=TRUE; } if (!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5)){ switch (pozycja){ case 1: Opcja_Info(); break; case 2: Opcja_Logo(); break; case 3: Opcja_Negatyw(); break; case 4: Opcja_Animacja(); break; } aktualizacja=TRUE; } if (aktualizacja){ LCDN_Clear(); LCDN_WriteXY(" MENU \0",0,0); for (i=1;i<=4;i++){ if (i==pozycja) { LCDN_WriteXY(">",0,i); } LCDN_WriteXY(menu[i-1],2,i); } aktualizacja=FALSE; } for (i=0;i<1500000ul;i++); }; return 0; }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* NVIC configuration */ NVIC_Config(); /* Configures LED 1..4 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Configure Push button key */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* CAN configuration */ CAN_Config(); CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE); /* turn off all leds*/ STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); /* Infinite loop */ while(1) { while(STM_EVAL_PBGetState(BUTTON_KEY) == KEY_PRESSED) { if(KeyNumber == 0x4) { KeyNumber = 0x00; } else { LED_Display(++KeyNumber); TxMessage.Data[0] = KeyNumber; CAN_Transmit(CANx, &TxMessage); Delay(); while(STM_EVAL_PBGetState(BUTTON_KEY) != KEY_NOT_PRESSED) { } } } } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* NVIC configuration ------------------------------------------------------*/ NVIC_Config(); /* Initialize LEDs mounted on EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the KEY/Tamper and Wakeup buttons mounted on EVAL board */ STM_EVAL_PBInit(BUTTON_KEY_TAMPER, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_EXTI); /* Configure the SysTick Handler Priority: Preemption priority and subpriority */ NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), !ubPreemptionPriorityValue, 0)); while (1) { if(ubPreemptionOccurred != 0) { /* Toggle LED1 */ STM_EVAL_LEDToggle(LED1); /* Insert delay Time */ Delay(0x5FFFF); /* Toggle LED2 */ STM_EVAL_LEDToggle(LED2); Delay(0x5FFFF); /* Toggle LED3 */ STM_EVAL_LEDToggle(LED3); Delay(0x5FFFF); /* Toggle LED4 */ STM_EVAL_LEDToggle(LED4); Delay(0x5FFFF); } } }
void Sys_Init() { NVIC_Config(); Usart1_Config(); DMA_Config(); SPI1_Init(); Nrf24l01_Init(3,40); LED_Config(); LED_OFF(); // I2C_MPU_Init(); // MPU6050_Init(); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { USART_Configuration(); printf("\r\n****************************************************************\r\n"); printf("CAN-Bus Test \r\n"); printf("CAN-Bus Speed 100kHz \r\n"); CAN_Config(); NVIC_Config(); Open207_LEDInit(); /* Infinite loop */ while (1) { if( CanFlag == ENABLE ) { CanFlag = DISABLE; printf("CAN Receive Data \r\n"); printf("CAN ID %x \r\n",CAN_ID); printf("CAN_DATA0 %x \r\n",CAN_DATA0); printf("CAN_DATA1 %x \r\n",CAN_DATA1); printf("CAN_DATA2 %x \r\n",CAN_DATA2); printf("CAN_DATA3 %x \r\n",CAN_DATA3); printf("CAN_DATA4 %x \r\n",CAN_DATA4); printf("CAN_DATA5 %x \r\n",CAN_DATA5); printf("CAN_DATA6 %x \r\n",CAN_DATA6); printf("CAN_DATA7 %x \r\n",CAN_DATA7); } CanWriteData(0xA5A5); if( Display ) { /*====LED-ON=======*/ GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED1); GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED2); GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED3); GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED4); } else { /*====LED-OFF=======*/ GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED1); GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED2); GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED3); GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED4); } Display = ~Display; Delay(); /* delay 200ms */ } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* NVIC configuration */ NVIC_Config(); /* Initialize LEDs mounted on EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize Key Button mounted on EVAL board */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* CAN configuration */ CAN_Config(); while(1) { while(STM_EVAL_PBGetState(BUTTON_KEY) == KEY_PRESSED) { if(ubKeyNumber == 0x4) { ubKeyNumber = 0x00; } else { LED_Display(++ubKeyNumber); TxMessage.Data[0] = ubKeyNumber; CAN_Transmit(CANx, &TxMessage); /* Wait until one of the mailboxes is empty */ while((CAN_GetFlagStatus(CANx, CAN_FLAG_RQCP0) !=RESET) || \ (CAN_GetFlagStatus(CANx, CAN_FLAG_RQCP1) !=RESET) || \ (CAN_GetFlagStatus(CANx, CAN_FLAG_RQCP2) !=RESET)); while(STM_EVAL_PBGetState(BUTTON_KEY) != KEY_NOT_PRESSED) { } } } } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* NVIC configuration ------------------------------------------------------*/ NVIC_Config(); /* Initialize LED1..LED4, Key and Sel Joystick Buttons mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_EXTI); /* Configure the SysTick Handler Priority: Preemption priority and subpriority */ NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), !PreemptionPriorityValue, 0)); while (1) { if(PreemptionOccured != 0) { /* Toggel The lED1 */ STM_EVAL_LEDToggle(LED1); /* Insert delay Time */ Delay(0x5FFFF); STM_EVAL_LEDToggle(LED2); Delay(0x5FFFF); STM_EVAL_LEDToggle(LED3); Delay(0x5FFFF); STM_EVAL_LEDToggle(LED4); Delay(0x5FFFF); } } }
void Serial_DMAConfig( SerialPort_T serial_port, char *pBuffer, uint16_t wBufferLen ) { assert(wBufferLen <= DC3_MAX_MSG_LEN); /* Enable the DMA clock */ RCC_AHB1PeriphClockCmd( a_UARTDMASettings[serial_port].dma_clk, ENABLE ); /* Set up Interrupt controller to handle USART DMA */ NVIC_Config( a_UARTDMASettings[serial_port].dma_irq_num, a_UARTDMASettings[serial_port].dma_irq_prio ); /* Copy over the buffer and index. TODO: maybe do this in the StartXfer()? */ a_UARTSettings[serial_port].indexTX = wBufferLen; MEMCPY( a_UARTSettings[serial_port].bufferTX, pBuffer, wBufferLen ); DMA_DeInit( a_UARTDMASettings[serial_port].dma_stream ); DMA_InitTypeDef DMA_InitStructure; DMA_InitStructure.DMA_Channel = a_UARTDMASettings[serial_port].dma_channel; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; // Transmit DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)a_UARTSettings[serial_port].bufferTX; DMA_InitStructure.DMA_BufferSize = (uint16_t)a_UARTSettings[serial_port].indexTX; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(a_UARTSettings[serial_port].usart)->DR; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init( a_UARTDMASettings[serial_port].dma_stream, &DMA_InitStructure ); /* Enable the USART Tx DMA request */ USART_DMACmd( a_UARTSettings[serial_port].usart, USART_DMAReq_Tx, ENABLE ); /* Enable DMA Stream Transfer Complete interrupt */ DMA_ITConfig( a_UARTDMASettings[serial_port].dma_stream, DMA_IT_TC, ENABLE ); }
/********************************************************************************************************** * 函 数 名: main * 功能说明: 标准c程序入口。 * 形 参:无 * 返 回 值: 无 **********************************************************************************************************/ int main(void) { // bsp_Init(); NVIC_Config(); USART_Config(); while(1) { while(RESET == USART_GetFlagStatus(USART1,USART_FLAG_TXE)); USART_SendData(USART1,'b'); while(RESET == USART_GetFlagStatus(USART1,USART_FLAG_TXE)); USART_SendData(USART1,'a'); //bsp_LedToggle(1); delay_second(); } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ RCC_Config(); NVIC_Config(); TIM_Config(); GPIO_Config(); //RCC->CR &= 0xfffffffe; while (1) { //GPIO_SetBits(GPIOA, GPIO_Pin_6); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { uint8_t initSuccess; uint8_t mpuData[14]; initSuccess = 0; NVIC_Config(); STM_EVAL_COMInit(); USART_Configuration(9600); USART_ITConfig(USART1,USART_IT_RXNE, ENABLE); initSuccess = MPU9250_Init(); while (initSuccess) { MPU9250_ReadValue(mpuData); USART_SendDataArray(USART1,mpuData); Delay(0xFFFF); } }
int main(void) { volatile unsigned long int i; int temperatura; unsigned char temperaturaTekst[8]={" 0,0 C\0"}; static const unsigned char stopienSymbol[8] = {0x06,0x09,0x09,0x06,0x00,0x00,0x00,0}; //symbol stopnia //konfiguracja systemu RCC_Config(); GPIO_Config(); NVIC_Config(); SPI_Config(); /*Tu nalezy umiescic ewentualne dalsze funkcje konfigurujace system*/ GPIO_ResetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); LCD_Initialize(); //Inicjalizacja wysietlacza LCD_SetUserChar(1, 1, stopienSymbol); //Umiesc symbol stopnia pod kodem =1 LCD_WriteCommand(HD44780_CLEAR); //Wyczysc wyswietlacz LCD_WriteText("Temp.:\0"); temperaturaTekst[5]=1; LCD_WriteTextXY(temperaturaTekst,7,0); //Wstaw do tekstu znak stopnia #define SPI_Mode_Slave_Mask ((unsigned short int)0xFEFB) //Maska pozwalajaca wyzerowac bity trybu pracy wprost w rejestrzez SPIx->CR1 while (1) { /*Tu nalezy umiescic glowny kod programu*/ SPI1->CR1 |= SPI_Mode_Master; //Ustaw tryb master - wymusi to zmiane stanu NSS na niski while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); //Czekaj na dane temperatura = SPI_I2S_ReceiveData(SPI1); //Odczytaj dane if ((temperatura&0x04)==0){ //Sprawdz, czy zakonczono juz pierwszy pomiar po wlaczeniu ukladu TC77 temperatura=0; //Jesli nie, ustaw temp=0, wprzeciwnym razie wynik bedzie bledny (>500stC) } temperatura = temperatura >> 3; //Usun 3 LSB SPI1->CR1 &= SPI_Mode_Slave_Mask; //Ustaw tryb slave - wymusi to zmiane stanu NSS na wysoki temperatura = (temperatura * 625)/100; //1 bit temperatury odpowiada 0,0625 stopnia sprintf((char *)temperaturaTekst, "%2d,%d C ", temperatura / 100, (temperatura % 100)/10 ); temperaturaTekst[4]=1; //Wstaw do tekstu znak stopnia LCD_WriteTextXY(temperaturaTekst,7,0); for (i=0;i<4500000ul;i++); GPIO_WriteBit(GPIOB, GPIO_Pin_15, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_15))); }; return 0; }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ RCC_Config(); NVIC_Config(); GPIO_Config(); UART_Config(); while (1) { //USART_SendByte('0'); asm("nop"); } }
/* ------------------------------------------------------------------------- * 函数名称: * 函数功能: * 输入形参: * 返回值: --------------------------------------------------------------------------- */ void Board_Init(void) { //系统时钟配置 SystemInit(); //延时函数初始化 delay_init(72); //定时器1初始化 TIM1_config(); //舵机初始化 Servo_Init(); //串口配置 USART_Config(); //串口中断配置 NVIC_Config(); //LED初始化 LED_Init(); //按键初始化 KEY_Init(); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* NVIC configuration */ NVIC_Config(); /* USART configuration */ USART_Config(); /* Enable the EVAL_COM1 Transmit interrupt: this interrupt is generated when the EVAL_COM1 transmit data register is empty */ USART_ITConfig(EVAL_COM1, USART_IT_TXE, ENABLE); /* Wait until EVAL_COM1 send the TxBuffer */ while(ubTxCounter < ubNbrOfDataToTransfer) {} /* The software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the last frame’s end of transmission*/ while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET) {} /* Enable the EVAL_COM1 Receive interrupt: this interrupt is generated when the EVAL_COM1 receive data register is not empty */ USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); /* Wait until EVAL_COM1 receive the RxBuffer */ while(uhRxCounter < ubNbrOfDataToRead) {} while (1) { } }
//Function to intialise the UART to allow transmission to PC and enable interrupts to detect messages receievd from PC void UART_init(void) { USART_InitTypeDef USART_InitStructure; //Enable periph clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //Configure required pins as UART TX/RX GPIO_Config(); //NVIC_Config(); //USART configuration values USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8 bit bytes USART_InitStructure.USART_StopBits = USART_StopBits_1; //one stop bit USART_InitStructure.USART_Parity = USART_Parity_No; //no parity bit USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware flow control //USART_InitStructure.USART_Mode = USART_Mode_Tx; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Enable USART for transmit and receive USART_Init(USART1, &USART_InitStructure); //Enable interrupts for RX USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //USART_ITConfig(USART2, USART_IT_TXE, ENABLE); USART_ClearITPendingBit(USART1, USART_IT_RXNE); //Conigure Nested Vectored INterrupt Controller to accept USART inerrupts NVIC_Config(); //Clear TXE flag (which indicates when transmit buffer is empty) USART_ClearFlag(USART1, USART_FLAG_TXE); //Enable UART USART_Cmd(USART1, ENABLE); }
void Tim2_Init() { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //基础设置,时基和比较输出设置,由于这里只需定时,所以不用OC比较输出 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); TIM_DeInit(TIM2); NVIC_Config(); TIM_TimeBaseStructure.TIM_Period=500;//装载值 //prescaler is 1200,that is 72000000/72/500=2000Hz; TIM_TimeBaseStructure.TIM_Prescaler=72-1;//分频系数 //set clock division TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; //or TIM_CKD_DIV2 or TIM_CKD_DIV4 //count up TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure); //clear the TIM2 overflow interrupt flag TIM_ClearFlag(TIM2,TIM_FLAG_Update); //TIM2 overflow interrupt enable TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); //enable TIM2 TIM_Cmd(TIM2,ENABLE); }
int main(void) { //uint16_t kezdet, vege; vSemaphoreCreateBinary(xADCSemaphore); RCC_Config(); IO_Init(); UART_Config(); PWM_Config(); DMA_Config(); I2C_Config(); NVIC_Config(); DebugTimerInit(); xTaskCreate(prvInitTask,(signed char*)"INIT", configMINIMAL_STACK_SIZE,NULL,TASK_INIT_PRIORITY,NULL); vTaskStartScheduler(); while (1) { } }
void board_init(void) { uint64_t i; #if 1 app_wdg_init(); app_wdg_start(); #endif NVIC_Config(); //SystemInit(); /*外部是12MHz振荡器,所以应该是108MHz系统频率*/ #if defined(DouLunJi_AIS_BASE_STATION_V1_0_130513_) || defined(DouLunJi_CAR_GBC_V1_2_130511_) || defined(DouLunJi_CAR_TRUCK_1_3_140303_) || defined(CAR_TRUCK_1_5_140325_) || defined(HC_CONTROLER_) app_zgb_init(); #endif #if defined(HC_CONTROLER_) app_zgb2_init(); #endif driv_systick_init(); app_usart_init(); #if defined (CAR_DB44_V1_0_20130315_) app_speed_init(); #endif // app_rtc_init(); #if defined(CAR_DB44_V1_0_20130315_) || defined(DouLunJi_CAR_GBC_V1_2_130511_) || defined(DouLunJi_AIS_BASE_STATION_V1_0_130513_) || defined(DouLunJi_CAR_TRUCK_1_3_140303_) || defined(CAR_TRUCK_1_5_140325_) || defined(CAR_TRUCK_1_3_140303_) app_gprs_init(); #endif #if defined(CAR_DB44_V1_0_20130315_) || defined(DouLunJi_CAR_GBC_V1_2_130511_) || defined(DouLunJi_AIS_BASE_STATION_V1_0_130513_) || defined(DouLunJi_CAR_TRUCK_1_3_140303_) || defined(CAR_TRUCK_1_5_140325_) || defined(CAR_TRUCK_1_3_140303_) app_gps_init(); #endif #if defined (CAR_DB44_V1_0_20130315_) app_key_init(); #endif #if defined (CAR_DB44_V1_0_20130315_) app_beep_init(); #endif /* i = ticks; i += 1*HZ; while (i > ticks) ; */ #if defined (CAR_DB44_V1_0_20130315_) app_lcd_init(); #endif /* i = ticks; i += 5*HZ; while (i > ticks) ; */ #if defined (CAR_DB44_V1_0_20130315_) || defined(HC_CONTROLER_) app_voice_init(); #endif #if defined (CAR_DB44_V1_0_20130315_) app_rfid_init(); #endif #if (defined(CAR_DB44_V1_0_20130315_) || defined(DouLunJi_CAR_GBC_V1_2_130511_) || defined(DouLunJi_AIS_BASE_STATION_V1_0_130513_) || defined(DouLunJi_CAR_TRUCK_1_3_140303_) || defined(CAR_TRUCK_1_5_140325_)) app_hmc5883l_bmp085_init(); #endif #if defined(CAR_TRUCK_1_5_140325_) || defined(CAR_TRUCK_1_3_140303_) app_vc0706_init(); #endif #if defined(HC_CONTROLER_) app_net_usart_init(); #endif #if defined(HC_CONTROLER_) app_ir_init(); #endif #if defined(HC_CONTROLER_) app_coil_init(); #endif #if defined(HC_CONTROLER_) app_weighbridge_init(); #endif #if defined(HC_CONTROLER_) app_red_green_init(); #endif #if defined(HC_CONTROLER_) app_cpu_id_init(); #endif }
/** * @brief Main program. * @param None * @retval None */ int main(void) { uint8_t error_can=0; USART_Configuration(); printf("\r\nCAN-Bus Test \r\n"); printf("CAN-Bus Speed 100kHz \r\n"); printf("Please click USER key.\r\n"); Key_Config(); CAN1_Config(); CAN2_Config(); NVIC_Config(); /* Infinite loop */ while (1) { while(GPIO_ReadInputDataBit(USER_KEY_Port,USER_KEY_Pin)); Can1WriteData(0x123); while( Can2Flag == DISABLE ); Can2Flag = DISABLE; printf("CAN2 Receive Data \r\n"); printf("CAN2 ID %x \r\n",CAN2_ID); printf("CAN2_DATA0 %x \r\n",CAN2_DATA0); printf("CAN2_DATA1 %x \r\n",CAN2_DATA1); printf("CAN2_DATA2 %x \r\n",CAN2_DATA2); printf("CAN2_DATA3 %x \r\n",CAN2_DATA3); printf("CAN2_DATA4 %x \r\n",CAN2_DATA4); printf("CAN2_DATA5 %x \r\n",CAN2_DATA5); printf("CAN2_DATA6 %x \r\n",CAN2_DATA6); printf("CAN2_DATA7 %x \r\n",CAN2_DATA7); if(CAN2_ID!=0x123 || CAN2_DATA0!=CAN1_DATA0 || CAN2_DATA1!=CAN1_DATA1 || CAN2_DATA2!=CAN1_DATA2 || CAN2_DATA3!=CAN1_DATA3 || CAN2_DATA4!=CAN1_DATA4 || CAN2_DATA5!=CAN1_DATA5 || CAN2_DATA6!=CAN1_DATA6 || CAN2_DATA7!=CAN1_DATA7 ) {printf("CAN1 发送或者CAN2 接收有问题\r\n");error_can=1;} Can2WriteData(0x321); while( Can1Flag == DISABLE ); Can1Flag = DISABLE; printf("CAN1 Receive Data \r\n"); printf("CAN1 ID %x \r\n",CAN1_ID); printf("CAN1_DATA0 %x \r\n",CAN1_DATA0); printf("CAN1_DATA1 %x \r\n",CAN1_DATA1); printf("CAN1_DATA2 %x \r\n",CAN1_DATA2); printf("CAN1_DATA3 %x \r\n",CAN1_DATA3); printf("CAN1_DATA4 %x \r\n",CAN1_DATA4); printf("CAN1_DATA5 %x \r\n",CAN1_DATA5); printf("CAN1_DATA6 %x \r\n",CAN1_DATA6); printf("CAN1_DATA7 %x \r\n",CAN1_DATA7); if(CAN1_ID!=0x321 || CAN1_DATA0!=CAN2_DATA0 || CAN1_DATA1!=CAN2_DATA1 || CAN1_DATA2!=CAN2_DATA2 || CAN1_DATA3!=CAN2_DATA3 || CAN1_DATA4!=CAN2_DATA4 || CAN1_DATA5!=CAN2_DATA5 || CAN1_DATA6!=CAN2_DATA6 || CAN1_DATA7!=CAN2_DATA7 ) {printf("CAN2 发送或者CAN1 接收有问题\r\n");error_can=1;} while(!GPIO_ReadInputDataBit(USER_KEY_Port,USER_KEY_Pin)); if(error_can==0){printf("CAN1 CAN2正常!\r\n");} } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* NVIC configuration */ NVIC_Config(); /* Configures LED 1..4 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* LCD Initialization */ STM3210C_LCD_Init(); LCD_Clear(LCD_COLOR_WHITE); /* Set the LCD Back Color */ LCD_SetBackColor(LCD_COLOR_RED); /* Set the LCD Text Color */ LCD_SetTextColor(LCD_COLOR_GREEN); LCD_DisplayStringLine(LCD_LINE_0, " STM3210C-EVAL "); LCD_DisplayStringLine(LCD_LINE_1, " STM32F10x Dual CAN "); LCD_DisplayStringLine(LCD_LINE_2, "To start Press on: "); LCD_DisplayStringLine(LCD_LINE_3, "Key or Tamper Button"); /* Set the LCD Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); #if CAN_BAUDRATE == 1000 /* 1MBps */ LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 1MBps "); #elif CAN_BAUDRATE == 500 /* 500KBps */ LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 500kBps "); #elif CAN_BAUDRATE == 250 /* 250KBps */ LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 250kBps "); #elif CAN_BAUDRATE == 125 /* 125KBps */ LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 125kBps "); #elif CAN_BAUDRATE == 100 /* 100KBps */ LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 100kBps "); #elif CAN_BAUDRATE == 50 /* 50KBps */ LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 50kBps "); #elif CAN_BAUDRATE == 20 /* 20KBps */ LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 20kBps "); #elif CAN_BAUDRATE == 10 /* 10KBps */ LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 10kBps "); #endif /* Set the LCD Text Color */ LCD_SetTextColor(LCD_COLOR_WHITE); /* Configure BUTTON_KEY */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* Configure BUTTON_TAMPER */ STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); /* CANs configuration */ CAN_Config(); /* IT Configuration for CAN1 */ CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); /* IT Configuration for CAN2 */ CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE); /* turn off all leds*/ STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); /* Infinite loop */ while(1) { if(STM_EVAL_PBGetState(BUTTON_KEY)== RESET) { /* Turn On LED1 */ LED_Display(0x01); TxMessage.Data[0] = 0x55; CAN_Transmit(CAN1, &TxMessage); /* Loop while KEY button is pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY)== RESET) { } } if(STM_EVAL_PBGetState(BUTTON_TAMPER)== RESET) { /* Turn On LED2 */ LED_Display(0x2); TxMessage.Data[0] = 0xAA; CAN_Transmit(CAN2, &TxMessage); /* Loop while TAMPER button is pressed */ while(STM_EVAL_PBGetState(BUTTON_TAMPER)== RESET) { } } } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ uint32_t index = 0; /* NVIC Configuration */ NVIC_Config(); /* Initialize the LCD */ STM320518_LCD_Init(); /* Initialize the Temperature Sensor */ LM75_Init(); if (LM75_GetStatus() == SUCCESS) { /* Clear the LCD */ LCD_Clear(LCD_COLOR_WHITE); /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_GREEN); LCD_DisplayStringLine(LCD_LINE_0, " Temperature "); /* Configure the Temperature sensor device STLM75: - Thermostat mode Interrupt - Fault tolerance: 00 */ LM75_WriteConfReg(0x02); /* Configure the THYS and TOS in order to use the SMbus alert interrupt */ LM75_WriteReg(LM75_REG_THYS, TEMPERATURE_THYS << 8); /*31°C*/ LM75_WriteReg(LM75_REG_TOS, TEMPERATURE_TOS << 8); /*32°C*/ /* Enables the I2C SMBus Alert feature */ I2C_SMBusAlertCmd(LM75_I2C, ENABLE); I2C_ClearFlag(LM75_I2C, I2C_FLAG_ALERT); SMbusAlertOccurred = 0; /* Enable SMBus Alert interrupt */ I2C_ITConfig(LM75_I2C, I2C_IT_ERRI, ENABLE); /* Infinite Loop */ while (1) { /* Get double of Temperature value */ TempValue = LM75_ReadTemp(); if (TempValue <= 256) { /* Positive temperature measured */ TempCelsiusDisplay[7] = '+'; /* Initialize the temperature sensor value*/ TempValueCelsius = TempValue; } else { /* Negative temperature measured */ TempCelsiusDisplay[7] = '-'; /* Remove temperature value sign */ TempValueCelsius = 0x200 - TempValue; } /* Calculate temperature digits in °C */ if ((TempValueCelsius & 0x01) == 0x01) { TempCelsiusDisplay[12] = 0x05 + 0x30; TempFahrenheitDisplay[12] = 0x05 + 0x30; } else { TempCelsiusDisplay[12] = 0x00 + 0x30; TempFahrenheitDisplay[12] = 0x00 + 0x30; } TempValueCelsius >>= 1; TempCelsiusDisplay[8] = (TempValueCelsius / 100) + 0x30; TempCelsiusDisplay[9] = ((TempValueCelsius % 100) / 10) + 0x30; TempCelsiusDisplay[10] = ((TempValueCelsius % 100) % 10) + 0x30; if (TempValue > 256) { if (((9 * TempValueCelsius) / 5) <= 32) { /* Convert temperature °C to Fahrenheit */ TempValueFahrenheit = abs (32 - ((9 * TempValueCelsius) / 5)); /* Calculate temperature digits in °F */ TempFahrenheitDisplay[8] = (TempValueFahrenheit / 100) + 0x30; TempFahrenheitDisplay[9] = ((TempValueFahrenheit % 100) / 10) + 0x30; TempFahrenheitDisplay[10] = ((TempValueFahrenheit % 100) % 10) + 0x30; /* Positive temperature measured */ TempFahrenheitDisplay[7] = '+'; } else { /* Convert temperature °C to Fahrenheit */ TempValueFahrenheit = abs(((9 * TempValueCelsius) / 5) - 32); /* Calculate temperature digits in °F */ TempFahrenheitDisplay[8] = (TempValueFahrenheit / 100) + 0x30; TempFahrenheitDisplay[9] = ((TempValueFahrenheit % 100) / 10) + 0x30; TempFahrenheitDisplay[10] = ((TempValueFahrenheit % 100) % 10) + 0x30; /* Negative temperature measured */ TempFahrenheitDisplay[7] = '-'; } } else { /* Convert temperature °C to Fahrenheit */ TempValueFahrenheit = ((9 * TempValueCelsius) / 5) + 32; /* Calculate temperature digits in °F */ TempFahrenheitDisplay[8] = (TempValueFahrenheit / 100) + 0x30; TempFahrenheitDisplay[9] = ((TempValueFahrenheit % 100) / 10) + 0x30; TempFahrenheitDisplay[10] = ((TempValueFahrenheit % 100) % 10) + 0x30; /* Positive temperature measured */ TempFahrenheitDisplay[7] = '+'; } /* Display Fahrenheit value on LCD */ for (index = 0; index < 20; index++) { LCD_DisplayChar(LCD_LINE_6, (319 - (16 * index)), TempCelsiusDisplay[index]); LCD_DisplayChar(LCD_LINE_7, (319 - (16 * index)), TempFahrenheitDisplay[index]); } if (SMbusAlertOccurred == 1) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_RED); LCD_DisplayStringLine(LCD_LINE_2, "Warning: Temp exceed"); LCD_DisplayStringLine(LCD_LINE_3, " 32 C "); } if (SMbusAlertOccurred == 2) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_WHITE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_WHITE); LCD_ClearLine(LCD_LINE_2); LCD_ClearLine(LCD_LINE_3); SMbusAlertOccurred = 0; /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_GREEN); } } }