Example #1
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  u8 l_cnt;
  disableInterrupts();
  Config();
  Errors_Init();
  enableInterrupts();
  Goto_HALT();
  
  while (1)
  {
    if((btn_pressed != BUTTON1) && (btn_pressed != BUTTON2))
    {
      DELAY_STOP;
      goto sleep;
    }
    
    while(!DELAY_EXPIRED);           // wait for power-up delay to expire (~20ms)
    DELAY_STOP;
    
    disableInterrupts();
    if(btn_pressed == BUTTON1)
    {
      RF_Send(RFCMD_HEATING_ON);
    }
    else if(btn_pressed = BUTTON2)
    {
      RF_Send(RFCMD_HEATING_OFF);
    }
    enableInterrupts();
    
    sleep:
    Goto_HALT();
  }
}
/*
 Function: Measures actual radiation value during specified time. Maximum time is 60 seconds
 Returns: 
	RadiationValueCPM: radiation value in CPM
 Parameters: 
	time: time while radiation is measured. Time must be in milliseconds
 Values: 
*/
float WaspRadiationBoard::getCPM(long time)
{

	float k=0;
	float minute = 60000;
	unsigned long previous=millis();

	enableInterrupts(RAD_INT);
	while( (millis()-previous<time) )
    {
		if( intFlag & RAD_INT)
		{
			disableInterrupts(RAD_INT);
			intFlag &= ~(RAD_INT);
			countPulse();

			while(!digitalRead(RAD_INT_PIN_MON));
    		enableInterrupts(RAD_INT);
  		}
    
    	// Condition to avoid an overflow (DO NOT REMOVE)
    	if( millis() < previous ) previous=millis();
    }
	k = (minute/time);
   	radiationValueCPM = k*count  ;
   	timePreviousMeassure = millis();
	ledBar(k*count);  
   	count = 0;

	return radiationValueCPM;
}
/*
 Function: Measures actual radiation value during 10 seconds.
 Returns: 
	radiationValue: Returns value of radiation in uSv/H
 Parameters: 
 Values: 
*/
float WaspRadiationBoard::getRadiationInt()
{

	unsigned long timeRepeat= 10000;        
	unsigned long previous=millis();

	enableInterrupts(RAD_INT);

	
	while( (millis()-previous<timeRepeat) )
	{
		if( intFlag & RAD_INT){
			disableInterrupts(RAD_INT);
			intFlag &= ~(RAD_INT);
			countPulse();

			while(!digitalRead(RAD_INT_PIN_MON));
				enableInterrupts(RAD_INT);
		}

		// Condition to avoid an overflow (DO NOT REMOVE)
		if( millis() < previous ) previous = millis();
	}

	radiationValue = 6.0 *count * CONV_FACTOR;
	timePreviousMeassure = millis();
	ledBar(6*count);  
	count = 0;

	return radiationValue;
}
Example #4
0
/**
  * @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);
  }
}
Example #5
0
void timer4_init ()
{
  timer4.setPsc (Btimer::div128);
  timer4.setArr (125);
  enableInterrupts();
  timer4.interrupt (true);
  enableInterrupts();
  timer4.start ();
}
Example #6
0
int main()
{
	
	// Chip errata
	CHIP_Init();
	
	// ensure core frequency has been updated
	SystemCoreClockUpdate();
	
	// start clocks
	initClocks();
		
	// init LEDs
	LED_Init();
	
	// init scheduler
	SCHEDULER_Init();
	
	// enable timers
	enableTimers();
	
	// enable interrupts
	enableInterrupts();
	
	// init tasks
	SCHEDULER_TaskInit(&radio_task, radio_task_entrypoint);
	
	// run
	SCHEDULER_Run();
	
}
Example #7
0
/**
  * @brief  Configure UART1 for the communication with HyperTerminal
  * @param  None
  * @retval None
  */
