/** * @brief Record Time in memory. * @param None * @retval None */ void Time_Record(void) { if (SaveId < MAXSAVETIME) { STM_EVAL_LEDOn(LED3); LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" Record Done "); Time_SaveCurrentTime(SaveId); SavedTime_Show(LCD_LINE2, SaveId); SaveId++; Delay(0x3FFF) ; STM_EVAL_LEDOff(LED3); } else { LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" Recordable "); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" Mem is Full "); Delay(0x17FFF) ; } Restore_LastDisplay() ; }
/** * @brief Main program. * @param None * @retval None */ void main(void) { uint8_t i = 0; /* Select fCPU = 16MHz */ CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1); /* Init the Eval board LCD */ STM8S_EVAL_LCD_Init(); /* Clear LCD */ LCD_Clear(); LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print("SPI-LCD example"); /* Display "moving" ST logo */ for (i = 1; i < 8; i++) { PrintLogo(); Delay(0xFFFF); } LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" "); LCD_DisplayLogo(0x93); Delay(600); while(1) {} }
/** * @brief Reset Chrono to zero. * @param None. * @retval None. */ void Time_ResetMenu(void) { LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" Reset Chrono ? "); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print("<No Yes>"); /* Endless loop */ while (1) { /* Check which key is pressed */ Key = ReadJoystick(); /* If "RIGHT" pushbutton is pressed */ if (Key == JOY_RIGHT) { Time_Reset(); Time_Pause(); Restore_LastDisplay() ; /* Exit */ return ; } /* If "LEFT" pushbutton is pressed */ if (Key == JOY_LEFT) { Restore_LastDisplay() ; /* Exit */ return ; } } }
/** * @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 Example main entry point. * @param None * @retval None */ void main(void) { uint8_t state = 0x00; /* GPIO Configuration -----------------------------------------------------*/ GPIO_Config(); /* Configure LCD mounted on STM8-128 EVAL board ----------------------------*/ LCD_Config(); /* Clock configuration -----------------------------------------------------*/ CLK_Config(); enableInterrupts(); while (1) { while(state == OscillatorStatus) {} state = OscillatorStatus; /* Update the selected master clock oscillator */ /* joystick right */ if(OscillatorStatus == 0x00) { CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE); /* Print on LCD line2*/ LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" CLK = HSI "); } /* joystick up */ if(OscillatorStatus == 0x01) { CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE); /* Print on LCD line2*/ LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" CLK = HSE "); } /* joystick down */ if(OscillatorStatus == 0x02) { CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE); /* Print on LCD line2*/ LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" CLK = LSI "); } } }
/** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" ERR "); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" ASSERT "); } }
/** * @brief Configure the LCD available on the evaluation board * @param None * @retval None */ static void LCD_Config(void) { /* Init the Eval board LCD */ STM8S_EVAL_LCD_Init(); /* Clear LCD */ LCD_Clear(); /* Print on LCD line1*/ LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print("Clock Selection"); /* Print on LCD line2*/ LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" Use joystick "); }
/** * @brief Configure the LCD available on the evaluation board * @param None * @retval None */ void LCD_Config(void) { /* Init the Eval board LCD */ STM8S_EVAL_LCD_Init(); /* Clear LCD */ LCD_Clear(); /* Display the welcome text on LCD */ LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" STM8S CAN "); /* Print "Press Key" on LCD line2*/ LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" Press Key "); }
/** * @brief Display the current voltage on the LCD. * @param voltage: specifies the voltage to display. * @retval None */ void ShowVoltages(uint32_t PotVoltage, uint32_t BNCVoltage ) { uint8_t voltage1000 = 0; uint8_t voltage100 = 0; uint8_t voltage10 = 0; /* Thousands voltage value*/ voltage1000 = (uint8_t)(PotVoltage / 1000); /* Hundreds voltage value */ voltage100 = (uint8_t)((PotVoltage % 1000) / 100); /* Tens voltage value */ voltage10 = (uint8_t)((PotVoltage % 100 ) / 10); /* Fill the LCDString fields with the current Voltage */ LCDString[1] = (uint8_t)((uint8_t)(voltage1000) + ASCII_NUM_0); LCDString[3] = (uint8_t)((uint8_t)(voltage100) + ASCII_NUM_0); LCDString[4] = (uint8_t)((uint8_t)(voltage10) + ASCII_NUM_0); /* Thousands voltage value*/ voltage1000 = (uint8_t)(BNCVoltage / 1000); /* Hundreds voltage value */ voltage100 = (uint8_t)((BNCVoltage % 1000) / 100); /* Tens voltage value */ voltage10 = (uint8_t)((BNCVoltage % 100 ) / 10); LCDString[9] = (uint8_t)((uint8_t)(voltage1000) + ASCII_NUM_0); LCDString[11] = (uint8_t)((uint8_t)(voltage100) + ASCII_NUM_0); LCDString[12] = (uint8_t)((uint8_t)(voltage10) + ASCII_NUM_0); /* Print the Voltage on the LCD*/ LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(LCDString); }
void Time_Show(uint8_t Line, uint8_t pos) { /* Wait until the calendar is synchronized */ while (RTC_WaitForSynchro() != SUCCESS); /* Get the current subsecond Time*/ Subsecondvalue = RTC_GetSubSecond(); /* Wait until the calendar is synchronized */ while (RTC_WaitForSynchro() != SUCCESS); /* Get the current Time*/ RTC_GetTime(RTC_Format_BCD, &RTC_TimeStr); Mstime = 999 - ((uint32_t)((uint32_t)Subsecondvalue * 1000) / (uint32_t)RTC_InitStr.RTC_SynchPrediv); Ms100 = (uint8_t)(Mstime / 100); Ms10 = (uint8_t)((Mstime % 100 ) / 10); Ms1 = (uint8_t)(Mstime % 10); /* Fill the LCDString fields with the current Time : second and milliseconds*/ LCDStringTime[pos] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Seconds & 0xF0) >> 4) + ASCII_NUM_0); LCDStringTime[pos+1] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Seconds & 0x0F)) + ASCII_NUM_0); LCDStringTime[pos+3] = (uint8_t)((uint8_t)(Ms100 + ASCII_NUM_0)); LCDStringTime[pos+4] = (uint8_t)((uint8_t)(Ms10 + ASCII_NUM_0)); LCDStringTime[pos+5] = (uint8_t)((uint8_t)(Ms1 + ASCII_NUM_0)); /* Print the Time Calendar on the LCD*/ LCD_SetCursorPos(Line, 0); LCD_Print((uint8_t*)LCDStringTime); }
/** * @brief Display the current RV voltage on the LCD. * @param voltage: specifies the voltage to display. * @retval None */ void ShowVoltage(uint16_t Voltage) { uint8_t voltage1000 = 0; uint8_t voltage100 = 0; uint8_t voltage10 = 0; /* Thousands voltage value*/ voltage1000 = (uint8_t)(Voltage / 1000); /* Hundreds voltage value */ voltage100 = (uint8_t)((Voltage % 1000) / 100); /* Tens voltage value */ voltage10 = (uint8_t)((Voltage % 100 ) / 10); /* Fill the LCDString fields with the current Voltage */ LCDString[3] = (uint8_t)((uint8_t)(voltage1000) + ASCII_NUM_0); LCDString[5] = (uint8_t)((uint8_t)(voltage100) + ASCII_NUM_0); LCDString[6] = (uint8_t)((uint8_t)(voltage10) + ASCII_NUM_0); /* Print the RV Voltage on the LCD line2 */ /* Print "RV ADC Voltage" on LCD line1*/ LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(LCDString); }
/** * @brief Pause Chronometer * @param None. * @retval None. */ void Time_Pause(void) { Time_Show(LCD_LINE2); LCD_SetCursorPos(LCD_LINE1, 0); if (PauseStatus == RESET) { STM_EVAL_LEDOn(LED2); LCD_Print(RESETDISPLAY); LastDisplay = 'P'; CLK_RTCClockConfig(CLK_RTCCLKSource_Off, CLK_RTCCLKDiv_1); STM_EVAL_LEDOff(LED1); } else { STM_EVAL_LEDOn(LED1); LCD_Print(DEFAULTDISPLAY); LastDisplay = 'D'; CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1); STM_EVAL_LEDOff(LED2); } /* Invert Pause Status */ PauseStatus = (BitStatus)(~PauseStatus); }
/** * @brief Restore Last Display * @param None. * @retval None. */ void Restore_LastDisplay(void) { LCD_SetCursorPos(LCD_LINE1, 0); if (LastDisplay == 'D') LCD_Print(DEFAULTDISPLAY); else if (LastDisplay == 'P') LCD_Print(RESETDISPLAY); }
void SavedTime_Show(uint8_t Line, uint8_t SavedTimeId) { mstime = 1000 - ((uint32_t)((uint32_t)SaveSubsecond[SavedTimeId] * 1000) / (uint32_t)RTC_InitStr.RTC_SynchPrediv); ms100 = (uint8_t)(mstime / 100); ms10 = (uint8_t)((mstime % 100 ) / 10); ms1 = (uint8_t)(mstime % 10); LCDStringTime[0] = (uint8_t)((uint8_t)( SavedTimeId + 1 + ASCII_NUM_0)); LCDStringTime[1] = '-'; /* Fill the LCDString fields with the current Time*/ LCDStringTime[SHOW_POINT] = (uint8_t)(((uint8_t)(RTC_SaveTimeStr[SavedTimeId].RTC_Hours & 0xF0) >> 4) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+1] = (uint8_t)(((uint8_t)(RTC_SaveTimeStr[SavedTimeId].RTC_Hours & 0x0F)) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+3] = (uint8_t)(((uint8_t)(RTC_SaveTimeStr[SavedTimeId].RTC_Minutes & 0xF0) >> 4) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+4] = (uint8_t)(((uint8_t)(RTC_SaveTimeStr[SavedTimeId].RTC_Minutes & 0x0F)) + (uint8_t)ASCII_NUM_0); LCDStringTime[SHOW_POINT+6] = (uint8_t)(((uint8_t)(RTC_SaveTimeStr[SavedTimeId].RTC_Seconds & 0xF0) >> 4) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+7] = (uint8_t)(((uint8_t)(RTC_SaveTimeStr[SavedTimeId].RTC_Seconds & 0x0F)) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+9] = (uint8_t)((uint8_t)(ms100 + ASCII_NUM_0)); LCDStringTime[SHOW_POINT+10] = (uint8_t)((uint8_t)(ms10 + ASCII_NUM_0)); LCDStringTime[SHOW_POINT+11] = (uint8_t)((uint8_t)(ms1 + ASCII_NUM_0)); /* Print the Time Calendar on the LCD*/ LCD_SetCursorPos(Line, 0); LCD_Print((uint8_t *)LCDStringTime); /* Restore String */ LCDStringTime[0] = ' '; LCDStringTime[1] = ' '; }
//main routine for ADC (linear) calibration testing void TestADCCalibration(void) { unsigned int * ADCBuffer; double * ADCRealValues; double P, Q; unsigned int i; unsigned int NumOfData; volatile double diffOrig; volatile double diffCalib; unsigned char DEBUG_STRING[30]; //set external clock (16MHz XTALL required) SetCPUClock(0); //allocate buffer space if ((ADCBuffer = malloc(ADC_BUFFER_SIZE * sizeof(ADCBuffer[0]))) == NULL) _asm("trap\n"); if ((ADCRealValues = malloc(ADC_BUFFER_SIZE * sizeof(ADCRealValues[0]))) == NULL) _asm("trap\n"); //main test { //collect data NumOfData = ADCCollectDataCalib(ADCBuffer, ADCRealValues); P= GetMultiplierCalib(ADCBuffer, ADCRealValues, NumOfData); diffOrig = GetErrorCalib(ADCBuffer, ADCRealValues, NumOfData, P, 0); //calib data ADCCalibratePQ(ADCBuffer, ADCRealValues, NumOfData, &P, &Q); diffCalib = GetErrorCalib(ADCBuffer, ADCRealValues, NumOfData, P, Q); //print errors sprintf(DEBUG_STRING, "Orig = %f", diffOrig); LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, DEBUG_STRING); sprintf(DEBUG_STRING, "Calib= %f", diffCalib); LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, DEBUG_STRING); delay(500000l);//to show results } //see real values after ADC calibration - for checking calibration LCD_Clear(); LCD_PrintString(LCD_LINE1, DISABLE, ENABLE, "Real calibrated U"); while(!JOY_SEL) { //start single conversion ADC2_StartConversion(); while (!ADC2_GetFlagStatus()); //clear end of conversion bit ADC2_ClearFlag(); //collect ADC value and display LCD_SetCursorPos(LCD_LINE2, 4);//set cursor position LCD_PrintDec4((P*ADC2_GetConversionValue() + Q)*1000); } //unallocate buffer free(ADCBuffer); }//TestADCCalibration
/** * @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 Parse Saved Times. * @param None * @retval None */ void SavedTime_Erase(void) { if ( SaveId != 0) { LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print("Erase Records ?"); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print("<No Yes>"); /* Endless loop */ while (1) { /* Check which key is pressed */ Key = ReadJoystick(); /* If "RIGHT" pushbutton is pressed */ if (Key == JOY_RIGHT) { SaveId = 0; Restore_LastDisplay() ; /* Exit */ return ; } /* If "LEFT" pushbutton is pressed */ if (Key == JOY_LEFT) { Restore_LastDisplay() ; /* Exit */ return ; } } } }
/** * @brief Print ST logo on the LCD * @param None * @retval None */ void PrintLogo(void) { static uint8_t logo_pos = 0x90; static int8_t logo_pos_index = 1; LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" "); LCD_DisplayLogo(logo_pos); logo_pos += logo_pos_index; if (logo_pos > 0x95) { logo_pos -= 2; logo_pos_index = -1; } if (logo_pos < 0x90) { logo_pos += 2; logo_pos_index = 1; } }
void Time_Show(uint8_t Line) { /* Wait until the calendar is synchronized */ while (RTC_WaitForSynchro() != SUCCESS); /* Get the current subsecond Time*/ subsecondvalue = RTC_GetSubSecond(); /* Wait until the calendar is synchronized */ while (RTC_WaitForSynchro() != SUCCESS); /* Get the current Time*/ RTC_GetTime(RTC_Format_BCD, &RTC_TimeStr); mstime = 1000 - ((uint32_t)((uint32_t)subsecondvalue * 1000) / (uint32_t)RTC_InitStr.RTC_SynchPrediv); ms100 = (uint8_t)(mstime / 100); ms10 = (uint8_t)((mstime % 100 ) / 10); ms1 = (uint8_t)(mstime % 10); /* Fill the LCDString fields with the current Time*/ LCDStringTime[SHOW_POINT] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Hours & 0xF0) >> 4) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+1] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Hours & 0x0F)) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+3] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Minutes & 0xF0) >> 4) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+4] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Minutes & 0x0F)) + (uint8_t)ASCII_NUM_0); LCDStringTime[SHOW_POINT+6] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Seconds & 0xF0) >> 4) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+7] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Seconds & 0x0F)) + ASCII_NUM_0); LCDStringTime[SHOW_POINT+9] = (uint8_t)((uint8_t)(ms100 + ASCII_NUM_0)); LCDStringTime[SHOW_POINT+10] = (uint8_t)((uint8_t)(ms10 + ASCII_NUM_0)); LCDStringTime[SHOW_POINT+11] = (uint8_t)((uint8_t)(ms1 + ASCII_NUM_0)); /* Print the Time Calendar on the LCD*/ LCD_SetCursorPos(Line, 0); LCD_Print((uint8_t *)LCDStringTime); }
/** * @brief Display led status and communication direction on the LCD * @param Ledstatus the led status * @retval None */ void LCD_Display(uint8_t Ledstatus) { LCD_SetCursorPos(LCD_LINE2, 0); switch((uint8_t)Ledstatus) { case(0): LCD_Print("Sender LD4 ON "); break; case(1): LCD_Print("Sender LD3 ON "); break; case(2): LCD_Print("Sender LD2 ON "); break; case(3): LCD_Print("Sender LD1 ON "); break; case(4): LCD_Print("Receiver LD4 ON "); break; case(5): LCD_Print("Receiver LD3 ON "); break; case(6): LCD_Print("Receiver LD2 ON "); break; case(7): LCD_Print("Receiver LD1 ON "); break; } }
/** * @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); } }
//collection of ADC data and also real precise values from external voltmeter //external data is entered with joystick movement as 0.000 number static unsigned int ADCCollectDataCalib(unsigned int * ADCBuffer, double * ADCRealValues) { unsigned int i; unsigned int multiplier; signed int Voltage; unsigned char cursorPos; unsigned char ArrowChar = '^'; unsigned char JoyUp,JoyDown,JoyLeft,JoyRight,JoySel; //disable ADC interrupts ADC2_ITConfig(DISABLE); //enable ADC ADC2_Init(ADC2_CONVERSIONMODE_SINGLE, ADC2_CHANNEL_12, ADC2_PRESSEL_FCPU_D6, ADC2_EXTTRIG_TIM, DISABLE, ADC2_ALIGN_RIGHT, ADC2_SCHMITTTRIG_CHANNEL12, DISABLE); //clear end of conversion bit ADC2_ClearFlag(); //for joystick control (init) //pull-ups on on all used buttons GPIOB->CR1 |= 0xF0; GPIOD->CR1 |= 0x80; Voltage = 0; multiplier = 1000; cursorPos = 2; //print values on LCD display LCD_Clear(); LCD_SetCursorPos(LCD_LINE1, 1); LCD_PrintDec4(Voltage); LCD_PrintString(LCD_LINE1, DISABLE, ENABLE, " =Real U"); LCD_SetCursorPos(LCD_LINE2, cursorPos/2); LCD_PrintChar(ArrowChar); //set external voltage - measure it with external voltmeter - enter voltmeter //value into LCD - measure ADC data - store real and ADC data to buffers //finish data collecting by KEY button on PCB board for(i=0; i<ADC_BUFFER_SIZE; i++) { LCD_SetCursorPos(LCD_LINE2, 0); LCD_PrintDec2(i); while(JOY_SEL); while(!JOY_SEL) { if(BUTTON_LOW) break; JoyUp = JOY_UP; JoyDown = JOY_DOWN; JoyLeft = JOY_LEFT; JoyRight= JOY_RIGHT; JoySel = JOY_SEL; if(JoyLeft)//increase multiplier { if (cursorPos!=2) { multiplier *= 10; cursorPos -= 1; } } if(JoyRight)//decrease multiplier { if (cursorPos!=5) { multiplier /= 10; cursorPos += 1; } } if(JoyRight || JoyLeft)//repaint cursor position { LCD_PrintString(LCD_LINE2, DISABLE, DISABLE, " ");//clear cursor LCD_SetCursorPos(LCD_LINE2, cursorPos/2);//set cursor position if(cursorPos & 1) LCD_PrintChar(' ');//print space LCD_PrintChar(ArrowChar);//print cursor while (JOY_RIGHT || JOY_LEFT); delay(1000l); } if(JoyUp)//increase real value { Voltage += multiplier; } if(JoyDown)//decrease real value { Voltage -= multiplier; } if(JoyUp || JoyDown)//repaint real value { LCD_PrintString(LCD_LINE1, DISABLE, DISABLE, " ");//clear voltage if (Voltage<0) { LCD_SetCursorPos(LCD_LINE1, 1); LCD_PrintDec4(-Voltage); LCD_SetCursorPos(LCD_LINE1, 0); LCD_PrintChar('-');//print sign } else { LCD_SetCursorPos(LCD_LINE1, 1); LCD_PrintDec4(Voltage); LCD_SetCursorPos(LCD_LINE1, 0); LCD_PrintChar('+');//print sign } while (JOY_UP || JOY_DOWN); delay(1000l); } //start single conversion ADC2_StartConversion(); while (!ADC2_GetFlagStatus()); //clear end of conversion bit ADC2_ClearFlag(); //collect ADC value and display it LCD_SetCursorPos(LCD_LINE2, 5);//set cursor position LCD_PrintDec4(ADC2_GetConversionValue()); } //stop collecting if KEY buttom pressed if(BUTTON_LOW) { break; } //otherwise collect ADC data (+ real data) and store them else { //start single conversion ADC2_StartConversion(); while (!ADC2_GetFlagStatus()); //clear end of conversion bit ADC2_ClearFlag(); //collect ADC value ADCBuffer[i] = ADC2_GetConversionValue(); //collect real value ADCRealValues[i] = (double)Voltage/1000; } } return i; }//ADCCollectDataCalib
/** * @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) { STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize KEY button */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); /* Enable general interrupts for Key button reading */ enableInterrupts(); /* Initialize LCD */ STM8L_EVAL_LCD_Init(); /* Clear LCD lines */ LCD_Clear(); /* Display "moving" ST logo on first line */ for (pos = 0x80; pos < 0x88; pos++) { LCD_Clear(); LCD_DisplayLogo(pos); Delay(5000); } /* Display "moving" ST logo on second line */ for (pos = 0x90; pos < 0x98; pos++) { LCD_Clear(); LCD_DisplayLogo(pos); Delay(5000); } /* Clear LCD lines */ LCD_Clear(); /* Max 15 characters per line */ LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" *** STM8L *** "); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print("SPI-LCD example"); for (i = 0; i < 10; i++) { Delay(0xFFFF); } /* Clear LCD lines */ LCD_Clear(); LCD_Print("Press KEY..."); while (1) { /* Check button status */ if (GetVar_ButtonPressed() == TRUE) /* Button is pressed */ { ButtonPressed = FALSE; LCD_SetCursorPos(LCD_LINE2, 0); LCD_Clear(); LCD_Print("LED #"); sprintf((char*)StrName, "%d", (int)(ButtonIndex + 2)); LCD_Print(StrName); LCD_SetCursorPos(LCD_LINE2, 2); /* 8th position */ if (LedState == 0) { LCD_Print("OFF"); } else { LCD_Print("ON"); } switch (ButtonIndex) { case 0: STM_EVAL_LEDToggle(LED2); ButtonIndex++; break; case 1: STM_EVAL_LEDToggle(LED3); ButtonIndex++; break; case 2: STM_EVAL_LEDToggle(LED4); ButtonIndex = 0; LedState ^= 0x01; break; } } } }
/** * @brief Parse Saved Times. * @param None * @retval None */ void SavedTime_Parsing(void) { if ( SaveId != 0) { SaveParsingId = 1; LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print("< Rec. Times >"); SavedTime_Show(LCD_LINE2, SaveParsingId - 1); /* Endless loop */ while (1) { /* Check which key is pressed */ Key = ReadJoystick(); /* If "RIGHT" pushbutton is pressed */ if (Key == JOY_RIGHT) { SaveParsingId++; if (SaveParsingId <= SaveId) { SavedTime_Show(LCD_LINE2, SaveParsingId - 1); } else { SaveParsingId = SaveId; } } /* If "LEFT" pushbutton is pressed */ if (Key == JOY_LEFT) { SaveParsingId--; if (SaveParsingId >= 1 ) { SavedTime_Show(LCD_LINE2, SaveParsingId - 1); } else { SaveParsingId = 1; } } /* If "UP" pushbutton is pressed */ if (Key == JOY_UP) { Restore_LastDisplay() ; /* Exit */ return ; } } } else { LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print(" No Times "); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(" are Recorded "); Delay(0x1FFFF); Restore_LastDisplay(); } }
/** * @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; } } } }
/** * @brief Tamper delay show function. * @param None. * @retval None. */ void Tamper_DelayShow(uint8_t DelayId) { LCDTamperTime[CHARPOS] = ((uint8_t)(1 << DelayId) - 1) + ASCII_NUM_0; LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print((uint8_t*)LCDTamperTime); }
/** * @brief Validation firmware main entry point. * @par Parameters: * None * @retval * None */ void main(void) { int ButtonIndex =0; u8 i =0; u8 LedState =1; u8 pos =0; u8 s[16]; /* Initialize I/Os in Output Mode for LEDs */ GPIO_Init(LEDS_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN,GPIO_MODE_OUT_PP_LOW_FAST); /* Initialization of I/O in Input Mode with Interrupt for Key button */ GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT); /* Initialization of the Interrupt sensitivity */ EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY); /* Enable general interrupts for Key button reading */ enableInterrupts(); /* Initialize SPI */ SPI_DeInit(); SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07); SPI_Cmd(ENABLE); /* Initialize LCD */ LCD_Init(); /* Clear LCD lines */ LCD_Clear(); /* Display "moving" ST logo on first line */ for (pos = 0x80; pos < 0x88; pos++) { LCD_Clear(); LCD_DisplayLogo(pos); Delay(20000); } /* Display "moving" ST logo on second line */ for (pos = 0x90; pos < 0x98; pos++) { LCD_Clear(); LCD_DisplayLogo(pos); Delay(20000); } LCD_Clear(); /* More than 15 characters: the message is displayed on 2 lines */ /* LCD_PrintMsg("STM8S - SPI/LCD example"); */ /* Max 15 characters per line */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " *** STM8S *** "); LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, "SPI-LCD example"); for (i = 0; i < 10; i++) { Delay(0xFFFF); } LCD_Clear(); LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "Press KEY..."); while (1) { /* Check button status */ if (GetVar_ButtonPressed() == TRUE) /* Button is pressed */ { ButtonPressed = FALSE; LCD_ClearLine(LCD_LINE2); LCD_PrintString(LCD_LINE2, DISABLE, DISABLE, "LED #"); /*Use the sprintf() and LCD_Print() function to print a digit on the LCD */ if (LedState == 0) { sprintf(s,"%d ", ButtonIndex + 1); LCD_Print(s); LCD_SetCursorPos(LCD_LINE2, 4); /* 8th position */ LCD_PrintChar('O'); LCD_PrintChar('F'); LCD_PrintChar('F'); } /*Use the LCD_PrintDec1() function to print a digit on the LCD */ else { LCD_PrintDec1((u8)(ButtonIndex + 1)); /* Display at current cursor position */ LCD_SetCursorPos(LCD_LINE2, 4); /* 8th position */ LCD_PrintChar('O'); LCD_PrintChar('N'); LCD_PrintChar(' '); } switch (ButtonIndex) { case 0: GPIO_WriteReverse(LEDS_PORT, LED1_PIN); ButtonIndex++; break; case 1: GPIO_WriteReverse(LEDS_PORT, LED2_PIN); ButtonIndex++; break; case 2: GPIO_WriteReverse(LEDS_PORT, LED3_PIN); ButtonIndex++; break; default: case 3: GPIO_WriteReverse(LEDS_PORT, LED4_PIN); ButtonIndex = 0; LedState ^= 0x01; break; } } } }