Exemplo n.º 1
0
/**
  * @brief funtion Current measurement in LOW POWER mode with LCD off
  * @caller main and test_icc_LCD
  * @param none
  * @retval Current (µA)
  */
float Icc_measure_LPR(void)
{
  float Current;
  uint16_t MeasurINT;
  
  /* To init the mode and measurement*/	
  MeasurINT = ADC_Icc_Test(MCU_LPR);
  
  /* Substract bias curent*/
  MeasurINT -= Bias_Current;
  
  Current = MeasurINT * Vdd_appli()/ADC_CONV; 
  Current *= 10L;
  
  /* To test if value is "normal"   */
  if ((int) Current<MAX_CURRENT)
  {	
    display_MuAmp((int)Current);
  }
  else
  {
    if (!Auto_test)
    {
      LCD_GLASS_Clear();
      LCD_GLASS_DisplayString("Error");
    }
  }

  return (Current);
}
Exemplo n.º 2
0
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
		}
	}
}
Exemplo n.º 3
0
void TIM4_IRQHandler(void) //ISR for timer 4
{
	if(TIM_GetFlagStatus(TIM4,TIM_FLAG_Update)==SET)
	//make sure that is an interrupt from timer 4
	{
		Count++; //increase count by 1
		count%=31; //0<=count<=30
		sprintf(LCD_buff,"%d",count);
		//put string “<count’s value>” to LCD_buff
		LCD_GLASS_Clear(); //clear LCD Screen
		LCD_GLASS_DisplayString((unsigned char*)LCD_buff);
// display LCD_buff string on LCD
		TIM_ClearFlag(TIM4,TIM_FLAG_Update);
		//clear timer 4 interrupt flag
	}
}
Exemplo n.º 4
0
/**
  * @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();
    
    
}
Exemplo n.º 5
0
/**
  * @brief funtion Current measurement in HALT mode
  * @caller main and test_icc_HALT
  * @param none
  * @retval Current (µA)
  */ 
float Icc_measure_HALT(void)
{
  float Current;
  uint16_t MeasurINT;
  
  /* To init the mode and measurement*/
  MeasurINT = ADC_Icc_Test(MCU_HALT);
  
  /* Substract bias curent*/
  MeasurINT -=	Bias_Current;
  Current = MeasurINT * Vdd_appli()/ADC_CONV;  

  Current *= 10L;
  
  if ((int) Current<MAX_CURRENT)
  {	
    display_MuAmp((int)Current);
  } else{
    LCD_GLASS_Clear();
    LCD_GLASS_DisplayString("Error");
  }
  
  return(Current);
}
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);
    }

}
Exemplo n.º 7
0
/**
  * @brief main entry point.
  * @par Parameters None
  * @retval void None
  * @par Required preconditions: None
  */