static void UART1_Config(void)
{
  /* EVAL COM (UART) configuration -----------------------------------------*/
  /* USART configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - Odd parity
        - Receive and transmit enabled
        - UART Clock disabled
  */
  UART1_Init((uint32_t)115200, UART1_WORDLENGTH_8D,UART1_STOPBITS_1, UART1_PARITY_ODD,
                   UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

  /* Enable the UART Receive interrupt: this interrupt is generated when the UART
    receive data register is not empty */
  UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
  
  /* Enable the UART Transmit complete interrupt: this interrupt is generated 
     when the UART transmit Shift Register is empty */
  UART1_ITConfig(UART1_IT_TXE, ENABLE);

  /* Enable UART */
  UART1_Cmd(ENABLE);
  
    /* Enable general interrupts */
  enableInterrupts();
}
/**
  ******************************************************************************
  * @brief Modify the tick values for specific cases when the H/W timer doesn't
  * work (halt, ...).
  * @param [in] Delay Time to add to the ticks (unit is 500 us). Range is [1..65535].
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void TSL_Timer_Adjust(u16 Delay)
{

  disableInterrupts();

  do
  {
    if (Delay > TICK_FACTOR_10MS) /* delay > 10ms */
    {
      TSL_Tick_Base += TICK_FACTOR_10MS;
      Delay -= TICK_FACTOR_10MS;
      TSL_Timer_Check_10ms_Tick();
    }
    else
    {
      TSL_Tick_Base++;
      Delay--;
      TSL_Timer_Check_10ms_Tick();
    }
  }
  while ( Delay );

  enableInterrupts();
  
}
/*
 Function: Measures actual radiation value during specified time. Maximum measure time is 60 seconds
 Returns: 
	radiationValue: Returns value of radiation in uSv/H
 Parameters: 
	time: time while radiation is measured. Time units must be milliseconds
 Values: 
*/
float WaspSensorRadiation::getRadiation(long time){

	float k=0;      //used to obtain CPM
	float minute = 60000;
	long previous=millis();
	
	while( (millis()-previous<time) )
    {
		if( intFlag & RAD_INT){
			disableInterrupts(RAD_INT);
			intFlag &= ~(RAD_INT);
			countPulse();

			while(!digitalRead(RAD_INT_PIN_MON));
    			enableInterrupts(RAD_INT);
  		}
    
    	// Condition to avoid an overflow (DO NOT REMOVE)
    	if( millis()-previous < 0 ) previous=millis();
    }
     	
	k = (minute/time);
	radiationValueCPM = k*count;
   	radiationValue = k*count * CONV_FACTOR;
   	timePreviousMeassure = millis();
	ledBar(k*count);  
   	count = 0;

	return radiationValue;
}
Example #10
0
int main() {
    SYSTEMConfigPerformance(10000000);    //Configures low-level system parameters for 10 MHz clock
    enableInterrupts();                   //This function is necessary to use interrupts.

    //TODO: Write each initialization function
    initLEDs();
    initTimer1();



    while(1) {

        switch(state) {
        case led1:
            LATDbits.LATD0 = ON;
            LATDbits.LATD1 = OFF;
            LATDbits.LATD2 = OFF;
            break;
        case led2:
            LATDbits.LATD0 = OFF;
            LATDbits.LATD1 = ON;
            LATDbits.LATD2 = OFF;
            break;
        case led3:
            LATDbits.LATD0 = OFF;
            LATDbits.LATD1 = OFF;
            LATDbits.LATD2 = ON;
            break;
        }

    }

    return 0;
}
Example #11
0
/**
  ******************************************************************************
  * @brief Initialize memory API and structures.
  * @par Parameters:
  * None
  * @retval void None
  * @par Required preconditions:
  * Must be run once in the main function during initialization phase.
  ******************************************************************************
  */
