/** * @brief Main program. * @param None * @retval None */ void main(void) { /* CLK configuration -------------------------------------------*/ CLK_Config(); /* Init TIM2 to generate 1 ms time base update interrupt */ TimingDelay_Init(); /* Enable Interrupts */ enableInterrupts(); /* Initialize LEDs mounted on STM8L152X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Turn on LED1 and LED3 */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED3); /* Initialize push-buttons mounted on STM8L152X-EVAL board */ STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI); /* Init the Eval board LCD */ STM8_EVAL_LCD_Init(); /* Clear LCD */ LCD_Clear(); /* Enable general interrupts */ enableInterrupts(); LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" System Clock "); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" Source: HSE "); while (1) { /* Toggle LED2 and LED4 */ STM_EVAL_LEDToggle(LED2); STM_EVAL_LEDToggle(LED4); /* Insert a delay */ Delay(10); /* Toggle LED1 and LED3 */ STM_EVAL_LEDToggle(LED1); STM_EVAL_LEDToggle(LED3); /* Insert a delay */ Delay(10); } }
/** * @brief Eval Board IO Configuration. * @param None * @retval None */ void EvalBoard_Init(void) { /* Init the Eval board LCD */ STM8_EVAL_LCD_Init(); LCD_Clear(); LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" Chronometer "); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" using RTC "); /* Initialize push-buttons mounted on STM8L1528-EVAL board */ STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_GPIO); /* For Saved Time parsing */ STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_GPIO); /* For Saved Time parsing */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); /* For recording Time */ STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); /* For Time Pause/Resume */ STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI); /* To enter to Saved Times*/ STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_GPIO); /* To exit from Saved Times*/ STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); /* To Reset Chrono after 2s */ /* Initialize LEDs mounted on STM8L1528-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDOn(LED1); /* wait 1 second */ Delay_Seconds(1); STM_EVAL_LEDOn(LED2); /* wait 1 second */ Delay_Seconds(1); STM_EVAL_LEDOn(LED3); /* wait 1 second */ Delay_Seconds(1); STM_EVAL_LEDOn(LED4); /* wait 1 second */ Delay_Seconds(1); STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(DEFAULTDISPLAY); }
/** * @brief Main program. * @param None * @retval None */ void main(void) { /* CLK configuration -------------------------------------------*/ CLK_Config(); /* Init the Eval board LCD */ STM8_EVAL_LCD_Init(); /* Clear LCD */ LCD_Clear(); /* Print the Voltage on the LCD*/ LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" POT BNC "); /* ADC configuration -------------------------------------------*/ ADC_Config(); /* DMA configuration -------------------------------------------*/ DMA_Config(); /* Enable ADC1 DMA requests*/ ADC_DMACmd(ADC1, ENABLE); /* Start ADC1 Conversion using TIM1 TRGO*/ ADC_ExternalTrigConfig(ADC1, ADC_ExtEventSelection_Trigger2, ADC_ExtTRGSensitivity_Rising); /* Master Mode selection: Update event */ TIM1_SelectOutputTrigger(TIM1_TRGOSource_Update); /* Enable TIM1 */ TIM1_Cmd(ENABLE); /* Enable Interrupts */ enableInterrupts(); /* Infinite loop*/ while (1) { if (DisplayStatus != DISABLE) { /* Display Potentiometer RV and BNC voltage values on LCD*/ ShowVoltages(PotVoltage, BNCVoltage); /* Disable displaying voltages on LCD until next DMA Channel0 Transfer complete occurs */ DisplayStatus = DISABLE; } } }
/** * @brief Eval Board IO Configuration. * @param None * @retval None */ void EvalBoard_Init(void) { /* Init the Eval board LCD */ STM8_EVAL_LCD_Init(); LCD_Clear(); /* Initialize push-buttons mounted on STM8L152x-EVAL board */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); /* used to decrease Tamper */ STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI); /* used to decrease Tamper time */ STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI); /* used to increase Tamper time */ /* Initialize LEDs mounted on STM8L152x-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED3); }
/** * @brief Main program. * @param None * @retval None */ void main(void) { /* CLK configuration -------------------------------------------*/ CLK_Config(); /* Init TIM2 to generate 1 ms time base update interrupt */ TimingDelay_Init(); /* Enable Interrupts */ enableInterrupts(); /* 1s delay to ensure proper LCD Init*/ Delay(1000); /* Init the Eval board LCD */ STM8_EVAL_LCD_Init(); /* Clear LCD */ LCD_Clear(); /* print "Pot ADC Voltage" on LCD line1*/ LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print("Pot ADC Voltage"); /* ADC configuration -------------------------------------------*/ ADC_Config(); /* Infinite loop*/ while (1) { /* Calculate voltage value*/ PotVoltage = (uint16_t)((uint32_t)((uint32_t)ADCdata * (uint32_t)ADC_RATIO) / (uint32_t)1000); /* Display voltage value on LCD*/ ShowVoltage((uint16_t)PotVoltage); } }
/** * @brief Main program. * @param None * @retval None */ void main(void) { uint16_t voltage = 0; /* Init the Eval board LCD */ STM8_EVAL_LCD_Init(); /* Clear LCD */ LCD_Clear(); /* Print "RV ADC Voltage" on LCD line1*/ LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print("RV ADC Voltage"); /* ADC configuration -------------------------------------------*/ ADC_Config(); /* Init Leds */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Infinite loop*/ while (1) { ADCSavedData = ADCData; while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); ADCData = ADC_GetConversionValue(ADC1); if (ADCSavedData != ADCData) { /* Calculate voltage value*/ voltage = (uint16_t)(((uint32_t)ADCData * (uint32_t)ADC_RATIO) / (uint32_t)1000); /* Display voltage value on LCD*/ ShowVoltage(voltage); STM_EVAL_LEDOff(LED1); /* LED4 is On only if ADC converted data is higher than High Analog watchdog Threshold */ if (ADCData >= HighThresholdData) { STM_EVAL_LEDOn(LED4); LCDString[14] = '<'; } else { STM_EVAL_LEDOff(LED4); LCDString[14] = ' '; } /* LED3 is On only if ADC converted data is lower than Low Analog watchdog Threshold */ if (ADCData <= LowThresholdData) { STM_EVAL_LEDOn(LED3); LCDString[0] = '>'; } else { STM_EVAL_LEDOff(LED3); LCDString[0] = ' '; } } } }
/** * @brief Main program. * @param None * @retval None */ void main(void) { /* Initialize LEDs mounted on STM8L152X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); /* Initialize push-buttons mounted on STM8L152X-EVAL board */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); /* Initialize LCD*/ STM8_EVAL_LCD_Init(); /* Clear LCD*/ LCD_Clear(); /* Enable general interrupts for push button reading */ enableInterrupts(); LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" STM8L152X-EVAL "); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" IO Control "); while (1) { switch (PressedButton) { case BUTTON_KEY: { /* LD1..LD4 are off */ STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); /* LD5 is green */ STM_EVAL_LEDOn(LED5); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print("Button: KEY "); PressedButton = NO_BUTTON; break; } case BUTTON_RIGHT: { /* LD2, LD3 and LD4 are off */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); /* LD5 is red */ STM_EVAL_LEDOff(LED5); /* LD1 is On */ STM_EVAL_LEDOn(LED1); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print("Button: RIGHT"); PressedButton = NO_BUTTON; break; } case BUTTON_LEFT: { /* LD1, LD3 and LD4 are off */ STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); /* LD5 is red */ STM_EVAL_LEDOff(LED5); /* LD2 is On */ STM_EVAL_LEDOn(LED2); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print("Button: LEFT "); PressedButton = NO_BUTTON; break; } case BUTTON_UP: { /* LD1, LD2 and LD4 are off */ STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED4); /* LD5 is red */ STM_EVAL_LEDOff(LED5); /* LD3 is On */ STM_EVAL_LEDOn(LED3); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print("Button: UP "); PressedButton = NO_BUTTON; break; } case BUTTON_DOWN: { /* LD1, LD2 and LD3 are off */ STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); /* LD5 is red */ STM_EVAL_LEDOff(LED5); /* LD4 is On */ STM_EVAL_LEDOn(LED4); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print("Button: DOWN "); PressedButton = NO_BUTTON; break; } case BUTTON_SEL: { /* LD1..LD4 are on */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); /* LD5 is green */ STM_EVAL_LEDOn(LED5); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print("Button: SEL "); PressedButton = NO_BUTTON; break; } default: { break; } } } }