void main(void)
{ 
uint8_t PayloadLength,
				data_sensor,
				*bufMessage;
		
	/* deinit I/O ports */
	DeInitClock();
	DeInitGPIO();
	
	/* Select HSI as system clock source */
	#ifdef USE_HSI
		CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
		CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16);	
	 #else
		CLK_SYSCLKSourceSwitchCmd(ENABLE);
		/* Select 2MHz HSE as system clock source */
		CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);
		CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_4);	
		CLK_HSICmd(DISABLE);
	#endif

	// Initializes the LCD glass 
  LCD_GLASS_Init();

	
	/* LED button init: GPIO set in push pull */
	GPIO_Init( LED_GPIO_PORT, LED_GPIO_PIN, GPIO_Mode_Out_PP_Low_Fast);
	// set to 0 
	GPIOE->ODR &= ~LED_GPIO_PIN;
	
	/* USER button init: GPIO set in input interrupt active mode */
  GPIO_Init( BUTTON_GPIO_PORT, USER_GPIO_PIN, GPIO_Mode_In_FL_IT);
	EXTI_SetPinSensitivity(EXTI_Pin_7, EXTI_Trigger_Falling);

  //* Init Bar on LCD all are OFF
  BAR0_OFF;
  BAR1_OFF;
  BAR2_OFF;
  BAR3_OFF;	
	
	enableInterrupts();
	
  
  //* At power on VDD diplays 
	bufMessage = NDEFmessage;
	
	if (EEMenuState > STATE_TEMPMEAS) 
		EEMenuState = STATE_CHECKNDEFMESSAGE;
		
	FLASH_Unlock(FLASH_MemType_Data );
	
	state_machine = EEMenuState ; 
	
	delayLFO_ms (1);
	
	if (EEInitial == 0)
	{
			User_WriteFirmwareVersion ();
			EEInitial =1;
	}
	
  while (1)
  {
    
    switch (state_machine)
    {
			  
				case STATE_VREF:
					// measure the voltage available at the output of the M24LR04E-R
					Vref_measure();

					delayLFO_ms (2);
        break;
			
        case STATE_CHECKNDEFMESSAGE:
				
						// read the NDEF message from the M24LR04E-R EEPROM and display it if it is found 				
					if (User_ReadNDEFMessage (&PayloadLength) == SUCCESS)						
						User_DisplayMessage (bufMessage,PayloadLength);
	//					User_DisplayMessageActiveHaltMode (PayloadLength);
					else 
						User_DisplayMessage((uint8_t*)ErrorMessage,20);		
		
					
	
        break;
				
				case STATE_TEMPMEAS:
						
						// read the ambiant tempserature from the STTS751
						User_GetOneTemperature (&data_sensor);
						// display the temperature
						User_DisplayOneTemperature (data_sensor);
			
						delayLFO_ms (2);
						
				break;
			
			break;
  
        /* for safe: normaly never reaches */ 			
        default:
					LCD_GLASS_Clear();
					LCD_GLASS_DisplayString("Error");
					state_machine = STATE_VREF;
        break;
      }
    
		
    }
}	
Exemplo n.º 8
0
void display(const char *str_display)
{
  LCD_GLASS_Clear();
  LCD_GLASS_DisplayString((unsigned char*)str_display);
}
Exemplo n.º 9
0
int main(void)
{ 
    bool StanbyWakeUp ;
    float Current_STBY;
  
 /*!< 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
     */ 
  
    Int_CurrentSTBY = Current_Measurement();
  
    /* Check if the StandBy flag is set */
    if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
    {
        /* System resumed from STANDBY mode */
        /* Clear StandBy flag */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
        PWR_ClearFlag(PWR_FLAG_SB); 
        
        StanbyWakeUp = TRUE;
    
    } else
    {
        StanbyWakeUp = FALSE;    
    } 

    PWR_PVDCmd(DISABLE);
    
    RCC_Configuration();
    
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
    
    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
     
    /* Init I/O ports */
    Init_GPIOs ();
    
    /* Initializes ADC */
    ADC_Icc_Init();
    
    enableInterrupts();	
    
    /* Warning ! in TSL Init the sysTick interrupt is setted to:
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/
    
    /* Init Touch Sensing configuration */  
    TSL_Init();
    
    sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[0].Setting.b.ENABLED = 1;
    sMCKeyInfo[0].DxSGroup = 0x00; 
 
    /* Initializes the LCD glass */
    LCD_GLASS_Init();
  
    // EECE 337 Code -- Start
        
    char str[50];                       // Used to display results
    unsigned int delay_time = 5000;      // Will delay for 5 seconds
    const unsigned int numItems = 10;          // # items in array
	int MyArray[10] = { 365, 245, -499, 0, 23, 8, 200, -4, -50, 25 };

	int minimum = 0;                    // Will hold minimum value
	int maximum = 0;                    // Will hold maximum value
    
    // Call Function to obtain Min and Max values from array
	min_max(MyArray, numItems, &minimum, &maximum);	
    
    // Copy min result to str
    sprintf (str, "%d", minimum);
    
    // Display on LCD
    LCD_GLASS_DisplayString(str);
    
    // Pause for 5 seconds
    Delay(delay_time);
    
    // Clear LCD
    LCD_GLASS_Clear();
    
    // Copy max result to str
    sprintf (str, "%d", maximum);
    
    // Display on LCD
    LCD_GLASS_DisplayString(str);
    
    // Pause for 5 seconds
    Delay(delay_time);
    
    // EECE 337 Code -- End
    
    return(0);
}		
Exemplo n.º 10
0
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();
  uint8_t rxBuf[4];
  uint8_t txBuf[16];

  uint8_t chByte[2];
  uint8_t chMainStep=MAIN_STEP_IDLE;
  int16_t* iCurentAdcValue=(int16_t*)chByte; // теперь тут будет лежать последнее измеренное число
  /* Configure RTC Clocks */
  RTC_Configuration();

  /* 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 */
  conf_analog_all_GPIOS();   /* configure all GPIOs as analog input */

  InitButton();
  MesureCurInit();

  LCD_GLASS_Init();/* Initializes the LCD glass */