void TSL_Init(void)
{

  disableInterrupts();

  DetectionIntegrator = DETECTION_INTEGRATOR_DEFAULT;
  EndDetectionIntegrator = END_DETECTION_INTEGRATOR_DEFAULT;
  ECSTimeStep = ECS_TIME_STEP_DEFAULT;
  ECSTemporization = ECS_TEMPO_DEFAULT;
  RecalibrationIntegrator = RECALIBRATION_INTEGRATOR_DEFAULT;
  DetectionTimeout = DTO_DEFAULT;

  ECS_K_Fast = ECS_IIR_KFAST_DEFAULT;
  ECS_K_Slow = ECS_IIR_KSLOW_DEFAULT;
  ECSTimeStepCounter = ECSTimeStep;
  ECSTempoCounter = 0;
  ECSTempoPrescaler = 0;

  TSL_IO_Init();

  TSL_Timer_Init();
  
  TSL_SCKey_Init();
  
#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0
  TSL_MCKey_Init();
#endif

  enableInterrupts();

  TSLState = TSL_IDLE_STATE;

}
Example #12
0
int main() {
	bool newreadings;
	bool buttonschanged;

	load_init();
	initsystem();
	watchdog_init();
	initserial();
	timer_init();
	display_init();
	initfan();
	adc_init();

	buttons_init();

	enableInterrupts();

	protocol_onbooted();

	while (1) {
		watchdog_kick();
		newreadings = adc_updatereadings();
		if (newreadings) {
			checkstate();
		}
		buttonschanged = buttons_check();
		if (newreadings || buttonschanged) {
			protocol_sendstate();
			display_update();
		}

		protocol_checkcommand();
	}
}
Example #13
0
void mcs_turn(int32_t a)
{
  /* a the angle in degrees */

  /* degrees to ticks */
  uint32_t enc = (abs(a) * 10) / 37 - 3;

  disableInterrupts();

  /* turn left or right */
  if (a < 0)
  {
    ldir = 0;
    rdir = 1;
  }
  else
  {
    ldir = 1;
    rdir = 0;
  }

  do_encoder(enc);

  enableInterrupts();
}
Example #14
0
void mcs_move(int32_t d)
{
  /* d the distance in cms */

  /* convert distance to tick */
  uint32_t enc = abs(d) * CONFIG_TICK_PER_CM;

  disableInterrupts();

  /* forward or backward direction */
  if (d < 0)
  {
    ldir = 0;
    rdir = 0;
  }
  else
  {
    ldir = 1;
    rdir = 1;
  }

  do_encoder();

  enableInterrupts();
}
Example #15
0
int main() 
{
    enableInterrupts();
    initTMR2();
    char key = 'x';
    
    while(1);
    {
       clearLCD();
       InitKeyPad();
       
       switch(state)
       {
           case findKey:
               ScanKeys(); //should i update the key value here?
               break;
           case debouncePress:
               delayUs(5000); //Proper Delay?
               break;
           case debounceRelease:
               delayUs(5000);
               break;
           case display:
               printCharLCD(key);
               break;
       }
    }
    
}
Example #16
0
void TIM2_IRQHandler(void)
{
  /* 10hz frequency */

  /* todo: reduce the scope by capturing variables */
  disableInterrupts();

  /* forward */
  if ((dir != 1) || (speed <= 0)) goto on_done;

  if (lenc < speed) lpwm += 2; /* I_up */
  else if (lenc > speed) lpwm -= 2;

  if (renc < speed) rpwm += 2;
  else if (renc > speed) rpwm -= 2;

  err = clamp(err + lenc - renc, -128, 128);

  /* reset encoder counters */
  lenc = 0;
  renc = 0;

  lpwm = clamp(CONFIG_START_POWER_FWD + lpwm - err, 0, 255);
  rpwm = clamp(CONFIG_START_POWER_FWD + rpwm - err, 0, 255);

  set_lpwm(lpwm);
  set_rpwm(rpwm);

 on_done:
  TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  enableInterrupts();
}
/**
 * Enable interrupts to occur on this input.
 * Interrupts are disabled when the RequestInterrupt call is made. This gives
 * time to do the
 * setup of the other options before starting to field interrupts.
 */
