/** * @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_stm32l1xx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* System Clocks Configuration */ RCC_Config(); /* LCD GLASS Initialization */ LCD_GLASS_Init(); #ifdef USE_STM32L152D_EVAL LCD_GLASS_DisplayLogo(ENABLE); #endif /*Display " STM32L15 " string on LCD glass in scrolling mode*/ LCD_GLASS_ScrollString(LCD_String, SCROLL_NUM, SCROLL_SPEED); /* Infinite loop */ while (1) { } }
void Peripheral_Config(void) { RCC_Config(); GPIO_Config(); USART_Config(); TIM_Config(); DMA_Config(); }
int main(void) { int j; //uint16_t p16; //uint8_t p8; RCC_Config(); GPIO_Config(); ADC_Config(); T_UART_Init(); // start conversion ADC_Cmd (ADC1, ENABLE); //enable ADC1 ADC_SoftwareStartConvCmd(ADC1, ENABLE); // start conversion (will be endless as we are in continuous mode) USART_SendData(USART2, 0xAF); j = 50000; while(1) { GPIO_SetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9); Delay(100000); GPIO_ResetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9); Delay(100000); j = ADC_GetConversionValue(ADC1); // value from 0 to 4095000 //p16 = 0x1234; //p8 = (uint8_t)(p16>>8); USART_SendData(USART2, (uint8_t)(j>>4)); } }
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); } }
/**************************************************** 函数功能:延时初始化 输入参数:SYSCLK : 系统时钟(168)MHZ 输出参数:无 备 注:无 *****************************************************/ void Delay_Init(u8 SYSCLK) { RCC_Config(); SysTick->CTRL =0x00000005;//选择外部时钟(HCLK,no PreSC) //SysTick->CTRL &=~BIT(1);//关闭定时器减到0后的中断请求 fac_us = SYSCLK;//计算好SysTick加载值 fac_ms = (u16)fac_us*1000; }
/******************************************************************************* * Function Name : Set_System * Description : Configures Main system clocks & power * Input : None. * Return : None. *******************************************************************************/ void Set_System(void) { /* RCC configuration */ RCC_Config(); GPIO_Config(); /* MAL configuration */ MAL_Config(); }
/*系统初始化*/ void Init_sys(void) { RCC_Config(); NVIC_Config(); GPIO_Config(); USART_Config(); SPI_Config(SPI1); app_tim(); //应用程序的定时器配置 }
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; }
/******************************************************************************* * Function Name : Set_System * Description : Configures Main system clocks & power * Input : None. * Return : None. *******************************************************************************/ void Set_System(void) { /* RCC configuration */ RCC_Config(); /* Enable and GPIOD clock */ USB_Disconnect_Config(); /* MAL configuration */ MAL_Config(); }
/* * System setup */ void Set_System(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_Config(); /* Configure PC.13 as Output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); }
/******************************************************************************* * Function Name : Set_System * Description : Configures Main system clocks & power * Input : None. * Return : None. *******************************************************************************/ void Set_System(void) { /* RCC configuration */ RCC_Config(); #if defined (USE_STM3210B_EVAL) || defined (USE_STM3210E_EVAL) /* Enable and Disconnect Line GPIO clock */ USB_Disconnect_Config(); #endif /* (USE_STM3210B_EVAL) || (USE_STM3210E_EVAL) */ /* MAL configuration */ MAL_Config(); }
/** * @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); } }
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"); } }
int main(void) { HAL_Init(); SystemClock_Config(); RCC_Config(); GPIO_Config(); UART_Config(); if (SysTick_Config(SystemCoreClock / 1000)) { error_handler(); } log_init(LOGLEVEL_INFO); log_info("PROJECT STERTED"); while (1) { led_toggle(LED_BLUE); log_info("Hello! :)"); HAL_Delay(DELAY); } }
/** * @brief Description 外设初始化 * @param None * @retval None */ void PeripheralInit(void) { RCC_Config(); SysTick_Init(); TIM2_Configuration(); LED_GPIO_Config(); KEY_GPIO_Config(); EXTI15_10_Config(); General_GPIO_Config(); LCD_GLASS_Init(); USART1_Config(115200); // Delay_ms(10); //开启滴答定时 LCD_GLASS_Clear(); AVCC1_POWER(OFF); //关ADC1电源 BATTEST_POWER(OFF); //关电池电压检测电源 MODEL_PWRCTRL(ON); //开对外接口电源 ADC1_Init(); /* 8M串行flash W25Q64初始化 */ SPI_FLASH_Init(); I2C_GPIO_Config(); //rtc 初始化 rtc_init(); }
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) { } }
__noreturn main() { RCC_Config(); //I2C_Enable(); SPI_Enable(); GPIO_Enable(); //ADC_Enable(); MTouchInit(); MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1,OUT_CH0_MODER,IN_CH0_MODER,AN_CH0_MODER);// sensor #0 MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1,OUT_CH1_MODER,IN_CH1_MODER,AN_CH1_MODER);// sensor #1 MTouchSetSensor(2, CH2_TRIS, CH2_LAT, CH2_IO_BIT, CH2_AN_NUM, -1, -1, -1,OUT_CH2_MODER,IN_CH2_MODER,AN_CH2_MODER);// sensor #2 MTouchSetSensor(3, CH3_TRIS, CH3_LAT, CH3_IO_BIT, CH3_AN_NUM, -1, -1, -1,OUT_CH3_MODER,IN_CH3_MODER,AN_CH3_MODER);// sensor #3 // thr ovs cd MTouchSetButton(0, 0, DECODE_PRESS_RELEASE|DECODE_ONE_EVENT); MTouchSetButton(1, 1, DECODE_PRESS_RELEASE|DECODE_ONE_EVENT); MTouchSetButton(2, 2, DECODE_PRESS_RELEASE|DECODE_ONE_EVENT); MTouchSetButton(3, 3, DECODE_PRESS_RELEASE|DECODE_ONE_EVENT); Timers_init(); #ifdef __MOD_BUS_ENABLE__ eMBMasterInit(MB_RTU, 2, 38400, MB_PAR_NONE); eMBMasterEnable(); #endif /*__MOD_BUS_ENABLE__*/ __enable_irq(); //*******************Потом заменим на чтение из EEPROM******************* up_led(1); bottom_led(0); chasy_led_string("er"); minuty_led_string("r"); Indic_struct.colon = False; //************************************************************************ while (1) { #ifdef __MOD_BUS_ENABLE__ eMBMasterPoll(); #endif /*__MOD_BUS_ENABLE__*/ #ifdef __SENSOR_KEYS__ MTouchDecode(); #endif /*__SENSOR_KEYS__*/ #ifdef __TOUCH_DEBUG__ up_led(buttons[0].pSensor->delta/10); chasy_led(buttons[1].pSensor->delta/10); minuty_led(buttons[2].pSensor->delta/10); bottom_led(buttons[3].pSensor->delta/10); if(buttons[0].curState == 0x01){Indic_struct.k4 = True;} else {Indic_struct.k4 = False;}; if(buttons[1].curState == 0x01){Indic_struct.k3 = True;} else {Indic_struct.k3 = False;}; if(buttons[2].curState == 0x01){Indic_struct.k2 = True;} else {Indic_struct.k2 = False;}; if(buttons[3].curState == 0x01){Indic_struct.k1 = True;} else {Indic_struct.k1 = False;}; #endif /*__TOUCH_DEBUG__*/ // if (o < 7 ) {o++;} else {/*o = 0;*/}; // switch(o) // { // case 0: // Indic_struct.k1 = True; // break; // case 1: // Indic_struct.k2 = True; // break; // case 2: // Indic_struct.k3 = True; // break; // case 3: // Indic_struct.k4 = True; // break; // case 4: // Indic_struct.red_bottom = True; // break; // case 5: // //Indic_struct.minus = True; // break; // case 6: // Indic_struct.red_up = True; // break; // case 100: // Indic_struct.k1 = False; // Indic_struct.k2 = False; // Indic_struct.k3 = False; // Indic_struct.k4 = False; // Indic_struct.red_bottom = False; // Indic_struct.minus = False; // Indic_struct.red_up = False; // break; // default: // break; // }; // // for(uint16_t f=0;f<60000;f++){ for(uint16_t f=0;f<50;f++){};}; // // Indic_struct.minuty++; // // // // //Indic_struct.blink_chasy = True; // Indic_struct.blink_k2 = True; // Indic_struct.blink_minus = False; // //Indic_struct.blink_minuty = True; // Indic_struct.blink_verhniy_indicator = True; // Indic_struct.blink_colon = True; }; //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 */ /* Configure Clocks */ RCC_Config(); /* Initialize LEDs, Key Button and LCD available on STM320518-EVAL board *****************************************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ STM320518_LCD_Init(); /* Display message on LCD ***********************************************/ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(Yellow); LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); /* Set the LCD Back Color */ LCD_SetBackColor(White); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); /* Configure the Push buttons in Polling mode */ STM_EVAL_PBInit(BUTTON_KEY, Mode_GPIO); /* if STM32 device is set as Master */ #ifdef I2C_MASTER /* Configure and enable the systick timer to generate an interrupt each 1 ms */ SysTick_Config((SystemCoreClock / 1000)); /* Deinitialize I2Cx Device */ CPAL_I2C_DeInit(&MASTERSTRUCTURE); /* Initialize CPAL I2C structure parameters values */ CPAL_I2C_StructInit(&MASTERSTRUCTURE); #ifdef CPAL_I2C_DMA_PROGMODEL MASTERSTRUCTURE.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_DMATX_TCIT; MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA; #elif defined (CPAL_I2C_IT_PROGMODEL) MASTERSTRUCTURE.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR; MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT; #else #error "Please select one of the programming model (in main.h)" #endif /* Set I2C Speed */ MASTERSTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = MASTER_I2C_TIMING; /* Select Master Mode */ MASTERSTRUCTURE.CPAL_Mode = CPAL_MODE_MASTER; /* Initialize I2Cx Device*/ CPAL_I2C_Init(&MASTERSTRUCTURE); /* Infinite loop */ while(1) { /* Initialize Transfer parameters */ MASTERSTRUCTURE.pCPAL_TransferTx = &sTxStructure; sTxStructure.wNumData = BufferSize; sTxStructure.pbBuffer = (uint8_t*)BufferTX; sTxStructure.wAddr1 = OWNADDRESS; /* Update LCD Display */ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(Line8, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line5, MESSAGE4); LCD_DisplayStringLine(Line6, MESSAGE5); /* wait until Key button is pushed */ while(STM_EVAL_PBGetState(BUTTON_KEY)); /* Update LCD Display */ LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line6, MEASSAGE_EMPTY); /* Write operation */ CPAL_I2C_Write(&MASTERSTRUCTURE); /* Wait until communication finishes */ while ((MASTERSTRUCTURE.CPAL_State != CPAL_STATE_READY) && (MASTERSTRUCTURE.CPAL_State != CPAL_STATE_ERROR)); if (TransferStatus == PASSED) { /* Update LCD Display */ LCD_SetBackColor(Red); LCD_SetTextColor(White); LCD_DisplayStringLine(Line8, MESSAGE6); } else { TransferStatus = PASSED; } Delay(1000); } #endif /* I2C_MASTER */ /* if STM32 device is set as Slave */ #ifdef I2C_SLAVE /* GPIOA Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Output System Clock on MCO pin (PA.08) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_MCOConfig(RCC_MCOSource_SYSCLK); /* Deinitialize I2Cx Device */ CPAL_I2C_DeInit(&SLAVESTRUCTURE); /* Initialize CPAL I2C structure parameters values */ CPAL_I2C_StructInit(&SLAVESTRUCTURE); #ifdef CPAL_I2C_DMA_PROGMODEL SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP | CPAL_OPT_DMARX_TCIT; SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA; #elif defined (CPAL_I2C_IT_PROGMODEL) SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP; SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT; #else #error "Please select one of the programming model (in main.h)" #endif /* Configure Own address 1 */ SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_OwnAddress1 = OWNADDRESS; /* Set I2C Speed */ SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = SLAVE_I2C_TIMING; /* Select Slave Mode */ SLAVESTRUCTURE.CPAL_Mode = CPAL_MODE_SLAVE; /* Initialize I2Cx Device*/ CPAL_I2C_Init(&SLAVESTRUCTURE); /* Infinite loop */ while(1) { /* Reset BufferRX value */ Reset_bBuffer(BufferRX, (uint16_t)BufferSize); /* Initialize Transfer parameters */ SLAVESTRUCTURE.pCPAL_TransferRx = &sRxStructure; sRxStructure.wNumData = BufferSize; sRxStructure.pbBuffer = (uint8_t*)BufferRX; /* Update LCD Display */ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(Line8, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line5, MESSAGE7); Delay(1000); /* Update LCD Display */ LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line6, MESSAGE8); /* Read operation */ CPAL_I2C_Read(&SLAVESTRUCTURE); /* Enter Stop Mode and wait for interrupt to wake up */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Wait until communication finishes */ while ((SLAVESTRUCTURE.CPAL_State != CPAL_STATE_READY) && (SLAVESTRUCTURE.CPAL_State != CPAL_STATE_ERROR)); /* Configure SystemClock*/ RestoreConfiguration(); /* Configure and enable the systick timer to generate an interrupt each 1 ms */ SysTick_Config((SystemCoreClock / 1000)); /* Update LCD Display */ LCD_DisplayStringLine(Line6, MEASSAGE_EMPTY); LCD_SetBackColor(Red); LCD_SetTextColor(White); LCD_DisplayStringLine(Line8, MESSAGE9); /* If are received correctly */ if (Compare_bBuffer((uint8_t*)BufferTX, BufferRX, BufferSize) == PASSED ) { /* Update LCD Display */ LCD_DisplayStringLine(Line9, MESSAGE6); } else { /* Update LCD Display */ LCD_DisplayStringLine(Line9, MESSAGE10); } Delay(1500); } #endif /* I2C_SLAVE */ }
/**************************************************************/ //程 序 名: main() //开 发 者: MingH //入口参数: 无 //功能说明: 主函数 //**************************************************************/ int main(void) { unsigned char err_code; RCC_Config(); // 时钟初始化配置 Beep_Init(); // 蜂鸣器初始化配置 Touch_Init(); Pcie_Gpio_Init(); Tim3_Init(); RGB_Init(); //RGB 初始化 RCC_GetClocksFreq(&RCC_ClockFreq); SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); USB2Serial_Init(); // 串口初始化配置 Pwm_Init(); Adc_Init(); I2C_GPIO_Configuration(); err_code = LIS3DH_Init(); if (NO_ERROR == err_code) { printf("\r\nLIS3DH Init is succeed! \r\n"); } else { printf("\r\nLIS3DH Init is failed! \r\n"); } RTC_Init(); // RTC 初始化配置 if(SD_Init() == SD_OK) { printf ("\r\n发现SD卡!\r\n"); } else { printf("\r\n没有发现 SD 卡设备! \r\n"); } printf("\r\n\r\n"); save_sd_detect = SD_Detect(); //初始化SD卡插入状态 SysTick_Delay_ms(500); TIM_Cmd(TIM1, DISABLE); TIM_CtrlPWMOutputs(TIM1, DISABLE); while (1) { if(read_sd_detect_flag){ if (save_sd_detect != SD_Detect()){ /* 蜂鸣器响 */ TIM_Cmd(TIM1, ENABLE); TIM_CtrlPWMOutputs(TIM1, ENABLE); sd_detect_change = 1; //SD卡插入状态有变 buzzer_delay = 0; if (SD_Detect() != SD_NOT_PRESENT){ if(SD_Init() == SD_OK) { printf ("\r\n发现SD卡!\r\n"); } else { printf("\r\n没有发现 SD 卡设备! \r\n"); } printf("\r\n\r\n"); } } save_sd_detect = SD_Detect(); read_sd_detect_flag = 0; } Time_Show(); Test_Pcie_Gpio(); Touch_Key_Proc(); if (read_lis3dh_flag){ Collect_Data(ACCdata); for (i=0; i<3; i++){ if (oldACCdata[i] < ACCdata[i]){ ACCdiff[i] = ACCdata[i] - oldACCdata[i]; } else{ ACCdiff[i] = oldACCdata[i] - ACCdata[i]; } } RGB_Control(ACCdiff[0]<<1, ACCdiff[1]<<1, ACCdiff[2]<<1); for (i=0; i<3; i++){ oldACCdata[i] = ACCdata[i]; } read_lis3dh_flag = 0; } if (one_second_flag){ printf("X=%d, Y=%d, Z=%d\r\n\r\n", ACCdata[1], ACCdata[0], ACCdata[2]); Adc_Proc(); one_second_flag = 0; } } }
/** * @brief Main program * @param None * @retval None */ int main(void) { __IO uint16_t i; __IO uint16_t *ptr; __IO uint16_t tmp1; __IO uint16_t tmp2; uint32_t scpcnt; uint32_t scpwait; uint32_t scptpos; /* RCC Configuration */ RCC_Config(); /* GPIO Configuration */ GPIO_Config(); /* TIM Configuration */ TIM_Config(); /* NVIC Configuration */ NVIC_Config(); /* DAC Configuration */ DAC_Config(); /* SPI Configuration */ SPI_Config(); /* USART Configuration */ USART_Config(115200); /* Calibrate LC Meter */ LCM_Calibrate(); // /* Update bluetooth baudrate */ // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount); // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount); // USART3_puts("AT\0"); // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount) // { // if ((USART3->SR & USART_FLAG_RXNE) != 0) // { // STM32_CMD.BTBuff[i] = USART3->DR; // i++; // } // } // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount); // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount); // USART3_puts("AT+BAUD8\0"); // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount) // { // if ((USART3->SR & USART_FLAG_RXNE) != 0) // { // STM32_CMD.BTBuff[i] = USART3->DR; // i++; // } // } // while (1) // { // } while (1) { USART3_getdata((uint8_t *)&STM32_CMD.Cmd,4); switch (STM32_CMD.Cmd) { case CMD_LCMCAL: LCM_Calibrate(); USART3_putdata((uint8_t *)&STM32_CMD.STM32_LCM.FrequencyCal0,sizeof(STM32_LCMTypeDef)); break; case CMD_LCMCAP: GPIO_ResetBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); USART3_putdata((uint8_t *)&STM32_CMD.STM32_LCM.FrequencyCal0,sizeof(STM32_LCMTypeDef)); break; case CMD_LCMIND: GPIO_ResetBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_6); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); USART3_putdata((uint8_t *)&STM32_CMD.STM32_LCM.FrequencyCal0,sizeof(STM32_LCMTypeDef)); break; case CMD_FRQCH1: GPIO_ResetBits(GPIOD, GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_0); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); break; case CMD_FRQCH2: GPIO_ResetBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_1); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); break; case CMD_FRQCH3: GPIO_ResetBits(GPIOD, GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_1); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); break; case CMD_SCPSET: USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); USART3_getdata((uint8_t *)&STM32_CMD.STM32_SCP.ADC_Prescaler,sizeof(STM32_SCPTypeDef)); /* Scope magnify */ i = (STM32_CMD.STM32_SCP.ScopeMag & 0x07) << 3; GPIO_SetBits(GPIOE,(i ^ 0x38)); GPIO_ResetBits(GPIOE,i); /* Set V-Pos */ DAC_SetChannel1Data(DAC_Align_12b_R, STM32_CMD.STM32_SCP.ScopeVPos); /* Set Trigger level */ DAC_SetChannel2Data(DAC_Align_12b_R, STM32_CMD.STM32_SCP.ScopeTriggerLevel); if (STM32_CMD.STM32_SCP.ADC_TripleMode) { /* DMA Configuration */ DMA_TripleConfig(STM32_CMD.STM32_SCP.ADC_SampleSize); /* ADC Configuration */ ADC_TripleConfig(STM32_CMD.STM32_SCP.ADC_Prescaler, STM32_CMD.STM32_SCP.ADC_TwoSamplingDelay); } else { /* DMA Configuration */ DMA_SingleConfig(STM32_CMD.STM32_SCP.ADC_SampleSize); /* ADC Configuration */ ADC_SingleConfig(STM32_CMD.STM32_SCP.ADC_Prescaler,STM32_CMD.STM32_SCP.ADC_SampleTime); } if (STM32_CMD.STM32_SCP.ScopeTrigger == 2) { /* Rising edge */ TIM5->CCER &= ~0x2; } else { /* Falling edge */ TIM5->CCER |= 0x2; } if (STM32_CMD.STM32_SCP.ScopeTrigger) { /* Wait for trigger */ scpcnt = TIM5->CNT; scpwait = STM32_CMD.TickCount + 2; while (scpcnt == TIM5->CNT && scpwait != STM32_CMD.TickCount); } /* Start ADC1 Software Conversion */ ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART; i = 0; while (i < 30000) { i++; } /* Since BlueTooth is slower than the lowest sampling rate there is no need to wait */ SendCompressedBuffer((uint32_t *)SCOPE_DATAPTR, STM32_CMD.STM32_SCP.ADC_SampleSize / 4); /* Done */ ADC->CCR=0; ADC1->CR2=0; ADC2->CR2=0; ADC3->CR2=0; break; case CMD_SCP2SET: STM_EVAL_LEDToggle(LED4); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); USART3_getdata((uint8_t *)&STM32_CMD.STM32_SCP2.SampleRateSet,sizeof(STM32_SCP2TypeDef)); /* Scope magnify */ i = ((uint32_t)STM32_CMD.STM32_SCP2.Mag & 0x07) << 3; GPIO_SetBits(GPIOE,(i ^ 0x38)); GPIO_ResetBits(GPIOE,i); /* Set V-Pos */ DAC_SetChannel1Data(DAC_Align_12b_R, STM32_CMD.STM32_SCP2.VPos); /* Set Trigger level */ DAC_SetChannel2Data(DAC_Align_12b_R, STM32_CMD.STM32_SCP2.TriggerLevel); /* Get number of samples needed */ SampleSize = GetScopeSampleSize(); if (STM32_CMD.STM32_SCP2.Triple) { /* DMA Configuration */ DMA_TripleConfig(SampleSize); /* ADC Configuration */ ADC_TripleConfig((uint32_t)STM32_CMD.STM32_SCP2.SampleRateSet >> 4,(uint32_t)STM32_CMD.STM32_SCP2.SampleRateSet & 0xF); } else { /* DMA Configuration */ DMA_SingleConfig(SampleSize); /* ADC Configuration */ ADC_SingleConfig(((uint32_t)STM32_CMD.STM32_SCP2.SampleRateSet >> 3) & 0x3,(uint32_t)STM32_CMD.STM32_SCP2.SampleRateSet & 0x7); } /* Trigger configuration */ if (STM32_CMD.STM32_SCP2.Trigger == 2) { /* Rising edge */ TIM5->CCER &= ~0x2; } else { /* Falling edge */ TIM5->CCER |= 0x2; } if (STM32_CMD.STM32_SCP2.Trigger) { /* Wait for trigger */ scpcnt = TIM5->CNT; scpwait = STM32_CMD.TickCount + 2; while (scpcnt == TIM5->CNT && scpwait != STM32_CMD.TickCount); } /* Start ADC1 Software Conversion */ ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART; /* Reset wavedata */ ScopeResetWave((uint32_t *)SCOPE_WAVEPTR,SCOPE_MAXWAVESIZE); ScopeResetWave((uint32_t *)SCOPE_COUNTPTR,SCOPE_MAXWAVESIZE); /* Wait until DMA transfer complete */ while (DMA_GetFlagStatus(DMA2_Stream0, DMA_FLAG_TCIF0) == RESET); /* Done sampling */ ADC->CCR=0; ADC1->CR2=0; ADC2->CR2=0; ADC3->CR2=0; ScopeSetWaveData((uint32_t *)SCOPE_WAVEPTR, (uint32_t *)SCOPE_COUNTPTR, (uint16_t *)SCOPE_DATAPTR); scptpos = 0; if (STM32_CMD.STM32_SCP2.Trigger) { scptpos = ScopeFindTrigger((uint16_t *)SCOPE_DATAPTR); } /* Send wave data */ SendCompressedBuffer((uint32_t *)(SCOPE_DATAPTR + scptpos * 2), (uint32_t)STM32_CMD.STM32_SCP2.PixDiv * (uint32_t)STM32_CMD.STM32_SCP2.nDiv * 2 / 4); STM_EVAL_LEDToggle(LED4); break; case CMD_HSCSET: GPIO_ResetBits(GPIOD, GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_0); USART3_getdata((uint8_t *)&STM32_CMD.STM32_HSC.HSCSet,sizeof(STM32_HSCTypeDef)); TIM4->ARR = STM32_CMD.STM32_HSC.HSCSet; TIM4->CCR2 = (STM32_CMD.STM32_HSC.HSCSet+1) / 2; TIM4->PSC = STM32_CMD.STM32_HSC.HSCDiv; USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); break; case CMD_DDSSET: USART3_getdata((uint8_t *)&STM32_CMD.STM32_DDS.DDS_Cmd,sizeof(STM32_DDSTypeDef)); if (STM32_CMD.STM32_DDS.DDS_Cmd == DDS_PHASESET) { SPISendData(DDS_PHASESET); SPISendData32(STM32_CMD.STM32_DDS.DDS__PhaseAdd); } else if (STM32_CMD.STM32_DDS.DDS_Cmd == DDS_WAVESET) { SPISendData(DDS_WAVESET); SPISendData(STM32_CMD.STM32_DDS.DDS_Wave); SPISendData(STM32_CMD.STM32_DDS.DDS_Amplitude); SPISendData(STM32_CMD.STM32_DDS.DDS_DCOffset); } else if (STM32_CMD.STM32_DDS.DDS_Cmd == DDS_SWEEPSET) { SPISendData(DDS_SWEEPSET); SPISendData(STM32_CMD.STM32_DDS.SWEEP_Mode); SPISendData(STM32_CMD.STM32_DDS.SWEEP_Time); SPISendData32(STM32_CMD.STM32_DDS.SWEEP_Step); SPISendData32(STM32_CMD.STM32_DDS.SWEEP_Min); SPISendData32(STM32_CMD.STM32_DDS.SWEEP_Max); } break; case CMD_LGASET: USART3_getdata((uint8_t *)&STM32_CMD.STM32_LGA.DataBlocks,sizeof(STM32_LGATypeDef)); /* Set the Prescaler value */ TIM8->PSC = STM32_CMD.STM32_LGA.LGASampleRateDiv; /* Set the Autoreload value */ TIM8->ARR = STM32_CMD.STM32_LGA.LGASampleRate; TIM8->CNT = STM32_CMD.STM32_LGA.LGASampleRate-1; DMA_LGAConfig(); TIM_DMACmd(TIM8, TIM_DMA_Update, ENABLE); /* DMA2_Stream1 enable */ DMA_Cmd(DMA2_Stream1, ENABLE); /* Enable timer */ TIM8->CR1 |= TIM_CR1_CEN; while (DMA_GetFlagStatus(DMA2_Stream1,DMA_FLAG_HTIF1) == RESET); /* Half done */ USART3_putdata((uint8_t *)LGA_DATAPTR, STM32_CMD.STM32_LGA.DataBlocks * 1024 / 2); while (DMA_GetFlagStatus(DMA2_Stream1,DMA_FLAG_TCIF1) == RESET); /* Done */ USART3_putdata((uint8_t *)(LGA_DATAPTR + STM32_CMD.STM32_LGA.DataBlocks * 1024 / 2), STM32_CMD.STM32_LGA.DataBlocks * 1024 / 2); TIM_Cmd(TIM8, DISABLE); DMA_DeInit(DMA2_Stream1); break; case CMD_WAVEUPLOAD: USART3_getdata((uint8_t *)WAVE_DATAPTR,4096); SPISendData(DDS_WAVEUPLOAD); ptr = (uint16_t *)WAVE_DATAPTR; i = 2048; while (i--) { SPISendData(*ptr); ptr++; } STM_EVAL_LEDToggle(LED4); break; }
int main(void) { int i; RCC_Configuration(); //????????????? NVIC_Configuration(); LED_Config(); TIM7_Configuration(10) ; RCC_Config(); ADC_initial(); UART1_Init(); UART1_Config(9600); UART1_Cmd(ENABLE); UART1_Write("stm start",9); LCD_GLASS_Configure_GPIO(); LCD_GLASS_Init(); while (1) { int wdt=0; int adc_wdt=0; double adc=0; //// solution 2 working String i=0; memcpy(buff2,buff, strlen(buff)); // ? buff ??? buff2 memset(buff, 0, strlen(buff)); // ?? buff ??????? while(1) { if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE) != RESET) { char c = USART_ReceiveData(USART1); i=i+1; if(c == '\r') break; else if (c == '\n') break; else sprintf (buff, "%s%c", buff,c); }else { wdt++; adc_wdt++; if(adc_wdt%100==0) { adc=(adc*99.0+GetADC())/100.0; } if(adc_wdt>10000) { adc_wdt=0; LCDPrint(" %0.1f ",adc); } if(wdt==50) { wdt=0; for(i=0;i<4;i++) { if(flag[i]==0) { LED[i]++; if(LED[i]>300) { flag[i]=1; } }else { LED[i]--; if(LED[i]==0) { flag[i]=0; } } } } } } /* strcat(buff,"\n"); UART1_Write(buff, strlen(buff)); Lcd_print(buff); */ // UART1_Write(")",1); USART_ClearFlag(USART1, USART_FLAG_RXNE); } }
/** * @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_stm32f40xx.s/startup_stm32f427x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* RCC configuration */ RCC_Config(); /* GPIO configuration */ GPIO_Config(); /* TIM4 configuration */ TIM4_Config(); /* UART4 configuration */ UART4_Config(); /* SPI3 configuration */ SPI3_Config(); /* NVIC configuration */ NVIC_Config(); /* Network Configuration */ NET_Config(); /* Configure SysTick */ SysTick_Config(SystemCoreClock / 1000); /* Infinite Loop */ while (1) { if(TimerCounter >= 10) { TimerCounter = 0; if(SendFlag) { //SendFlag = False; char str[30]; if(order++ < 90) { float one = NULL; float two = NULL; float thr = NULL; if(inc <= 300) { one = convertSample(EQ_SAMPLE[inc++]) * 1e-7; two = convertSample(EQ_SAMPLE[inc++]) * 1e-7; thr = convertSample(EQ_SAMPLE[inc++]) * 1e-7; } else { inc = 0; } sprintf(str, "%-0.7f,%-0.7f,%-0.7f\n", one, two, thr); } else { order = 0; } // Only when socket is established, send data if(getSn_SR(SOCK_TCPS) == SOCK_ESTABLISHED) { /* send the received data */ send(SOCK_TCPS, (uint8*)str, strlen(str)); } } } if(ParseUART4) { ParseUART4 = False; printSysCfg(); } ProcessTcpSever(); } }
int main() { RCC_Config(); // to read and write to AFIO_remap AFIO_clock must first be eanble NVIC_Config(); TIM_Config(); GPIO_Config(); EXTI_Configuration(); initUsart(); //initBT(); // Only for debug the clock tree *********************************************** // Put the clock configuration into RCC_APB2PeriphClockCmd RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /* Output clock on MCO pin ---------------------------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // RCC_MCOConfig(RCC_MCO_HSE); // Put on MCO pin the: freq. of external crystal RCC_MCOConfig(RCC_MCO_SYSCLK); // Put on MCO pin the: System clock selected // //RTCInit(); RCC_GetClocksFreq(&RCC_Clocks); writeStringUSART2("\033[2J"); //clear usart 2 screen writeStringUSART1("\033[2J"); //clear usart 1 screen writeStringUSART1(" <<<<- Welcome To Hinkens Cobra Bluetooth ->>>>\n\n\r"); while(1) { if(GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== false) writeStringUSART1("On Hook\n\r"); else //Luren är lyft { writeStringUSART1("Phone is off hook!\n\r Dial: \n\r"); acceptCall(); //accept incoming call Delay(Delay_10ms); //for(counter = 0 ; counter < 10 ; counter++) while(TIM_GetITStatus(TIM2, TIM_IT_Update) == RESET) // { dialed_number = 0; while(GPIO_ReadInputDataBit(GPIOB, COBRA_DIALING)== true && GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== true)//Wait for user to start dialing { //writeStringUSART1("Timer Counter: %d\r\n",TIM_GetCounter(TIM2)); if(state == 1 && dialingFlag == true) //check if timer has run out and user has started a call { writeStringUSART1("time is up dialing number: "); for (int x = 0; x < counter; x++) { //printf("%d", number[x] ); } sendPhoneNumber(number, counter); writeStringUSART1("\r\n"); dialingFlag = false; state = 0; counter = 0; } } Delay(Delay_100ms); //Wait for switch to debounce while(GPIO_ReadInputDataBit(GPIOB, COBRA_DIALING) == false) { dialingFlag = true; state = 0; TIM_SetCounter(TIM2, 0); TIM_Cmd(TIM2, ENABLE); //Start timer //RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); Delay(Delay_10ms); Delay(Delay_10ms); //Now count how many times the mechnical switch toggles if(GPIO_ReadInputDataBit(GPIOB, COBRA_PULSE)== false && pulseFlag == 1) { pulseFlag = 0; dialed_number ++; } else if(GPIO_ReadInputDataBit(GPIOB, COBRA_PULSE) == true && pulseFlag == 0) { pulseFlag = 1; //Do notthing just idle.. } Delay(Delay_10ms); } Delay(Delay_100ms); if(dialed_number != 0) // to handle the error of a extra loop after dialed number { dialed_number--; //Rotary always has one extra closure that must be taken off number[counter] = dialed_number; counter ++; } if(GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== false) //Hunng upp { hangUp(); //hang-up command to bluettooh writeStringUSART1("Hung up!\n\r"); counter = 0; break; } //printf("%d\n\r", dialed_number); }//end for loop } Delay(Delay_100ms); }//end while(1) }//end main()