//  RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK , ENABLE);
  //RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK 		| P_GATE1_GPIO_PORT_CLK |
///		  	  	  	  P_GATE2_GPIO_PORT_CLK 	| N_GATE1_GPIO_PORT_CLK |
//		  	  	  	  N_GATE2_GPIO_PORT_CLK		, ENABLE);

  Delay.Init();
  DbgUART.UART_Init(USART3);
  i2cMgr.SetDbgUART(&DbgUART);
  i2cMgr.Init();
  calipers.Init();
  calipers.Callback=CallBackCalipers;



  // Setup i2cCmd  to write config data to ADC
  txBuf[0]=0x88; //Bits 3 and 2 control the ADS1100Тs data rate "1 0"= 16SPS
  I2C_command.Address=0x48;
  I2C_command.DataToRead.Length = 0;
  I2C_command.DataToRead.Buf=rxBuf;
  I2C_command.DataToWrite.Buf = txBuf;
  I2C_command.DataToWrite.Length = 1;
  I2C_command.Callback=CallBackI2C;
  i2cMgr.AddCmd(I2C_command);

  // Setup i2cCmd  to read data from ADC
  I2C_command.Address=0x48;
  I2C_command.DataToRead.Length = 4;
  I2C_command.DataToRead.Buf=rxBuf;
  I2C_command.DataToWrite.Buf = txBuf;
  I2C_command.DataToWrite.Length = 0;
  I2C_command.Callback=CallBackI2C;

  /* Display Welcome message */ 
 // LCD_GLASS_ScrollSentence((uint8_t*)"      CELESTIA ONLINE ",1,SCROLL_SPEED);

  Delay.Reset(&TimeDelay);
  Delay.Reset(&DbgDelay);
  MesureCurStop();
  char chI2cCounter=0;
  MesureCurUpward();
  chflagI2C=1;
  while(1){
	  i2cMgr.Task();
	  calipers.Task();
	  switch (chMainStep)
	  {
	  case MAIN_STEP_IDLE:
		  if (calipers.GetState()==SPI_END_RX)  //при выходе из холостго режима пропускаем первый отсчет со штангена, чтобы ток в датчике
		  {
			  chMainStep=MAIN_STEP_WAIT_CALIPERS_START;
			  DbgUART.SendPrintF("OUT IDLE  \n");
			  MesureCurUpward();					// включаем ток
			  chflagI2C=0;
		  }
		  break;
	  case MAIN_STEP_WAIT_CALIPERS_START:
		  if (calipers.GetState()==SPI_IDLE) // давно небыло посылок с штангена,
		  {
			  DbgUART.SendPrintF("IN IDLE  \n");
			  chMainStep=MAIN_STEP_IDLE;   // переходим в холостой режим
			  MesureCurStop();				//отключаем ток в датчике.
		  }
		  if (calipers.GetState()==SPI_START_RX)  // начало приема данных со штангена
		  {
			  //DbgUART.SendPrintF("IN I2C  \n");
			  chMainStep=MAIN_STEP_WAIT_I2C;
			  i2cMgr.AddCmd(I2C_command);
		  }
		  break;
	  case MAIN_STEP_WAIT_I2C:
		  if (chflagI2C==1) // закончилась работа с I2C
		  {
			    chMainStep=MAIN_STEP_WAIT_CALIPERS_END;
			    MesureCurToggle();				// переключаем направление тока
		  }
		  break;
	  case MAIN_STEP_WAIT_CALIPERS_END:
		  if (calipers.GetState()==SPI_END_RX) // закончилcz прием данных о штангена
		  {
			  	chByte[0]=rxBuf[1];
			  	chByte[1]=rxBuf[0];
			  	DbgUART.SendPrintF("ACD_VAL=%d  \n",*iCurentAdcValue);
			    LCD_GLASS_Clear();
			    tiny_sprintf(strDisp, " %d ", calipers.iSpiDataRx );
			    LCD_GLASS_DisplayString( (unsigned char *) strDisp );
			    DbgUART.SendPrintF("CALIPERS_VAL=%d  \n",calipers.iSpiDataRx);
			    DbgUART.SendPrintF("OUT I2CE  \n");
			  chMainStep=MAIN_STEP_WAIT_CALIPERS_START;
		  }
		  break;
	  } //switch

	 // if (Delay.Elapsed(&DbgDelay,100))  DbgUART.SendPrintF("i2c flag=%d  main_state=%d \n ",chflagI2C, chMainStep) ;
	/*  if (chflagI2C==1) // закончилась работа с I2C
	  {
		  MesureCurToggle();
		  chflagI2C=0;
	  }
	  if (Delay.Elapsed(&DbgDelay,250))
	  {
		  if (chI2cCounter<=10)
		  {
			  //MesureCurToggle();
			  chByte[0]=rxBuf[1];
		  	  chByte[1]=rxBuf[0];
			  DbgUART.SendPrintF("ACD_VAL=%d  \n",*iCurentAdcValue);
			  rxBuf[0]=0;
			  rxBuf[1]=0;
			  chI2cCounter++;
			  //chflagI2C=0;
			  i2cMgr.AddCmd(I2C_command);
		  }
	  }
*/

    if (flag_UserButton == TRUE)
    {
       clearUserButtonFlag();

       chI2cCounter=0;

    }
  }

}
Exemplo n.º 11
0
/**
  * @brief  Display a string in scrolling mode
  * @note   The LCD should be cleared before to start the write operation.  
  * @param  ptr: Pointer to string to display on the LCD Glass.
  * @param  nScroll: Specifies how many time the message will be scrolled
  * @param  ScrollSpeed: Speciifes the speed of the scroll.
  *                     Low value gives higher speed. 
  * @retval None
  */
