Exemple #1
0
int main(void)
{	      
  int32_t dac_data = 0;
  int8_t inc_dir = 1;
  char buffer[16];
  
	RCC->AHBENR |= RCC_AHBENR_GPIOAEN; 	// enable the clock to GPIOA
	RCC->AHBENR |= RCC_AHBENR_GPIOBEN; 	// enable the clock to GPIOB
	RCC->AHBENR |= RCC_AHBENR_GPIOCEN; 	// enable the clock to GPIOC

	// Put PORTC.8 in output mode
	GPIOC->MODER |= (1 << 16);

	// Put PORTC.9 in output mode
	GPIOC->MODER |= (1 << 18);

	// Put PORTA.0 in input mode
	GPIOA->MODER &= ~(3 << 0);

	// This configures interrupt such that SysTick_Handler is called
	// at ever TIMER_TICK_HZ i.e. 1/1000 = 1ms
	SysTick_Config(SystemCoreClock / TIMER_TICK_HZ);
	
	// Initialize the lcd	
	lcd_init();
  dac_init();
  	  
	lcd_puts("   STM32F051");	
	lcd_gotoxy(1, 4);
	lcd_puts("DAC TEST");  
  delay_ms(2000);
  
  lcd_clear();
  lcd_puts("DAC Value (PA4): ");
  
  // Generate a step wave on DAC output whose amplitude is
  // proportional to the voltage on ADC input.
	while(1)
	{            
    DAC_SetChannel1Data(DAC_Align_8b_R, dac_data);
    DAC_SoftwareTriggerCmd(0, ENABLE);
    dac_data += (10 * inc_dir);
    if(dac_data > 255)
    {
      dac_data = 250;
      inc_dir = -1;
    }
    else if(dac_data < 0)
    {
      dac_data = 0;
      inc_dir = 1;
    }
    
    int_to_str(dac_data, 5, buffer, sizeof(buffer));
    lcd_gotoxy(1, 0);
    lcd_puts(buffer);
    delay_ms(1000);    
	}

}
Exemple #2
0
void DAC_VOLTAGE_Configuration(void)
{
	DAC_InitTypeDef DAC_InitStructure;
	DAC_DeInit();
	DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
	DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;      
	DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
	DAC_Init(DAC_Channel_1, &DAC_InitStructure);
	DAC_Cmd(DAC_Channel_1, ENABLE);
	DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
}
Exemple #3
0
uint8_t Dac_Output(uint8_t channel, uint16_t value)
{
    switch(channel) {
        case 1: 
            if(!(ChannelEn & DAC_CH1_EN)) return 0;
                DAC_SetChannel1Data(DAC_Align_12b_R,value);
                DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
                while(DAC->SWTRIGR & 0x0001);
            return 1;

        case 2:
            if(!(ChannelEn & DAC_CH2_EN)) return 0;
                DAC_SetChannel2Data(DAC_Align_12b_R,value);
                DAC_SoftwareTriggerCmd(DAC_Channel_2,ENABLE);
                while(DAC->SWTRIGR & 0x0002);
            return 1;
        
        default: return 0;
    }
}
void SetAnalogOutput(int dacOutput, int value)
{
    assert_param(IS_DAC_ID_VALID(dacNumber));
    
    if(value >= 0 && value <= 4095)
    {    
        switch(dacOutput)
        {
        case DAC_1:
            DAC_SoftwareTriggerCmd(DAC_Channel_1, DISABLE);
            DAC_SetChannel1Data(DAC_Align_12b_R, value);
            DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
            break;
        case DAC_2:
            DAC_SoftwareTriggerCmd(DAC_Channel_2, DISABLE);
            DAC_SetChannel2Data(DAC_Align_12b_R, value);
            DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE);
            break;
        }
    }
}
Exemple #5
0
void stm32dac_init(void)
{
 	DAC_InitTypeDef DAC_InitStructure;
 	GPIO_InitTypeDef GPIO_InitStructure;
 	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
 	GPIO_InitStructure.GPIO_Pin = (STM32DAC0 | STM32DAC1);
 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
 	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
 	GPIO_Init(STM32DAC_PORT, &GPIO_InitStructure);
 	/* DAC channel1 Configuration */
 	DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
 	DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
 	DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
 	//DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bits4_0;
 	DAC_Init(DAC_Channel_1, &DAC_InitStructure);	
 	DAC_Init(DAC_Channel_2, &DAC_InitStructure); 	
 	DAC_Cmd(DAC_Channel_1, ENABLE);
 	DAC_Cmd(DAC_Channel_2, ENABLE);
 	DAC_SetChannel1Data(DAC_Align_12b_R,0x0);DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
 	DAC_SetChannel2Data(DAC_Align_12b_R,0x0);DAC_SoftwareTriggerCmd(DAC_Channel_2,ENABLE);
	
}
Exemple #6
0
void Dac_Init(uint8_t channel1, uint8_t channel2)
{   
    DAC_InitTypeDef DAC_InitStructure;

    ChannelEn = (channel1 ? DAC_CH1_EN : 0) | (channel2 ? DAC_CH2_EN : 0);
    Dac_PinInit();
    
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

    DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
    DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
    DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;
    DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;

    if(ChannelEn & DAC_CH1_EN) DAC_Init(DAC_Channel_1, &DAC_InitStructure);
    if(ChannelEn & DAC_CH2_EN) DAC_Init(DAC_Channel_2, &DAC_InitStructure);

    if(ChannelEn & DAC_CH1_EN) DAC_Cmd(DAC_Channel_1, ENABLE);
    if(ChannelEn & DAC_CH2_EN) DAC_Cmd(DAC_Channel_2, ENABLE);

    if(ChannelEn & DAC_CH1_EN) DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
    if(ChannelEn & DAC_CH2_EN) DAC_SoftwareTriggerCmd(DAC_Channel_2,ENABLE);
}
// initValue - 0 - 4095
void Init_DAC_1(int initValue)
{
    DAC_InitTypeDef  DAC_InitStructure;
    
    //Set DAC clock
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
    
    /* DAC channel1 Configuration */
    DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
    DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
    DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
    
    
    DAC_DeInit(); 
    DAC_Init(DAC_Channel_1, &DAC_InitStructure);
    DAC_Cmd(DAC_Channel_1, ENABLE);
    DAC_SetChannel1Data(DAC_Align_12b_R, initValue);
    DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
}
Exemple #8
0
void BIAS_Config(void){
	DAC_InitTypeDef DAC_InitStructure;
	GPIO_InitTypeDef GPIO_InitStructure;
	DAC_DeInit();
  /* DAC Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
	 /* DAC channel1 Configuration */
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude =  DAC_TriangleAmplitude_1;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);
	/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 
     automatically connected to the DAC converter. */
  DAC_Cmd(DAC_Channel_1, ENABLE);
  /* Set DAC Channel1 DHR12L register */
  //DAC_SetChannel1Data(DAC_Align_12b_L, 0x7FF0);
  //DAC_SetChannel1Data(DAC_Align_12b_L, 0x9B20);
	//DAC_SetChannel1Data(DAC_Align_12b_R, 0x04D9);
	//BIAS_DAC_Value = DAC_GetDataOutputValue(DAC_Channel_1);
	DAC_SetChannel1Data(DAC_Align_12b_R, DAC_OUT_BOOT);
	//BIAS_DAC_Value = DAC_GetDataOutputValue(DAC_Channel_1);
	DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
	BIAS_DAC_Value = DAC_GetDataOutputValue(DAC_Channel_1);
  /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically 
     connected to the DAC converter. In order to avoid parasitic consumption, 
     the GPIO pin should be configured in analog */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);	 
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	 /* Used peripherals clock enable -------------------------------------------*/
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
	
	 /* configure PC9 as output push-pull  */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
	GPIO_SetBits(GPIOC, GPIO_Pin_9);	
}
Exemple #9
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_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     
       
  /* System Clocks Configuration */
  RCC_Configuration();   

  /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically 
     connected to the DAC converter. In order to avoid parasitic consumption, 
     the GPIO pin should be configured in analog */
  GPIO_Configuration();

  /* DAC channel1 Configuration */
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Noise;
  DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits8_0;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);

  /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 
     automatically connected to the DAC converter. */
  DAC_Cmd(DAC_Channel_1, ENABLE);

  /* Set DAC Channel1 DHR12L register */
  DAC_SetChannel1Data(DAC_Align_12b_L, 0x7FF0);

  while (1)
  {
    /* Start DAC Channel1 conversion by software */
    DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
  }
}
Exemple #10
0
void DAC_SetVoltage(uint32 CH,uint16 Data)
{
	DAC_SetChannel1Data(CH,Data);
	DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
}
Exemple #11
0
void stm32dac1(uint16_t t)		
{
	DAC_SetChannel2Data(DAC_Align_12b_R,(uint16_t)t);
	DAC_SoftwareTriggerCmd(DAC_Channel_2,ENABLE);
}
Exemple #12
0
int main(void)
{	      
  const uint8_t sine_wave[] = {128,152,176,198,218,234,245,253,
                               255,253,245,234,218,198,176,152,
                               128,103,79,57,37,21,10,2,
                               0,2,10,21,37,57,79,103,};  
  int32_t dac_data_cnt = 0; 
  float scale_factor = 1.0;
  char buffer[16];
  
	RCC->AHBENR |= RCC_AHBENR_GPIOAEN; 	// enable the clock to GPIOA
	RCC->AHBENR |= RCC_AHBENR_GPIOBEN; 	// enable the clock to GPIOB
	RCC->AHBENR |= RCC_AHBENR_GPIOCEN; 	// enable the clock to GPIOC

	// Put PORTC.8 in output mode
	GPIOC->MODER |= (1 << 16);

	// Put PORTC.9 in output mode
	GPIOC->MODER |= (1 << 18);

	// Put PORTA.0 in input mode
	GPIOA->MODER &= ~(3 << 0);

	// This configures interrupt such that SysTick_Handler is called
	// at ever TIMER_TICK_HZ i.e. 1/1000 = 1ms
	SysTick_Config(SystemCoreClock / TIMER_TICK_HZ);
	
	// Initialize the lcd	
	lcd_init();
  adc_init();
  // Confgure 
  ADC_ChannelConfig(ADC1, ADC_Channel_0, ADC_SampleTime_28_5Cycles);
  // Start the first conversion
  ADC_StartOfConversion(ADC1);
  
  dac_init();
  	  
	lcd_puts("   STM32F051");	
	lcd_gotoxy(1, 1);
	lcd_puts("ADC DAC TEST");  
  delay_ms(2000);
  
  lcd_clear();
  lcd_puts("ADC Value (PA0): ");
  
  // Generate a step wave on DAC output
	while(1)
	{        
    uint16_t adc_value;       
    
    if(dac_data_cnt == 0)
    {
      adc_value = ADC_GetConversionValue(ADC1);
      scale_factor = (float)adc_value / 4095;
      int_to_str(adc_value, 5 /*num of digits*/, buffer, sizeof(buffer));
      lcd_gotoxy(1, 0);
      lcd_puts(buffer);
    }
    
    DAC_SetChannel1Data(DAC_Align_8b_R, scale_factor * sine_wave[dac_data_cnt]);
    DAC_SoftwareTriggerCmd(0, ENABLE);
    dac_data_cnt = (dac_data_cnt + 1) % sizeof(sine_wave);         
	}
}
Exemple #13
0
/********************************************************************
 * DAC1 initialization code template
********************************************************************/
void DAC1_Init()
{

    GPIO_InitTypeDef GPIO_InitStructure;
    DAC_InitTypeDef DAC_InitStructure;
	
	
    /* Enable peripheral clocks ------------------------------------*/
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // GPIOA Periph clock enable 
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);  // DAC Periph clock enable 
	
	    
    /*GPIO Configuretion -------------------------------------------*/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
	
    
	   /*DAC1 Configuretion ----------------------------------------*/
	   DAC_InitStructure.DAC_Trigger = $DAC1Tri$; //Trigger Source	
	   
	   
	   
	   DAC_InitStructure.DAC_WaveGeneration = $DAC1WaveGene$; //Wave Chose  
	   #if(STRCMP($DAC1WaveGene$,DAC_WaveGeneration_Noise) == 1)	
	   DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = $DAC1LFSRUnma$; //LFSR Unmask 
	   #endif
	   #if(STRCMP($DAC1WaveGene$,DAC_WaveGeneration_Triangle) == 1)	
	   DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = $DAC1TriAmpli$;//Triangle Edge 
	   #endif    	
	   DAC_InitStructure.DAC_OutputBuffer = $DAC1OutBuff$; //Ouput Buffer Enable 
	
	
	
	   /*DAC1 Init ------------------------------------------------------*/
	   DAC_Init(DAC_Channel_1, &DAC_InitStructure);
	   /*DAC1 Enable ----------------------------------------------------*/
	   DAC_Cmd(DAC_Channel_1, ENABLE);	
	
	
	
	   #if(STRCMP($DAC1Tri$,DAC_Trigger_Software) == 1)
	   /*Software Trigger Enable -----------------------------------------*/
	   DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
	   #endif
	
	
	   #if(STRCMP($DAC1WaveGene$,DAC_WaveGeneration_Noise) == 1)
	   /*Noise Generation Enable ------------------------------------------*/
	   DAC_WaveGenerationCmd(DAC_Channel_1, DAC_Wave_Noise, ENABLE);
	   #endif
	   #if(STRCMP($DAC1WaveGene$,DAC_WaveGeneration_Triangle) == 1)
	   /*Trigger Wave Generation Enable -----------------------------------*/
	   DAC_WaveGenerationCmd(DAC_Channel_1, DAC_Wave_Triangle, ENABLE);
	   #endif
	
	
       #if(STRCMP($DMAEn$,ENABLE) == 1) 
    /*DMA Enable--------------------------------------------------------*/	
    DAC_DMACmd(DAC_Channel_1, ENABLE);
       #endif	
	   #if(STRCMP($DAC1Int$,ENABLE) == 1)
	   /*Enables  DAC1 Interrupts -----------------------------------------*/
	   DAC_ITConfig(DAC_Channel_1, DAC_IT_DMAUDR, ENABLE);
	   #endif
	
	   
	   #if(STRCMP($AlignSty$,DAC_Align_8b_R) == 1)
	   /*8 bit Data Right Align Register Set--------------------------------*/
	   DAC_SetChannel1Data($AlignSty$, $EightB$);
	   #endif
	   #if(STRCMP($AlignSty$,DAC_Align_12b_L) == 1)
	   /*12 bit Data Light Align Register Set--------------------------------*/
	   DAC_SetChannel1Data($AlignSty$, $ElevB$);
	   #endif
	   #if(STRCMP($AlignSty$,DAC_Align_12b_R) == 1)
	   /*12 bit Data Right Align Register Set--------------------------------*/
	   DAC_SetChannel1Data($AlignSty$, $ElevB$);
	   #endif	
    
}
int main(void)
{
//***********************************DEBUG********************************************/
#if 0

nmeaPOS p1,p2;
nmeaINFO info;
info.lat = 5547.1206;
info.lon = 4906.2111;
nmea_info2pos(&info, &p1);
info.lat = 5547.1221;
info.lon = 4906.208;
nmea_info2pos(&info, &p2);

m += 23;

u32 t    = nmea_distance(&p1, &p2);
if(m)
#endif
//***********************************END OF DEBUG********************************************/
  NVIC_Configuration();	//for  all peripheria
  if (SysTick_Config(SystemCoreClock / 1000))  //1ms
     { 
       /* Capture error */ 
       while (1);
     }
  Delay(500);


  USBIniPin();
  	  
  signUSBMass = USBDetectPin();
  signUSBMass = 0;  //deb
  #if not defined (VER_3)
    USBCommonIni(); 
  #endif
  if(signUSBMass)
    {
	 #if defined (VER_3)
	 USBCommonIni();
	 #endif
     while (bDeviceState != CONFIGURED);
	}
  else //if(!signUSBMass)
   {

  	 /* Flash unlock */
     FLASH_Unlock();
     /* Clear All pending flags */
     FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);	

//***********************************DEBUG********************************************/

     
//***********************************END OF DEBUG********************************************/
  /* Enable CRC clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
    
  ledDioGPIOInit();
  led_dn(BOARD_LED_ON);
  led_mid(BOARD_LED_ON);
#if defined (VER_3)
  led_up(BOARD_LED_ON);
  ibuttonInit();
  rfmodemInit();
#endif
  Delay(1000);
  alarmInit();
  BKPInit();

  //timer6Init();

  //rs485Init();
#if not defined (VER_3)
  ais326dq_init();
#endif

  //ais326dq_data(&ais326dq_out);
  /*ADC*/
  adcInit();
  /*GPS*/
  gpsInit();

  /* reading settings */
  readConfig();
  /*MODEM*/
  gprsModemInit();
  gprsModemOn(innerState.activeSIMCard);
//***********************************DEBUG********************************************/
  //GSMSpeaker(1);
//***********************************END OF DEBUG********************************************/

#ifndef BRIDGE_USB_GSM
  setupGSM();
  ftpGSMPrepare();
  packetsIni();
#endif

  led_dn(BOARD_LED_OFF);
  led_mid(BOARD_LED_OFF);
#if defined (VER_3)
  led_up(BOARD_LED_OFF);
#endif

  rtc_init();
  rtc_gettime(&rtc);

#if 1			  /* WATCH DOG */
  /* IWDG timeout equal to 3.27 sec (the timeout may varies due to LSI frequency dispersion) */
  /* Enable write access to IWDG_PR and IWDG_RLR registers */
  IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  /* IWDG counter clock: 40KHz(LSI) / 32 = 1.25 KHz */
  IWDG_SetPrescaler(IWDG_Prescaler_64);	//32
  /* Set counter reload value to 0xFFF */
  IWDG_SetReload(0xFFF);
  /* Reload IWDG counter */
  IWDG_ReloadCounter();
  /* Enable IWDG (the LSI oscillator will be enabled by hardware) */
  IWDG_Enable();
  setTimerIWDG(ONE_SEC);
#endif

  initSD();
#if defined (VER_3)
  //DACInit();
#endif

  /* Log  */
  saveSDInfo((u8 *)"TURN ON BLOCK ",strlen((u8 *)"TURN ON BLOCK "), SD_SENDED, SD_TYPE_MSG_LOG );
  //saveSDInfo((u8 *)readRTCTime(&rtc),strlen((const char *)readRTCTime(&rtc)), SD_SENDED, SD_TYPE_MSG_LOG );
#if defined (VER_3)  
  //DACSpeaker(1);
  //wp_play("0:/sound.wav");
  //DACSpeaker(0);
#endif 

  }	 //if(!signUSBMass)

  while (1)
  {
    if(!signUSBMass)
	  {
		 monitorWatchDog();

		 #ifndef BRIDGE_USB_GPS
	     if(!innerState.bootFTPStarted)
	         gpsHandling();
		 #endif

		 #ifndef BRIDGE_USB_GSM
		 if(!innerState.flagTmpDebug)
		    loopGSM();
			loopFTP();
            UpdatingFlash();
			if(!innerState.bootFTPStarted)
			   naviPacketHandle();
			rcvPacketHandle();
            rcvPacketHandleUSB();
		 #endif 

		 #if !defined (VER_3)
			 buttonScan();
		     accelScan();
		 #endif
		 
		 //rs485Analyse();
		 handleFOS();
		 executeDelayedCmd();
#if defined (VER_3)
		 #if 0 
		 if(innerState.flagDebug)
		 {
  			DACSpeaker(1);
	        /* Start DAC Channel1 conversion by software */
		    //a += 300;
    		//DAC_SetChannel1Data(DAC_Align_12b_R, 4000);
    		//DAC_SetChannel1Data(DAC_Align_12b_L, a);  //for saw
    		//DAC_SetChannel1Data(DAC_Align_8b_R, a);
			
			//DAC_SetChannel1Data(DAC_Align_12b_R, 4095);
			//DAC_SetChannel1Data(DAC_Align_12b_R, 0);
			//for (a = 0; a<4095; ++a)
			//for(;;)
			//  DAC_SetChannel1Data(DAC_Align_12b_R, 0);

			//DAC_SetChannel1Data(DAC_Align_12b_R, 0);
			//for ( ; ; )
			//{
			//   DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
			//}
 

	        DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);  //debugga
		 }
		 else
		 {
		     DACSpeaker(0);
		 }
	  #endif
#endif
	 }
	else
	  handleUSBPresent();
  }	   //while(1)
}