void InterruptableSensorBase::EnableInterrupts() {
  if (StatusIsFatal()) return;
  wpi_assert(m_interrupt != nullptr);
  int32_t status = 0;
  enableInterrupts(m_interrupt, &status);
  wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
Example #18
0
/*主程序*/
void main()
{	
	CLK_Config();

	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER3, ENABLE);	

	/* Check if the system has resumed from IWDG reset */
	if (RST_GetFlagStatus(RST_FLAG_IWDGF) != RESET)
	{
	  /* Clear IWDGF Flag */
	  RST_ClearFlag(RST_FLAG_IWDGF);
	}
	
	/*通信串口初始化*/
	DBG_Config();
	
	IR_Init();
	
	printf("starting...\n");

	/*打开全局中断*/
	enableInterrupts();    

	while (1)
	{
		IR_Process();
	}
		
}
Example #19
0
int main(void)
{
    SYSTEMConfigPerformance(10000000);
    initTimer1();
    initSW2();
    initLEDs();
    enableInterrupts();
    state = led1;

    while(1)
    {
        //TODO: Using a finite-state machine, define the behavior of the LEDs
        //Debounce the switch
        switch(state) {
        case led1:
            turnOnLED(1);
            stateNext = led2;
            break;

        case led2:
            turnOnLED(2);
            stateNext = led1;
            break;

        case deBounce1:
            delayUs(10000);
            break;
        case deBounce2:
            delayUs(10000);
            break;
        }
    }

    return 0;
}
Example #20
0
/**
  * @brief  Configure ADC and Analog watchdog
  * @param  None
  * @retval None
  */
static void ADC_Config(void)
{
    /* Enable ADC1 clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

    /* Initialise and configure ADC1 */
    ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2);
    ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);

    /* Enable ADC1 */
    ADC_Cmd(ADC1, ENABLE);

    /* Enable ADC1 Channel 3 */
    ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE);

    /* Calculate Threshold data value*/
    HighThresholdData = (uint16_t)(((uint32_t)HIGH_THRESHOLD_VOLTAGE * 1000) / (uint32_t)ADC_RATIO) ;
    LowThresholdData  = (uint16_t)(((uint32_t)LOW_THRESHOLD_VOLTAGE * 1000) / (uint32_t)ADC_RATIO) ;

    /* Configure Analog Watchdog selected channel and Thresholds */
    ADC_AnalogWatchdogConfig(ADC1, ADC_AnalogWatchdogSelection_Channel3,
                             HighThresholdData,
                             LowThresholdData);

    /* Enable Analog watchdog ADC1 Interrupt */
    ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);

    /* Enable Interrupts */
    enableInterrupts();

    /* Start ADC1 Conversion using Software trigger*/
    ADC_SoftwareStartConv(ADC1);
}
Example #21
0
int kickoff() {
	initVideo();	
	putStr("Hello World! - Team Virtua!!!\n");
	
 	installDescriptorTables();
	installTimer();
	installKeyboard();	
    initializePaging();    
	putStr("Hello, paging world! - Team Virtua !!!\n");	

	enableInterrupts();	

	
	// u32 end_addr = (u32)&end;
	// u32 *ptr = (u32 *)end_addr;		
	
	// while(1) {
		// putStr("End Address : ");
		// putHex(end_addr);
		// putStr(" ");
		// putHex((u32)ptr);
		// putStr(" : ");
		// putNum(*ptr);
		// putStr("\n");
		// ptr++;	
	// }
			
    putStr("Gotcha!!!\n");

    for (;;);
	return 0;	
}
Example #22
0
/**
  ******************************************************************************
  * @brief Initialize all the TS keys
  * @par Parameters:
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void ExtraCode_Init(void)
{

  u8 i;

  /* All keys are implemented and enabled */

  for (i = 0; i < NUMBER_OF_SINGLE_CHANNEL_KEYS; i++)
  {
    sSCKeyInfo[i].Setting.b.IMPLEMENTED = 1;
    sSCKeyInfo[i].Setting.b.ENABLED = 1;
    sSCKeyInfo[i].DESGroup = 0x01; /* Put 0x00 to disable the DES on these pins */
  }

#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0
  for (i = 0; i < NUMBER_OF_MULTI_CHANNEL_KEYS; i++)
  {
    sMCKeyInfo[i].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[i].Setting.b.ENABLED = 1;
    sMCKeyInfo[i].DESGroup = 0x01; /* Put 0x00 to disable the DES on these pins */
  }
#endif

  enableInterrupts();
}
/**
  ******************************************************************************
  * @brief Modify the tick values for specific cases when the H/W timer doesn't
  * work (halt, ...).
  * @param[in] adjust_delay Time to add to the ticks (unit is 500µs).
  * @retval None
  ******************************************************************************
  */