void LCD_GLASS_ScrollString(uint8_t* ptr, uint16_t nScroll, uint16_t ScrollSpeed)
{
  uint8_t Repetition = 0;
  uint8_t* ptr1;
  uint8_t str[8] = "";
  ptr1 = ptr;

  LCD_GLASS_DisplayString(ptr1);

  delay(ScrollSpeed);
		
  for (Repetition = 0; Repetition < nScroll; Repetition++)
  {
    *(str + 1) = *ptr1;
    *(str + 2) = *(ptr1 + 1);
    *(str + 3) = *(ptr1 + 2);
    *(str + 4) = *(ptr1 + 3);
    *(str + 5) = *(ptr1 + 4);
    *(str + 6) = *(ptr1 + 5);
    *(str + 7) =*(ptr1 + 6);
    *(str) = *(ptr1 + 7);    
    LCD_GLASS_Clear();
    LCD_GLASS_DisplayString(str);
    delay(ScrollSpeed);

    *(str + 1) = *(ptr1 + 7);
    *(str + 2) = *ptr1;
    *(str + 3) = *(ptr1 + 1);
    *(str + 4) = *(ptr1 + 2);
    *(str + 5) = *(ptr1 + 3);
    *(str + 6) = *(ptr1 + 4);
    *(str + 7) = *(ptr1 + 5);
    *(str) = *(ptr1 + 6);    
    LCD_GLASS_Clear();
    LCD_GLASS_DisplayString(str);
    delay(ScrollSpeed);

    *(str + 1) = *(ptr1 + 6);
    *(str + 2) = *(ptr1 + 7);
    *(str + 3) = *ptr1;
    *(str + 4) = *(ptr1 + 1);
    *(str + 5) = *(ptr1 + 2);
    *(str + 6) = *(ptr1 + 3);
    *(str + 7) = *(ptr1 + 4);    
    *(str) = *(ptr1 + 5);
    LCD_GLASS_Clear();
    LCD_GLASS_DisplayString(str);
    delay(ScrollSpeed);

    *(str + 1) = *(ptr1 + 5);
    *(str + 2) = *(ptr1 + 6);
    *(str + 3) = *(ptr1 + 7);
    *(str + 4) = *ptr1;
    *(str + 5) = *(ptr1 + 1);
    *(str + 6) = *(ptr1 + 2);
    *(str + 7) = *(ptr1 + 3);    
    *(str) = *(ptr1 + 4);
    LCD_GLASS_Clear();
    LCD_GLASS_DisplayString(str);
    delay(ScrollSpeed);

    *(str + 1) = *(ptr1 + 4);
    *(str + 2) = *(ptr1 + 5);
    *(str + 3) = *(ptr1 + 6);
    *(str + 4) = *(ptr1 + 7);
    *(str + 5) = *ptr1;
    *(str + 6) = *(ptr1 + 1);
    *(str + 7) = *(ptr1 + 2);    
    *(str) = *(ptr1 + 3);
    LCD_GLASS_Clear();
    LCD_GLASS_DisplayString(str);
    delay(ScrollSpeed);

    *(str + 1) = *(ptr1 + 3);
    *(str + 2) = *(ptr1 + 4);
    *(str + 3) = *(ptr1 + 5);
    *(str + 4) = *(ptr1 + 6);
    *(str + 5) = *(ptr1 + 7);
    *(str + 6) = *ptr1;
    *(str + 7) = *(ptr1 + 1);    
    *(str) = *(ptr1 + 2);
    LCD_GLASS_Clear();
    LCD_GLASS_DisplayString(str);
    delay(ScrollSpeed);

    *(str + 1) = *(ptr1 + 2);
    *(str + 2) = *(ptr1 + 3);
    *(str + 3) = *(ptr1 + 4);
    *(str + 4) = *(ptr1 + 5);
    *(str + 5) = *(ptr1 + 6);
    *(str + 6) = *(ptr1 + 7);
    *(str + 7) = *ptr1;    
    *(str) = *(ptr1 + 1);
    LCD_GLASS_Clear();
    LCD_GLASS_DisplayString(str);
    delay(ScrollSpeed);
    
    *(str + 1) = *(ptr1 + 1);
    *(str + 2) = *(ptr1 + 2);
    *(str + 3) = *(ptr1 + 3);
    *(str + 4) = *(ptr1 + 4);
    *(str + 5) = *(ptr1 + 5);
    *(str + 6) = *(ptr1 + 6);
    *(str + 7) = *(ptr1 + 7);    
    *(str) = *(ptr1);
    LCD_GLASS_Clear();
    LCD_GLASS_DisplayString(str);
    delay(ScrollSpeed);
  }
}
Exemplo n.º 12
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_stm32l1xx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */     
       
  /* RTC configuration -------------------------------------------------------*/
  RTC_Config();

  /* Configure the SysTick to generate an interrupt each 250 ms */
  SysTickConfig();
  
  /* LCD GLASS Initialization */
  LCD_GLASS_Init();

  /* Clear the LCD GLASS */
  LCD_GLASS_Clear();

  /* Configure STM32L152-EVAL LED1 and LED2 as Output push-pull */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);

  while (1)
  {
    /* Display " STM32L " string on LCD glass in scrolling mode */
    LCD_GLASS_ScrollString(LCD_String, SCROLL_NUM, SCROLL_SPEED);  

    /* Display String on the LCD */
#ifdef USE_STM32L152D_EVAL
    LCD_GLASS_DisplayString("STOPMOD");
#else
    LCD_GLASS_DisplayString("STOPMODE");
#endif
   

    /* Enable Wakeup Counter */
    RTC_WakeUpCmd(ENABLE);

    /* Enter Stop Mode */
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);

    /* Enable Wakeup Counter */
    RTC_WakeUpCmd(DISABLE);
    
    /* After wake-up from STOP reconfigure the system clock */
    /* Enable HSE */
    RCC_HSEConfig(RCC_HSE_ON);

    /* Wait till HSE is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET)
    {}
    
    /* Enable PLL */
    RCC_PLLCmd(ENABLE);
    
    /* Wait till PLL is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {}
    
    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
    
    /* Wait till PLL is used as system clock source */
    while (RCC_GetSYSCLKSource() != 0x0C)
    {}
  }
}
Exemplo n.º 13
0
/**
  * @brief main entry point.
  * @par Parameters None
  * @retval void None
  * @par Required preconditions: None
  */
