コード例 #1
0
ファイル: main.c プロジェクト: david1mdavis/sam3s-demo-source
/**
  * @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;
      }
    
		
    }
}	
コード例 #2
0
ファイル: main.c プロジェクト: SWilliams100/biosensor-code
/**
  * @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;
      }
    
		
    }
}