void TSL_Timer_Adjust(uint32_t adjust_delay)
{

  disableInterrupts();

  do
  {
    if (adjust_delay > TICK_FACTOR_10MS)
    {
      TSL_Tick_Base += TICK_FACTOR_10MS;
      adjust_delay -= TICK_FACTOR_10MS;
      TSL_Timer_Check_10ms_Tick();
    }
    else
    {
      TSL_Tick_Base++;
      adjust_delay--;
      TSL_Timer_Check_10ms_Tick();
    }
  }
  while (adjust_delay);

  enableInterrupts();

}
Example #24
0
void main(void)
{
	char x=10;
	char y=10;
	
	CLK->CKDIVR = 0;
	disableInterrupts();
	Init_GPIO();
	Init_TIM1();
	Init_Clock();
	usb_init();
	enableInterrupts();

	while(usb_ready == 0)
	{
		usb_process();
	}
	while(1)
	{
		delay(100);
		
		if(get_random_byte()>127)
		{
			x=-x;
			y=-y;
		}
		
		data_buffer[0] = 0x00;
		data_buffer[1] = x;
		data_buffer[2] = y;
		data_buffer[3] = 0x00;
		usb_send_data(&data_buffer[0], 4, 0);
	}
}
Example #25
0
File: main.c Project: yali101/LAB0
int main() {
    //SYSTEMConfigPerformance(10000000);    //Configures low-level system parameters for 10 MHz clock
    enableInterrupts();                   //This function is necessary to use interrupts.

    //TODO: Write each initialization function
    initLEDs();
    initTimer1();
    
    while(1){
        //TODO: Implement a state machine to create the desired functionality
        
        switch(state){
            case led1:  //LED1 is on
                LATDbits.LATD0 = ON;
                LATDbits.LATD1 = OFF;
                LATDbits.LATD2 = OFF;
                break;
            case led2:  //LED2 is on
                LATDbits.LATD0 = OFF;
                LATDbits.LATD1 = ON;
                LATDbits.LATD2 = OFF;
                break;
            case led3:  //LED3 is on
                LATDbits.LATD0 = OFF;
                LATDbits.LATD1 = OFF;
                LATDbits.LATD2 = ON;
                break;
        } 
    }
    return 0;
}
Example #26
0
int main() {
    
    //This function is necessary to use interrupts. 
    enableInterrupts();
    initSwitch1();
    initLEDs();
    
    while(1){
        switch (state){
            case led1:
                if(PORTDbits.RD7 == 0){
                    delayMs();
                    i=2;
                    wait2();
                    state = debounceRelease; 
                }
                break; 
            case led2:
                if(PORTDbits.RD7 == 0){
                    delayMs();
                    i=3;
                    wait2();
                    state = debounceRelease;
                }
                break; 
            case led3:
                if(PORTDbits.RD7 == 0){
                    delayMs();
                    i=1;
                    wait2();
                    state = debounceRelease;   
                }
                break; 
        }
        
        if(state == debounceRelease){
            if(PORTDbits.RD7 == 1){
                if(IFS0bits.T2IF == 1){ 
                i=i+1;
                if(i == 4) i=1; 
                turnOffTimer2();
                } 
                delayMs();
                if(i == 3){ 
                    turnOnLED(3);
                    state = led3;  
                }
                else if(i == 1){
                    turnOnLED(1);
                    state = led1;
                }
                else { 
                    turnOnLED(2);
                    state = led2; 
                }
            }       
        }
    }
    return 0;
}
Example #27
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    /* I2C  clock Enable*/
    CLK_PeripheralClockConfig(CLK_Peripheral_I2C, ENABLE);

    /* system_clock / 1 */
    CLK_MasterPrescalerConfig(CLK_MasterPrescaler_HSIDiv1);

    /* Initialize LEDs mounted on the EVAL board */
    STM_EVAL_LEDInit(LED2);
    STM_EVAL_LEDInit(LED3);

    I2C_DeInit();
    /* Initialize I2C peripheral */

#ifdef I2C_slave_7Bits_Address
    I2C_Init(100000, SLAVE_ADDRESS, I2C_DutyCycle_2, I2C_Ack_Enable,
             I2C_AcknowledgedAddress_7bit);
