Пример #1
0
//-----------------------------------------------------------------------------
//
//  InitDevice
//! \brief   Description:  This function will init the device
//
//  Entry:
//!   \param
//!   This routine does not have any input parameters.
///
//  Exit:
//!   \return NONE ( Does not return any values )
//-----------------------------------------------------------------------------
void InitDevice( void ){

  //Stop watchdog
  LowLevelInit();

  //Setup LEDs
  InitLEDs();

  //Configure clocks at 16MHz
  ConfigureClocks();

  //Initialize the button interupt for forcing last/saved roast curve
  InitBtnInterrupt();

  //Initialize PWM for fan
  InitPWM();

  //Initialize thermocouple for sampleing temp
  InitTherm();

  //Set ACLK to use internal VLO (12 kHz clock)
	BCSCTL3 |= LFXT1S_2;

	//Set TimerA to use auxiliary clock in UP mode
	TACTL = TASSEL_1 | MC_1;
	//Enable the interrupt for TACCR0 match
	TACCTL0 = CCIE;

  // Set TACCR0 which also starts the timer. At 12 kHz, counting to 12000
	// should output an LED change every 1 second. Try this out and see how
	// inaccurate the VLO can be
	TACCR0 = 3000;

} //InitDevice
Пример #2
0
int main(void)
{
    uint16_t sysTimerFrequency=1000;
    uint32_t TheTime = 0;
    sysTimerSetup(sysTimerFrequency,sysTimerCallback); // Sets up interrupt
    InitLEDs();
    UserPBInit();
    
    down = 0;

    while (1)
    {
        if( tick )
        {     
            tick = 0;
            TheTime = TheTime + (down ? -1 : 1);
            TheTime = TheTime % (1<<LED_COUNT);
            
            GPIOA->ODR &= CLEAR_A;
            GPIOC->ODR &= CLEAR_C;
            GPIOF->ODR &= CLEAR_F;
            
            //               Time Bit     GPIO pin
            GPIOC->ODR |= ( TheTime & 1    ? 1<<1 : 0 );
            GPIOC->ODR |= ( TheTime & 1<<1 ? 1<<3 : 0 );
            GPIOA->ODR |= ( TheTime & 1<<2 ? 1<<1 : 0 );
            GPIOC->ODR |= ( TheTime & 1<<3 ? 1<<0 : 0 );
            GPIOC->ODR |= ( TheTime & 1<<4 ? 1<<2 : 0 );
            GPIOF->ODR |= ( TheTime & 1<<5 ? 1<<2 : 0 );
        }
    }
}
Пример #3
0
int main()
{
	// This is needed for FreeRTOS.
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

	InitDebug();

	cfg_Init( );

	PolePosition_Init();

	// This MUST be initialized before fullCAN
	MotorPosition_Init(FEEDBACK_POLE_POSITION);

	fullCAN_Init( 1000000, cfg_GetControllerID() );

	if ( cfg_GetControllerID() == 0)
	{
		fullCAN_SetTerminationState(ENABLE);
	} else {
		fullCAN_SetTerminationState(DISABLE);
	}

	d1k_STDIO_CAN_Init( CAN2,
			fullCAN_GetControllerId() + FULLCAN_IDBASE_STDIO_TX,
			fullCAN_GetControllerId() + FULLCAN_IDBASE_STDIO_RX );

	d1k_portal_Init( );

	ControlLoopInit();

	InitLEDs( );

	adc_Init( 100000 );

	motor_Init( );

	fault_Init( );

	diag_Init( );

	fan_Init( );

	fan_SetDutyCycle( 1.0f );

	printf("fullStartup! Controller: %u\r\n", (uint16)fullCAN_GetControllerId());

	vTaskStartScheduler( );
}
Пример #4
0
int main(void)
{
	InitLEDs();
	SetGreenLED();

	wdt_enable(WDTO_250MS);

	UART_Init();
	Cmd_InitInterface();
	RegisterAppCommands();
	sei();                    // enable interrupts

	while(true)
	{
		wdt_reset();
		Cmd_ProcessInterface();
	}
}
Пример #5
0
int main (void) {
    int i, selection, result, score;
    char keyPressed;
    int keyResult;
    int userSelectTime;

    /* mask interrupts */
    __asm("CPSID   I");

    /* Perform all device initialization here */
    /* Before unmasking interrupts            */

    /* Fire up the UART */
    Init_UART0_IRQ();
    Init_PIT_IRQ();
    InitLEDs();

    __asm("CPSIE   I");  /* unmask interrupts */

    for(;;) {

        //1: Display the instructions for the game
        PutStringSB("            Welcome to the World's Greatest Game!\r\n",MAX_STRING);
        PutStringSB("----------------------------------------------------------\r\n",MAX_STRING);
        PutStringSB("Prepare your mind and body for a challenge like you\r\n",MAX_STRING);
        PutStringSB("have never experienced.\r\n",MAX_STRING);
        PutStringSB("----------------------------------------------------------\r\n",MAX_STRING);
        PutStringSB("The game consists of 10 rounds. Each round you will\r\n",MAX_STRING);
        PutStringSB("need to press a keyboard letter matching the color of\r\n",MAX_STRING);
        PutStringSB("the LED that is shown. If you fail to do this, one of\r\n",MAX_STRING);
        PutStringSB("two things may happen. EITHER the world will explode,\r\n",MAX_STRING);
        PutStringSB("or you may lose a point. There is no way to tell which\r\n",MAX_STRING);
        PutStringSB("outcome will occur, so be very careful not to mess up - we\r\n",MAX_STRING);
        PutStringSB("are all depending on you.\r\n",MAX_STRING);
        PutStringSB("----------------------------------------------------------\r\n",MAX_STRING);
        PutStringSB("You may be shown the green or red LED, or both LEDs, or neither.\r\n",MAX_STRING);
        PutStringSB("----------------------------------------------------------\r\n",MAX_STRING);
        PutStringSB("Good luck. Countless lives may or may not be in your hands now.\r\n",MAX_STRING);
        PutStringSB("----------------------------------------------------------\r\n",MAX_STRING);
        //2: Prompt player to start game
        PutStringSB("TO BEGIN, PRESS ANY KEY\r\n", MAX_STRING);

        StartTimer();
        GetChar();

        userSelectTime = getCount();

        //3: After a key is pressed, program runs each game round "i"
        for(i = 0; i < NUM_ROUNDS; i++) {
            //Start timer and reset
            //a: get a random number 0-3
            selection = getRandom(userSelectTime);

            StartTimer();

            //a: light the LEDs
            if(selection == NONE) {
                SetLED(0);
            } else if(selection == GREEN) {
                SetLED(1);
            } else if(selection == RED) {
                SetLED(2);
            } else {
                SetLED(3);
            }

            //b: print a ">" prompt
            PutStringSB(">", MAX_STRING);
            //c: player has 11-i seconds to press the key
            keyPressed = 'x';
            while(getCount() < (11-i)*100) {
                keyResult = IsKeyPressed();
                if(keyResult != 0) {
                    keyPressed = GetChar();
                    break;
                }
            }

            userSelectTime = getCount();

            //d: echo key, print correct or wrong, show color combination of LEDs
            PutChar(keyPressed);
            PutStringSB("\r\n", MAX_STRING);
            result = getScore(keyPressed, selection, i); //get score

            //negative implies wrong
            if(result <= 0) {
                PutStringSB("Ding dong, that was wrong.", MAX_STRING);
            } else {
                PutStringSB("Correct! We live... for now", MAX_STRING);
            }
            //Echo color combination shown
            PutStringSB("LEDs shown were: ",MAX_STRING);
            if(selection == NONE) {
                PutStringSB("None", MAX_STRING);
            } else if(selection == GREEN) {
                PutStringSB("Green", MAX_STRING);
            } else if(selection == RED) {
                PutStringSB("Red", MAX_STRING);
            } else if(selection == BOTH) {
                PutStringSB("Green & Red", MAX_STRING);
            }

            //Then, add to score
            score += result;

            //e: Move to the next round when EITHER:
            //   - time for current round expires
            //   - player types character
            while(getCount() < (11-i)*100) {
                keyResult = IsKeyPressed();
                if(keyResult != 0) {
                    keyPressed = GetChar();
                    break;
                }
            }
            PutStringSB("\r\n", MAX_STRING);
        }

        //4: After last round, display score
        PutStringSB("Your score is: ", MAX_STRING);
        PutNumU(score);
        PutStringSB("\r\n\r\n\r\n-----------------------------------------\r\n", MAX_STRING);
    }

} /* main */