void SwitchLEDExample() { LED_Init(); Switch_Init(); unsigned char switch_state = 0; unsigned char switch_on; LED_Off(LED0|LED1|LED2|LED3); while (1) { switch_on = Switch_On(SWITCH2); if (!switch_state && switch_on) { LED_On(LED0|LED1|LED2|LED3); switch_state = 1; } else if (switch_state && ~switch_on) { LED_Off(LED0|LED1|LED2|LED3); switch_state = 0; } } }
int main(void){ unsigned long status; Switch_Init(); // PA5 is input status = Switch_Input(); // 0x00 or 0x20 status = Switch_Input(); // 0x00 or 0x20 Board_Init(); // initialize PF0 and PF4 and make them inputs // make PF3-1 out (PF3-1 built-in LEDs) GPIO_PORTF_DIR_R |= (RED|BLUE|GREEN); // disable alt funct on PF3-1 GPIO_PORTF_AFSEL_R &= ~(RED|BLUE|GREEN); // enable digital I/O on PF3-1 GPIO_PORTF_DEN_R |= (RED|BLUE|GREEN); // configure PF3-1 as GPIO GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFF000F)+0x00000000; GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF while(1){ status = Board_Input(); switch(status){ // switches are negative logic on PF0 and PF4 case 0x01: LEDS = BLUE; break; // SW1 pressed case 0x10: LEDS = RED; break; // SW2 pressed case 0x00: LEDS = GREEN; break; // both switches pressed case 0x11: LEDS = 0; break; // neither switch pressed default: LEDS = (RED|GREEN|BLUE);// unexpected return value } } }
//------------main---------------------------- int main(void){ PLL_Init(); SysTick_Init(); Switch_Init(); Output_Init(); // print intro screen to lab printf(" Fixed-point Lab\n"); printf("\n\n\n\n\n\n\n\n\n\n"); printf(" By:\n"); printf(" Brandon Boesch\n"); printf(" Curtis Martin\n"); printf(" Press SW2 to begin\n"); ST7735_DrawBitmap(30, 108, bmp_Logo, 70, 100); // begin tests while(PF0 == 0x01){}; Fixed_uDecOut2_test(); while(PF0 == 0x01){}; Fixed_sDecOut3_test(); while(PF0 == 0x01){}; Fixed_uBinOut8_test(); while(PF0 == 0x01){}; // outro screen Output_Clear(); ST7735_SetCursor(0,0); printf("Tests complete!"); ST7735_DrawBitmap(6, 159, bmp_thumbs, 114, 146); while(1){}; }
void HardwareSetup(void) { ConfigureOperatingFrequency(); ConfigureOutputPorts(); Switch_Init(); Rtc_Init(); Wdt_Init(); }
void main(){ SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); //pll init UART_Init(); // initialize UART Switch_Init(); // initialize switch XBeeInit(); XBee_CreateTxFrame("hi"); //enable timer interrupts }
//the main function int main(void) { //change the clock to osc0 = 12MHz AVR32_PM.oscctrl0 = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3<<AVR32_PM_OSCCTRL0_MODE_OFFSET | 3<<AVR32_PM_OSCCTRL0_STARTUP_OFFSET; AVR32_PM.mcctrl |= AVR32_PM_MCCTRL_OSC0EN_MASK; while (!(AVR32_PM.poscsr & AVR32_PM_POSCSR_OSC0RDY_MASK)); AVR32_PM.mcctrl |= AVR32_PM_MCCTRL_MCSEL_OSC0; LED_Init(); Switch_Init(); LED_Off(LED0|LED1|LED2|LED3); unsigned int counter = 0; unsigned int div = 32; unsigned int cycle = 0, ccycle = 0; unsigned int cycle_counter = 0; while (1) { if (cycle) { if (counter == 0) LED_On(LED0|LED1|LED2|LED3); else if (counter == cycle) LED_Off(LED0|LED1|LED2|LED3); } counter = (counter + 1) % div; cycle_counter = (cycle_counter + 1) % (2048/div); if (!cycle_counter) { ccycle = (ccycle + 1) % (2*div); if (ccycle < div) cycle = ccycle; else cycle = 2*div - 1 - ccycle; } cpu_delay_us(2000/div, FOSC0); } return 0; }
/*! * @brief Initialisation thread. runs once. */ void InitThread(void *data) { for (;;) { OS_SemaphoreWait(InitSemaphore, 0); Random_Init(); //Switches mate Switch_Init(S1Callback, (void *) 0, S2Callback, (void *) 0); Toggle_Init(ToggleModeFinished); Game_Init(GameModeFinished); Touch_Init(); //Initialize all the modules LEDs_Init(); I2C_Init(100000, MODULE_CLOCK); Accel_Init(&AccelSetup); PIT_Init(MODULE_CLOCK, &PitCallback, (void *) 0); PIT_Set(500000000, bFALSE); PIT_Enable(bTRUE); Packet_Init(BAUD_RATE, MODULE_CLOCK); Flash_Init(); CMD_Init(); //Best to do this one last //TODO: disabled for yellow RTC_Init((void (*)(void*))OS_SemaphoreSignal, (void *) RtcSemaphore); Timer_Init(); Timer_Set(&PacketTimer); Timer_Set(&AccTimer); CMD_SpecialGetStartupValues(); LEDs_On(LED_ORANGE); } }
int main(void) { // Switch the main clock to the external oscillator 0 pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); board_init(); Switch_Init(); LED_Off(LED0|LED1|LED2|LED3); unsigned int counter = 0; unsigned int div = 32; unsigned int cycle = 0, ccycle = 0; unsigned int cycle_counter = 0; while (1) { if (cycle) { if (counter == 0) LED_On(LED0|LED1|LED2|LED3); else if (counter == cycle) LED_Off(LED0|LED1|LED2|LED3); } counter = (counter + 1) % div; cycle_counter = (cycle_counter + 1) % (2048/div); if (!cycle_counter) { ccycle = (ccycle + 1) % (2*div); if (ccycle < div) cycle = ccycle; else cycle = 2*div - 1 - ccycle; } cpu_delay_us(2000/div, FOSC0); } return 0; }
int main(void){ SysTick_Init(); // initialize SysTick timer, see SysTick.c Switch_Init(); // initialize PF0 and PF4 and make them inputs EnableInterrupts(); // I=0 //__set_BASEPRI(5<<5); while(1){ set_reg(); if(SW1){ elapsed = (before-NVIC_ST_CURRENT_R)&0x00FFFFFF; SW1=0; // Mark it as read PortF_Output(GPIO_PORTF_DATA_R | 0x04); // Turn Blue LED (PF2) ON } if (SW2){ elapsed = (before-NVIC_ST_CURRENT_R)&0x00FFFFFF; SW2=0; PortF_Output(0x00); // Turn Red LED (PF1) OFF } } }
//******** OS_AddSW2Task *************** // add a background task to run whenever the SW1 (PF4) button is pushed // Inputs: pointer to a void/void background function // priority 0 is the highest, 5 is the lowest // Outputs: 1 if successful, 0 if this thread can not be added // It is assumed that the user task will run to completion and return // This task can not spin, block, loop, sleep, or kill // This task can call OS_Signal OS_bSignal OS_AddThread // This task does not have a Thread ID // In labs 2 and 3, this command will be called 0 or 1 times // In lab 2, the priority field can be ignored // In lab 3, there will be up to four background threads, and this priority field // determines the relative priority of these four threads int OS_AddSW2Task(void(*task)(void), unsigned long priority) { Switch_Init(task,priority, 0); return 1; }
int main(void){ volatile uint32_t delay; int i; PLL_Init(); Output_Init(); // CAN0_Open(); DisableInterrupts(); SYSCTL_RCGCGPIO_R |= 0x20; while((SYSCTL_PRGPIO_R&0x0020) == 0){};// ready? Count = 0; // allow time to finish activating // GPIO_PORTF_DIR_R |= 0x04; // make PF2 out (built-in LED) // GPIO_PORTF_AFSEL_R &= ~0x04; // disable alt funct on PF2 // GPIO_PORTF_DEN_R |= 0x04; // enable digital I/O on PF2 // // configure PF2 as GPIO // GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF0FF)+0x00000000; // GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock GPIO Port F GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0 GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog on GPIO_PORTF_DIR_R &= ~0x03; // make PB6 in GPIO_PORTF_AFSEL_R |= 0x03; // enable alt funct on PB6 GPIO_PORTF_DEN_R |= 0x03; // enable digital I/O on PB6 // configure PB6 as T0CCP0 GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFFF00)+0x00000077; GPIO_PORTF_AMSEL_R &= ~0xFF; // disable analog functionality on PB6 SYSCTL_RCGCGPIO_R |= 0x01; delay = SYSCTL_RCGCGPIO_R; // 2) allow time for clock to stabilize delay = SYSCTL_RCGCGPIO_R; GPIO_PORTA_DIR_R |= 0x01; // 3.11) make PA6 output GPIO_PORTA_AFSEL_R &= ~0x01; // 4.11) disable alternate function on PA6 GPIO_PORTA_DEN_R |= 0x01; // 5.11) enable digital I/O on PA6 GPIO_PORTA_AMSEL_R = 0; // 6.11) disable analog functionality on PA6 Switch_Init(); Init_Timer4A(); Timer4A_Wait(80000000); //wait 1 sec Init_Timer5A(80000); ADC0_InitTimer3ATriggerSeq3PD3(6000); ADC0_InitTimer3BTriggerSeq2PD2(5500); TimerCapture_Init(UserTask2); InitMotors(); EnableInterrupts(); while(1) { getSensorValues(); printSensorValues(0); if(buttonL) { printSensorValues(6); ControlMotors(35000,35000); ST7735_SetCursor(0,8);ST7735_OutString("Buttonback"); buttonL = 0; for(i = 0; i < 1440000; i++); } if(buttonR) { printSensorValues(6); ControlMotors(35000,35000); ST7735_SetCursor(0,1);ST7735_OutString("ButtonR"); buttonR = 0; for(i = 0; i < 1440000; i++); } if (Ping1 < 18) { //ControlMotors(40000, 40000); ST7735_SetCursor(0,1); ST7735_OutString("Stopped"); printSensorValues(3); // while(1) { ST7735_SetCursor(0,1);ST7735_OutString("Stopped"); getSensorValues(); printSensorValues(0); // } if(IR_L > IR_R) { ControlMotors(35000,35000); ST7735_SetCursor(0,8);ST7735_OutString("BL"); } else { ControlMotors(35000,35000); ST7735_SetCursor(0,8);ST7735_OutString("BR"); } for(i = 0; i < 1440000; i++); } else if (((Ping2 > 80) != (Ping3 > 80)) && (Ping1 < 40)) { if (Ping2>80) { //spot turn right ControlMotors(20000, 60000); } if (Ping3>80) { //spot turn left ControlMotors(60000, 20000); } // ControlMotors(40000,40000); } else if(IR_L < 1500 && IR_R < 1500) { ControlMotors(70000,65000); ST7735_SetCursor(0,8);ST7735_OutString("FO"); } else if(IR_L < IR_R) { ControlMotors(70000,50000); ST7735_SetCursor(0,8);ST7735_OutString("LE"); } else if(IR_R < IR_L) { ControlMotors(70000,72000); ST7735_SetCursor(0,8);ST7735_OutString("RI"); } } }