int main(void) { int playPauseButton, playPauseButtonPrev, stopButton, stopButtonPrev; // Music output port. The DAC MUST use pins 0-3 on the port! Port dac = portInit('YOUR PORT LETTER HERE', 0x00, 0x0F); // port used for the play/pause and stop buttons // and the LED outputs (one for tempo/beat, one to show a note is playing) io = portInit(/* YOUR PORT INFO HERE*/); musicInit(dac); musicLoad(/* YOUR SONG INFO HERE */); // Main loop while(TRUE) { // Read inputs and call one of: // musicPlay() // musicPause() // musicStop() if (playing == TRUE) { WaitForInterrupt(); } } }
int main(void){// activate grader and set system clock to 80 MHz unsigned long NumberOfPresses = 0; // store the number of presses unsigned long LastInput = 0; // store the last input of Switch here TExaS_Init(SW_PIN_PA3, HEADPHONE_PIN_PA2,ScopeOn); Sound_Init(); EnableInterrupts(); // enable after all initialization are done while(1){ // main program is free to perform other tasks // do not use WaitForInterrupt() here, it may cause the TExaS to crash // perform other tasks - Read the input over and over again: Switch = GPIO_PORTA_DATA_R & 0x08; // read the switch from PA3 if (Switch != 0 && Switch != LastInput) { // if the switch is pressed, and last time it was released: NumberOfPresses++; // the number of the ACTUAL press increase by 1 } LastInput = Switch; // save the current input for next time if (NumberOfPresses%2 == 0) { // if the number of press is even // (those presses at the 0, 2nd, 4th, 6th,... time) GPIO_PORTA_DATA_R &= ~0x04; // then turn off PA2 } else { // if the number of press is odd // (those presses at the 1st, 3rd, 5th, 7th,... time) WaitForInterrupt(); // then periodically interrupt the system each 880 Hz // the SysTick will automatically // trigger itself every (1 s)/(880 Hz) = 1.13636 ms } } }
int main(void){ DisableInterrupts(); PLL_Init(Bus80MHz); // bus clock at 80 MHz UART_Init(); ST7735_InitR(INITR_REDTAB); ADC0_InitTimerTriggerSeq3_Ch0(); EnableInterrupts(); /* UART_OutString("Points: \r\n"); while(currentIndex < 100); for(int i = 0; i < 100; i += 1) { UART_OutUDec(data[i]); UART_OutString("\r\n"); } */ while(1) { ST7735_SetCursor(0, 0); int32_t currentTemperature = Temperature_Convert(ADC_FIFO_CurrentValue()); printf("Temperature %5d.%02d\n", currentTemperature / 100, currentTemperature % 100); ST7735_PlotClear(32, 159); //TODO change color? for(int i = 0; i < FIFO_SIZE; i += 1) { int32_t point = 128 - Temperature_Convert(ADC_FIFO_Get()[i]) * 2 / 100; ST7735_DrawPixel(i+1, point+1, ST7735_RED); ST7735_DrawPixel(i+1, point, ST7735_RED); ST7735_DrawPixel(i, point+1, ST7735_RED); ST7735_DrawPixel(i, point, ST7735_RED); } WaitForInterrupt(); } }
// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ PLL_Init(); // 80 MHz Sound_Init(); // initialize output and interrupts EnableInterrupts(); while(1){ // interrupts every 500us WaitForInterrupt(); } }
void tasks_run() { while(1) { if(!task_yield()) { //bufferPrintf("WFI\r\n"); WaitForInterrupt(); // Nothing to do, wait for an interrupt. } } }
int main(void) { // initialize PLL PLL_Init_50MHz(); // initialize SysTick_Init(); // initialize PortF PortF_Init(); while(1) { WaitForInterrupt(); } }
// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ PLL_Init(); // 80 MHz //Sound_Init(); // initialize output and interrupts Button_Init(); EnableInterrupts(); while(1){ // interrupts every 500us //check iinputs poll interrupt for buttons? //display state //go to next state WaitForInterrupt(); } }
//debug code int main(void){ volatile unsigned long delay; SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOC; // activate port C delay = SYSCTL_RCGC2_R; // allow time to finish activating GPIO_PORTC_DIR_R |= 0x20; // make PC5 out (PC5 built-in LED) GPIO_PORTC_DEN_R |= 0x20; // enable digital I/O on PC5 Timer0A_Init(); // initialize timer0A (~20,000 Hz) while(1){ WaitForInterrupt(); } }
int main(void){ DisableInterrupts(); //////////////////////// perhipheral initialization //////////////////////// // init PLL to 80Mhz PLL_Init(); // init screen, use white as text color Output_Init(); Output_Color(ST7735_WHITE); //Output_Clear(); // init usb uart, generate interrupts when data received via usb USB_UART_Init(); USB_UART_Enable_Interrupt(); // init systick to generate an interrupt every 1ms (every 80000 cycles) //SysTick_Init(80000); // init and enable PWM // PWM0A_Init(40000, 20000); // PWM0A_Enable(); // init debug LEDs DEBUG_Init(); // global enable interrupts EnableInterrupts(); //////////////////////// main loop //////////////////////// while(1){ WaitForInterrupt(); /* if (updateScreen){ updateScreen = false; // screen stuff here } */ if (USB_BufferReady){ USB_BufferReady = false; //INTER_HandleBuffer(); loopcount++; dd++; // experimental test comment } } }
int main(void) { DisableInterrupts(); PLL_Init(Bus80MHz); // bus clock at 50 MHz Tach_Init(); // initialize the Tach measureing input capture PWM0B_Init(40000, 30000); // 1000 Hz Buttons_Init(); ST7735_InitR(INITR_REDTAB); SysTick_Init(); EnableInterrupts(); int32_t x = 0; ST7735_SetCursor(0,0); printf("Speed:\nTarget:"); while(1) { ST7735_SetCursor(8, 0); int32_t speed = Tach_GetSpeed(); int32_t speedY = ST7735_TFTHEIGHT - 20 - speed / 4; printf("%5d.%01d rps", speed / 10, speed % 10); ST7735_SetCursor(8, 1); printf("%5d.%01d rps", Target_Speed / 10, Target_Speed % 10); if(x == 0) ST7735_PlotClear(32, 159); /* Speed = 200000000/Period; // 0.1 rps if(PID_delay == 0){ E = Target_Speed-Speed; // 0.1 rps U += (40*E)/64; // discrete integral if(U < 100) U=100; // Constrain output if(U>39900) U=39900; // 100 to 39900 PWM0B_Duty(U); // output PID_delay = 4; } else { PID_delay -= 1; }*/ while(! SysTick_ShouldDraw()); ST7735_DrawPixel(x+1, speedY+1, ST7735_RED); ST7735_DrawPixel(x+1, speedY, ST7735_RED); ST7735_DrawPixel(x, speedY+1, ST7735_RED); ST7735_DrawPixel(x, speedY, ST7735_RED); x = (x + 1) % ST7735_TFTWIDTH; WaitForInterrupt(); } }
int main(void) { PLL_Init(); // 80 MHz ADCTimerINT_Init(7999); // 10KHz EnableInterrupts(); // Enable global interrupt register flag UART0_Init(); TLV5618_Init(); Sound_Init(); UART0_TxString("Hi, Sir"); ToggleDebug(); //Sound_Tone(4780); while(1) { //delay(20); WaitForInterrupt(); } }
int main(void){ PLL_Init(Bus80MHz); // 80 MHz system clock SYSCTL_RCGCGPIO_R |= 0x00000020; // activate port F ADC0_InitTimer0ATriggerSeq3(0, 5000000); // ADC channel 0, 10 Hz sampling 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_DATA_R &= ~0x04; // turn off LED EnableInterrupts(); while(1){ WaitForInterrupt(); GPIO_PORTF_DATA_R ^= 0x04; // toggle LED } }
int main(void){ PLL_Init(Bus50MHz); // 50 MHz // 1) activate clock for Port F SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R5; // allow time to finish activating while((SYSCTL_PRGPIO_R&SYSCTL_PRGPIO_R5)==0){}; // 2) no need to unlock PF2 GPIO_PORTF_PCTL_R &= ~0x00000F00;// 3) configure PF2 as GPIO GPIO_PORTF_AMSEL_R &= ~0x04; // 4) disable analog function on PF2 GPIO_PORTF_DIR_R |= 0x04; // 5) make PF2 out (PF2 built-in blue LED) GPIO_PORTF_AFSEL_R &= ~0x04; // 6) disable alt funct on PF2 GPIO_PORTF_DEN_R |= 0x04; // 7) enable digital I/O on PF2 PWM0A_Init(250, 125); // initialize PWM0A, 100kHz, 50% duty // Timer0A_Init(&OutputSineWave, 3551);// initialize 440 Hz sine wave output Timer0A_Init(&OutputSineWave, 1563);// initialize 1000 Hz sine wave output while(1){ WaitForInterrupt(); } }
//debug code int main(void){ volatile unsigned long delay; PLL_Init(); // bus clock at 80 MHz SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // activate port F delay = SYSCTL_RCGC2_R; // allow time to finish activating GPIO_PORTF_DIR_R |= 0x0E; // make PF3-1 output (PF3-1 built-in LEDs) GPIO_PORTF_AFSEL_R &= ~0x0E; // disable alt funct on PF3-1 GPIO_PORTF_DEN_R |= 0x0E; // enable digital I/O on PF3-1 // 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 LEDS = 0; // turn all LEDs off // Timer1_Init(&UserTask, 4000); // initialize timer2 (20,000 Hz) Timer0_Init(&UserTask, 5000000); // initialize timer1 (16 Hz) // Timer1_Init(&UserTask, 80000000);// initialize timer1 (1 Hz) // Timer1_Init(&UserTask, 0xFFFFFFFF); // initialize timer1 (slowest rate) EnableInterrupts(); while(1){ WaitForInterrupt(); } }
int main(void) { PLL_Init(); // Enable the PLL Block and set the main clock frequency to 80 MHz GPIOPortF_EdgeTriggerSW(); // Init Edge Interrupt on high Edge on two switches PF0, PF4 UART0_Init(); SysTickInts_Init(8000000); // 100ms // Timer Period = Clock / Period // Period = 1 / ClockFrequency // for 80Khz, Period= 80MHz / 80KHz = 1000 // start with 50% DutyCycle on both wheels Timer0APWM_Init(1000, High); // 80 KHz, 50% Duty Cycle EnableInterrupts(); UART0_TxString("Ready, Sir"); UART0_NewLine(); while(1) { WaitForInterrupt(); // low power mode } }
int main(void){ PLL_Init(); // 25 MHz SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // activate port F ADC0_InitSWTriggerSeq3(0); // allow time to finish activating // ADC0_InitAllTriggerSeq3(0); // allow time to finish activating Timer0A_Init10HzInt(); // set up Timer0A for 10 Hz interrupts Timer1_Init(); // Intitalize timer1 count down 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_PORTF2 = 0; // turn off LED EnableInterrupts(); ST7735_InitR(INITR_REDTAB); ST7735_FillScreen(0); // set screen to black ST7735_SetCursor(0,0); ST7735_XYplotInit("Lab 2 PMF Averaging \n", 0, 4096, 0, 50); ST7735_OutString("1 point \n"); while(1){ WaitForInterrupt(); // GPIO_PORTF2 = 0x04; // profile // ADCvalue = ADC0_InSeq3(); // GPIO_PORTF2 = 0x00; if(Buffer_Counter == 1000){ break; } } uint32_t Jitter; // DisableInterrupts(); // TIMER1_CTL_R = 0x00000000; // 10) enable TIMER1A GPIO_PORTF2 = 0x04; // profile Jitter = Calc_Jitter(); uint32_t n = ADCvalue; // ST7735_OutUDec(n); Calc_PMF(); // will populate the frequency table ADC_Data = x-axis ADC_Freq = y-axis // Next line is call to the plot point function we created in lab1 // ST7735_XYplotInit("PMF", 0, 4096, 0, 50); // ST7735_XYplot(1000, ADC_Data, ADC_Freq); int j = 0; uint32_t x = 0; uint32_t y = 0; int i = 0; //ST7735_PlotClear(32, 159); // for(j = 0; j < 1000; j+=1){ ST7735_XYplotInit("Lab 2 PMF", 0, 4095, 0, 1000); ST7735_XYplot(1000, ADC_Data, ADC_Freq); // ST7735_PlotBar(ADC_Freq[j]); // ST7735_PlotBar(ADC_Freq[j]); //ST7735_PlotBar(30); //ST7735_PlotNext(); // y = 32+(127*(400-ADC_Freq[j]))/400; // x = 127-(127*(4095 - ADC_Data[j])/4095); // if(x<0)x = 0; // if(x>127)x=127; // if(y<32) y = 32; // ST7735_PlotBar(y); // if(y>159) y = 159; // if(x > i){ // ST7735_PlotNext(); // i += 1; // } /* if(j < 14){ ST7735_OutUDec(ADC_Data[j]); ST7735_OutString(" "); ST7735_OutUDec(ADC_Freq[j]); ST7735_OutString("\n"); } */ // } GPIO_PORTF2 = 0x00; // EnableInterrupts(); }
double getRPS(void){ WaitForInterrupt(); }
void IdleTask(void){ while(1) { // PF1 ^= 0x02; WaitForInterrupt(); } }
void IdleTask(void){ while(1) { WaitForInterrupt(); } }
int main(void){ DisableInterrupts(); PLL_Init(Bus10MHz); // bus clock at 10 MHz Buttons_Init(); SysTick_Init(); ST7735_InitR(INITR_REDTAB); TEC_Init(); ADC0_InitSWTriggerSeq3_Ch0(); printf("Critical Can Cooler\nV1.0\n\nCurrent Temp: \nDesired Temp: \nTEC Status: "); EnableInterrupts(); while(1) { /* convert ADC_sample to Current_Temp Get TEC_Temp Compare TEC_Temp with Current_Temp Turn off if less than/equal to Display "Critical Can Cooler V1.0" Display Current_Temp Display TEC_temp Display TEC_Status */ /* Temp scale: MAX 1740 mV or 2160 ADC measure = 25 C MIN 960 mV or 1192 ADC measure = 0 C 2160* .806mV/adctic = temp in mV vo -480/15.6 adc tics * .806mV/tic = sample in mV (mV - 960) /31.2 = T ((adc *806) - 960000) / 31200 = T */ Current_Temp = (((int32_t)ADC_Sample * 806) - 960000) / 31200; //if(TEC_Get() > Current_Temp) { // TEC_Stop(); //} ST7735_SetCursor(14,3); printf("%-3d",Current_Temp); ST7735_SetCursor(14,4); printf("%d",TEC_Get()); ST7735_SetCursor(14,5); if(TEC_Status()) { printf("ON \n"); } else { printf("OFF\n"); } WaitForInterrupt(); } }
//debug code int main(void){ EdgeCounter_Init(); // initialize GPIO Port F interrupt while(1){ WaitForInterrupt(); } }