void main(void)
{ 
uint8_t PayloadLength,
				data_sensor,
				*bufMessage;
		
	/* deinit I/O ports */
	DeInitClock();
	DeInitGPIO();
	
	/* Select HSI as system clock source */
	#ifdef USE_HSI
		CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
		CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16);	
	 #else
		CLK_SYSCLKSourceSwitchCmd(ENABLE);
		/* Select 2MHz HSE as system clock source */
		CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);
		CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_4);	
		CLK_HSICmd(DISABLE);
	#endif

	// Initializes the LCD glass 
  LCD_GLASS_Init();

	
	/* LED button init: GPIO set in push pull */
	GPIO_Init( LED_GPIO_PORT, LED_GPIO_PIN, GPIO_Mode_Out_PP_Low_Fast);
	// set to 0 
	GPIOE->ODR &= ~LED_GPIO_PIN;
	
	/* USER button init: GPIO set in input interrupt active mode */
  GPIO_Init( BUTTON_GPIO_PORT, USER_GPIO_PIN, GPIO_Mode_In_FL_IT);
	EXTI_SetPinSensitivity(EXTI_Pin_7, EXTI_Trigger_Falling);

  //* Init Bar on LCD all are OFF
  BAR0_OFF;
  BAR1_OFF;
  BAR2_OFF;
  BAR3_OFF;	
	
	enableInterrupts();
	
  
  //* At power on VDD diplays 
	bufMessage = NDEFmessage;
	
	if (EEMenuState > STATE_TEMPMEAS) 
		EEMenuState = STATE_CHECKNDEFMESSAGE;
		
	FLASH_Unlock(FLASH_MemType_Data );

	
	state_machine = EEMenuState ; 
	
	delayLFO_ms (1);
	
	if (EEInitial == 0)
	{
			User_WriteFirmwareVersion ();
			EEInitial =1;
	}
	
  while (1)
  {
    
    switch (state_machine)
    {
			  
				case STATE_VREFF:
					// measure the voltage available at the output of the M24LR04E-R

					Vref_measure();
					delayLFO_ms (2);
					//turn on led
					GPIO_SetBits(GPIOE, GPIO_Pin_6);
			
        break;
				
				case STATE_VBIO:
				//measure the output voltage of biosensor through Pin 7 Port E
				
					CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
						ADC_DeInit(ADC1);
					ADC_VrefintCmd(ENABLE);
					delay_10us(3);
					GPIO_DeInit(GPIOE);
					GPIO_Init(GPIOE,GPIO_Pin_7 ,/*GPIO_Mode_In_FL_No_IT*/GPIO_Mode_In_PU_No_IT);
					ADC_Cmd(ADC1, ENABLE);
					
					ADC_Init(ADC1, ADC_ConversionMode_Single,ADC_Resolution_12Bit, ADC_Prescaler_1);
					
					ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_9Cycles);
					ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE);
					delay_10us(3); // Important delay
					res = 0;
					res_2 = 0;
					i=0;
					for(i=8; i>0; i--)
						{
						/* start ADC convertion by software */
							ADC_SoftwareStartConv(ADC1);
						/* wait until end-of-covertion */
							while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 );
						/* read ADC convertion result */
							res += ADC_GetConversionValue(ADC1);
						}
					/* de-initialize ADC*/ 
					ADC_VrefintCmd(DISABLE);

					ADC_DeInit(ADC1);
 
					/* disable SchmittTrigger for ADC_Channel_24, to save power */
					ADC_SchmittTriggerConfig(ADC1, ADC_Channel_3, DISABLE);
	
					CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);
					ADC_ChannelCmd(ADC1, ADC_Channel_3, DISABLE);
					res = res>>3;
					P_VREFINT_Factory = VREFINT_Factory_CONV_ADDRESS;
					
					
					#ifdef VREFINT_FACTORY_CONV
						if ((*P_VREFINT_Factory>VREFINT_Factory_CONV_MIN ) && (*P_VREFINT_Factory<VREFINT_Factory_CONV_MAX ))
						{
							/* If the value exists:
							Adds the hight byte to FullVREF_FACTORY */
							FullVREF_FACTORY = VREFINT_Factory_CONV_MSB;
							FullVREF_FACTORY += *P_VREFINT_Factory;
							res_2 = (float)(FullVREF_FACTORY*VDD_FACTORY);
							res_2 /= res;
							} else {
											res_2 = (VREF/res) * ADC_CONV; // usally res>>3
											}
											#else
										/* We use the theorcial value */
											res_2 = (VREF/res) * ADC_CONV;
												#endif
						/* Vdd_appli in mV */  
						res_2*= 1000L;
					

						convert_into_char (res_2, tab);
	
							/* To add unit and decimal point  */
						tab[5] = 'V';
						tab[4] = ' ';
						tab[1] |= DOT; /* To add decimal point for display in volt */
						tab[0] = ' ';

						LCD_GLASS_DisplayStrDeci(tab);
						delayLFO_ms (2);
						
					
					//LCD_GLASS_DisplayString("V BIO");
					
					break;
			
			
			
			
        case STATE_CHECKNDEFMESSAGE:
				
						// read the NDEF message from the M24LR04E-R EEPROM and display it if it is found 				
					if (User_ReadNDEFMessage (&PayloadLength) == SUCCESS)						
						User_DisplayMessage (bufMessage,PayloadLength);
	//					User_DisplayMessageActiveHaltMode (PayloadLength);
					else 
						User_DisplayMessage(ErrorMessage,20);		
		
	
        break;
				
				case STATE_TEMPMEAS:
						
						// read the ambiant tempserature from the STTS751
						User_GetOneTemperature (&data_sensor);
						// display the temperature
						User_DisplayOneTemperature (data_sensor);
			
						delayLFO_ms (2);
						
				break;
			
			break;
  
        /* for safe: normaly never reaches */ 			
        default:
					LCD_GLASS_Clear();
					LCD_GLASS_DisplayString("Error");
					state_machine = STATE_VREFF;
        break;
      }
    
		
    }
}