int main() { unsigned int k = 0; // used for counter unsigned short count = 0; char strDisp[20] ; // ### INITILIZATION ### // Enable the High Speed Internal (HSI) Clock RCC_HSI_enable(); // Select the HSI for the SYSCLK RCC_SYSCLK_HSI(); // Enable comparator clock LCD and PWR mngt RCC_LCD_enable(); RCC_PWR_enable(); // Enable SYSCFG RCC_SYSCFG_enable(); // Allow access to the RTC // Also selects the RTCCLK as LSE RTC_access_enable(); // LSE Enable, // this clock is needed for the RTCCLK and LCD RCC_LSE_enable(); // Initializes the LCD LCD_GLASS_Configure_GPIO(); LCD_GLASS_Init(); // configure PB6 as an output config_PB6_out(); // ### TOGGLE PB6, increment counter on LCD ### while(1) { k++; // Toggle at approximately 1 Hz if (k >= 10e5) { PB6_toggle(); //sprintf(strDisp, "%d", ++count); // decimal sprintf(strDisp, "%x", ++count); // hex //sprintf(strDisp, "%o", ++count); // octal LCD_GLASS_Clear(); LCD_GLASS_DisplayString((unsigned char *) strDisp); k = 0; // reset counter } } }
int main() //main function goes here { TIM_TimeBaseInitTypeDef tim4; //store initialize value for timer NVIC_InitTypeDef tim4interrupt; //store initialize value for interrupt RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE); //open clock for timer 4 TIM_TimeBaseStructInit(&tim4); //initialize tim value /* 1 sec->16,000,000 clock (ARR+1)*(PSC+1) = 16,000,000*1 ARR = 4000-1 PSC = 4000-1 */ tim4.TIM_Prescaler = 4000-1; tim4.TIM_Period = 4000-1; TIM_TimeBaseInit(TIM4,&tim4); //initialize tim4 value on timer 4 tim4interrupt.NVIC_IRQChannel = TIM4_IRQn; //timer 4 interrupt tim4interrupt.NVIC_IRQChannelCmd = ENABLE; //enable interrupt for timer 4 NVIC_Init(&tim4interrupt); //initialize interrupt by tim4interrupt value RCC_Configuration(); //config RCC for LCD RTC_Configuration(); //config RTC for LCD LCD_GLASS_Configure_GPIO(); //config io pin for LCD LCD_GLASS_Init(); //initialize LCD TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE); //config timer 4 interrupt TIM_ClearFlag(TIM4,TIM_FLAG_Update); //clear timer 4 interrupt flag TIM_Cmd(TIM4,ENABLE); //enable timer 4 while(1) //loop instruction goes here { } }
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_md.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* Configure Clocks for Application need */ RCC_Configuration(); /* Configure RTC Clocks */ RTC_Configuration(); /* Set internal voltage regulator to 1.8V */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ; /* Enable debug features in low power modes (Sleep, STOP and STANDBY) */ #ifdef DEBUG_SWD_PIN DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE); #endif /* Configure SysTick IRQ and SysTick Timer to generate interrupts */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 500); /* Init I/O ports */ Init_GPIOs(); /* Initializes the LCD glass */ LCD_GLASS_Configure_GPIO(); LCD_GLASS_Init(); /* Display Welcome message */ LCD_GLASS_ScrollSentence(" ** TEMPERATURE SENSOR EXAMPLE ** ",1,SCROLL_SPEED); /* Disable SysTick IRQ and SysTick Timer */ SysTick->CTRL &= ~ ( SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk ); /* Test user or factory temperature sensor calibration value */ if ( testFactoryCalibData() == SUCCESS ) getFactoryTSCalibData(&calibdata); else if ( testUserCalibData() == SUCCESS ) calibdata = *USER_CALIB_DATA; else { /* User calibration or factory calibration TS data are not available */ calibdata.TS_CAL_1 = DEFAULT_COLD_VAL; calibdata.TS_CAL_2 = DEFAULT_HOT_VAL; writeCalibData(&calibdata); calibdata = *USER_CALIB_DATA; } /* Configure Wakeup from sleep using RTC event*/ configureWakeup(); /* Configure direct memory access for ADC usage*/ configureDMA(); /* Configure ADC for temperature sensor value conversion */ configureADC_Temp(); while(1) { /* Re-enable DMA and ADC conf and start Temperature Data acquisition */ acquireTemperatureData(); /* Stay in SLEEP mode untill the data are acquired by ADC */ __WFI(); /* for DEBUG purpose uncomment the following line and comment the __WFI call to do not enter STOP mode */ // while (!flag_ADCDMA_TransferComplete); /* Disable ADC, DMA and clock*/ powerDownADC_Temper(); /* Process mesured Temperature data - calculate average temperature value in °C */ processTempData(); if (flag_UserButton == TRUE) { clearUserButtonFlag(); if (CurrentlyDisplayed == Display_TemperatureDegC) CurrentlyDisplayed = Display_ADCval; else CurrentlyDisplayed = Display_TemperatureDegC; } if (CurrentlyDisplayed == Display_TemperatureDegC) { /* print average temperature value in °C */ sprintf(strDisp, "%d °C", temperature_C ); } else { /* print result of ADC conversion */ sprintf(strDisp, "> %d", tempAVG ); } LCD_GLASS_Clear(); LCD_GLASS_DisplayString( (unsigned char *) strDisp ); /* Enable RTC Wakeup */ RTC_WakeUpCmd(ENABLE); /* Clear WakeUp flag */ PWR_ClearFlag(PWR_FLAG_WU); /* Enter in wait for interrupt stop mode*/ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); RCC_Configuration(); // reinitialize clock /* After Wake up : Disable Wake up from RTC*/ RTC_WakeUpCmd(DISABLE); } }
/*--------------------------------------------------------------------------- Main program start here *---------------------------------------------------------------------------*/ int main() { GPIO_InitTypeDef pa0; RCC_RTC_Configuration(); LCD_GLASS_Init(); LCD_GLASS_Configure_GPIO(); init_USART(); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); GPIO_StructInit(&pa0); pa0.GPIO_Mode = GPIO_Mode_IN; pa0.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOA,&pa0); while(1) { if( GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 1 && state == 0) { count++; sprintf(DataSendToServer,"GET /cpe312/index.php?Name=TESTING_%d HTTP/1.1\r\nHost: markdang.lnw.mn\r\n\r\n",count); // Test AT startup send_data("AT\r\n"); wait_data("OK"); // Restart module send_data("AT+RST\r\n"); wait_data("ready"); display("OK RST"); // Set Station & softAP Mode send_data("AT+CWMODE_CUR=3\r\n"); wait_data("OK"); display("STA+AP"); // Set Station & softAP Mode send_data("AT+CWJAP_CUR=\"CPE312\",\"25033333\"\r\n"); wait_data("OK"); display("SET AP"); // Set TCP , Address & Port : Check data http://markdang.lnw.mn/cpe312/show_data.php send_data("AT+CIPSTART=\"TCP\",\"markdang.lnw.mn\",80\r\n"); wait_data("CONNECT"); display("SETTCP"); length = strlen(DataSendToServer); // find length of data sprintf(nbr_DataSendToServer, "AT+CIPSEND=%d\r\n", length); // Set data size // Send length of data to server send_data(nbr_DataSendToServer); wait_data(">"); display("SetLEN"); // Send data to server send_data(DataSendToServer); wait_data("SEND OK"); display("SENDOK"); // Close AP send_data("AT+CWQAP\r\n"); wait_data("OK"); display("Close"); state = 1; } else if ( GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0 && state == 1) { state = 0; } display("ready "); } }
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); } }