#else
    I2C_Init(100000, SLAVE_ADDRESS, I2C_DutyCycle_2, I2C_Ack_Enable,
             I2C_AcknowledgedAddress_10bit);
#endif

    /* Enable Error Interrupt*/
    I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_ERR | I2C_IT_EVT | I2C_IT_BUF), ENABLE);

    /* Enable general interrupts */
    enableInterrupts();

    /*Main Loop */
    while (1)
    {
        /* infinite loop */
    }
}
Example #28
0
/**
  * @brief Example main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
  /* Initialize I/Os in Output Mode for LEDs */
  GPIO_Init(LEDS_PORT, LED1_PIN | LED2_PIN, GPIO_MODE_OUT_PP_LOW_FAST);
	
  /* Initialize I/O in Input Mode with Interrupt for button and joystick */
	/* Button */
  GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT);
  /* Joystick */
  GPIO_Init(JOYSTICK_PORT, JOYSTICK_DOWN_PIN, GPIO_MODE_IN_FL_IT);

  /* Initialize the Interrupt sensitivity for button and joystick */
  EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOB, EXTI_SENSITIVITY_FALL_LOW);
  EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_LOW);

  /*
    Change the software priority between button and joystick:
    - By hardware the PORTB (joystick) has a higher priority than PORTC (button)
    - We configure the PORTC (button) to have a higher sw priority than PORTB (joystick)
  */
  ITC_SetSoftwarePriority(ITC_IRQ_PORTB, ITC_PRIORITYLEVEL_1); /* joystick */
  ITC_SetSoftwarePriority(ITC_IRQ_PORTC, ITC_PRIORITYLEVEL_2); /* button = higher sw priority */

  enableInterrupts();

  /* LEDs are ON together */
  GPIO_WriteHigh(LEDS_PORT, (LED1_PIN | LED2_PIN));
 
  while (1);
}
Example #29
0
int main() {
    SYSTEMConfigPerformance(10000000);    //Configures low-level system parameters for 10 MHz clock
    enableInterrupts();                   //This function is necessary to use interrupts.

    initLEDs();
    initTimer1();
    
    while(1){
        switch(state) {
            case INIT:
                next_state = LED_0;
                break;
            case LED_0:
                turnOnLED(0);
                next_state = LED_1;
                break;
            case LED_1:
                turnOnLED(1);
                next_state = LED_2;                
                break;
            case LED_2:
                turnOnLED(2);
                next_state = LED_0;
                break;
        }
    }
    
    return 0;
}
Example #30
0
void main(void)
{
    u16 trigpos;
    u8 keycode;
    
    SystemState = AutoRunMode;
    // 现在还是使用软件触发
	  ADCState = Triggered;       // ADCState = WaitTrigger;

    CLK_Init();                 // 主时钟初始化
    TIM4_Init();                // TIM4 用于产生系统运行需要的定时信号
    KEY_Init();                 // 按键驱动初始化
    KeyParse_Init();            // 按键处理模块初始化
    LCD_Init();                 // LCD驱动初始化
    WDraw_Init();               // 波形显示模块初始化
    TriggerInterruptInit();     // 外部触发中断初始化
    ADC_Init();                 // ADC采样程控模块初始化
    DProc_Init();               // 数据处理模块初始化
  

    enableInterrupts();

    /* Infinite loop */
    while (1)
    {
    
				if(flag_10ms_ok)
        {
            flag_10ms_ok = 0;
            keycode = KEY_Scan();
						switch(GET_KTYPE(keycode))
            {
                case KTYPE_NORMAL:
                    KeyParse(GET_KCODE(keycode));
                default:
                    break;
            }
        }
        switch(SystemState)
        {
            // to do
            case AutoRunMode:
            case ManualMode:
                //  处理数据
                if( ADCState == ADC_Buffer_Full )
                {
                    trigpos = GetTriggerPostion(0, 64);
                    WDraw_DisplayUpdate(&ADC_Buffer[trigpos]);
                    ADCState = Triggered;
                    ADC_Index = 0;
                }
                break;
            default:
                break;
        }
		
		}
  
}