int main(int argc, char** argv) { PT_setup(); // Enable multivector interrupts INTEnableSystemMultiVectoredInt(); // Initialize threads PT_INIT(&pt_cap); PT_INIT(&pt_blink); PT_INIT(&pt_cap_read) //init the display tft_init_hw(); tft_begin(); tft_fillScreen(ILI9340_BLACK); // Set orientation of the display tft_setRotation(1); // Set up pins PerPinSetup(); while(1){ PT_SCHEDULE(protothread_blink(&pt_blink)); PT_SCHEDULE(protothread_cap(&pt_cap)); PT_SCHEDULE(protothread_cap_read(&pt_cap_read)); } }
//===================== Main ======================= // void main(void) { SYSTEMConfig( SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); ANSELA = 0; ANSELB = 0; CM1CON = 0; CM2CON = 0; PT_setup(); INTEnableSystemMultiVectoredInt(); // initialize the threads PT_INIT(&pt_blink); PT_INIT(&pt_capture); // initialize the display tft_init_hw(); tft_begin(); tft_fillScreen(ILI9340_BLACK); tft_setRotation(0); //240x320 vertical display // initialize the comparator CMP1Open(CMP_ENABLE | CMP_OUTPUT_ENABLE | CMP1_NEG_INPUT_IVREF); // initialize the timer2 OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_64, 0xffffffff); // initialize the input capture, uses timer2 OpenCapture1( IC_EVERY_RISE_EDGE | IC_FEDGE_RISE | IC_INT_1CAPTURE | IC_TIMER2_SRC | IC_ON); ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_3 | IC_INT_SUB_PRIOR_3 ); INTClearFlag(INT_IC1); // initialize the input/output I/O mPORTBSetPinsDigitalOut(BIT_3); mPORTBClearBits(BIT_3); PPSOutput(4, RPB9, C1OUT); //set up output of comparator for debugging PPSInput(3, IC1, RPB13); //Either Pin 6 or Pin 24 idk //round-robin scheduler for threads while(1) { PT_SCHEDULE(protothread_blink(&pt_blink)); PT_SCHEDULE(protothread_capture(&pt_capture)); } } //main
void setup_lcd_fs(void){ _disable_interrupts(); WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_16MHZ; /* Set DCO for 16 MHz */ DCOCTL = CALDCO_16MHZ; delay_ms(100); // Initialize SD card: spi_initialize(); dres = disk_initialize(); tft_init_hw(); tft_begin(); tft_fillScreen(ILI9340_WHITE); tft_setCursor(0, 1); tft_setTextColor(ILI9340_BLACK); tft_setTextSize(1); if (dres){ sprintf(buffer, "Disk error = %d\n", (int) dres); tft_writeString(buffer); while (1); } pres = pf_mount(&fs); if (pres){ sprintf(buffer, "PFF error 1 = %d\n", (int) pres); tft_writeString(buffer); while (1); } tft_fillScreen(ILI9340_WHITE); P1DIR |= BIT0 | BIT1; P1OUT &= ~ (BIT0 | BIT1); }
//===================== Main ======================= // void main(void) { SYSTEMConfigPerformance(PBCLK); ANSELA = 0; ANSELB = 0; CM1CON = 0; CM2CON = 0; PT_setup(); refreshRate = 10; //msec //Temporary Random Ball generator head = Ball_create(50, 50, 2, 0, 0, NULL); int i = 1; for(i = 1; i < 15; i++) { signed char troll1 = rand() % 5; signed char troll2 = rand() % 5; struct Ball *temp = Ball_create(i*10,i*10,troll1,troll2,0,NULL); temp->b = head; head = temp; } // initialize the threads PT_INIT(&pt_calculate); PT_INIT(&pt_refresh); // initialize the display tft_init_hw(); tft_begin(); tft_fillScreen(ILI9340_BLACK); INTEnableSystemMultiVectoredInt(); tft_setRotation(0); //240x320 vertical display //round-robin scheduler for threads while(1) { PT_SCHEDULE(protothread_calculate(&pt_calculate)); PT_SCHEDULE(protothread_refresh(&pt_refresh)); } } //main
// === Main ====================================================== void main(void) { SYSTEMConfigPerformance(PBCLK); ANSELA = 0; ANSELB = 0; CM1CON = 0; CM2CON = 0; // === config threads ========== // turns OFF UART support and debugger pin PT_setup(); // === setup system wide interrupts ======== INTEnableSystemMultiVectoredInt(); // init the threads PT_INIT(&pt_timer); PT_INIT(&pt_color); PT_INIT(&pt_anim); PT_INIT(&pt_key); // init the display tft_init_hw(); tft_begin(); tft_fillScreen(ILI9340_BLACK); //240x320 vertical display tft_setRotation(0); // Use tft_setRotation(1) for 320x240 // seed random color srand(1); // round-robin scheduler for threads while (1){ PT_SCHEDULE(protothread_timer(&pt_timer)); PT_SCHEDULE(protothread_color(&pt_color)); PT_SCHEDULE(protothread_anim(&pt_anim)); PT_SCHEDULE(protothread_key(&pt_key)); } } // main
// === Main ====================================================== void main(void) { //SYSTEMConfigPerformance(PBCLK); ANSELA = 0; ANSELB = 0; // === config threads ========== // turns OFF UART support and debugger pin, unless defines are set PT_setup(); // === setup system wide interrupts ======== INTEnableSystemMultiVectoredInt(); CloseADC10(); // ensure the ADC is off before setting the configuration #define PARAM1 ADC_FORMAT_INTG16 | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_OFF // // define setup parameters for OpenADC10 // ADC ref external | disable offset test | disable scan mode | do 1 sample | use single buf | alternate mode off #define PARAM2 ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_OFF | ADC_SAMPLES_PER_INT_1 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF // Define setup parameters for OpenADC10 // use peripherial bus clock | set sample time | set ADC clock divider // ADC_CONV_CLK_Tcy2 means divide CLK_PB by 2 (max speed) // ADC_SAMPLE_TIME_5 seems to work with a source resistance < 1kohm #define PARAM3 ADC_CONV_CLK_PB | ADC_SAMPLE_TIME_5 | ADC_CONV_CLK_Tcy2 //ADC_SAMPLE_TIME_15| ADC_CONV_CLK_Tcy2 // define setup parameters for OpenADC10 // set AN11 and as analog inputs #define PARAM4 ENABLE_AN11_ANA // pin 24 // define setup parameters for OpenADC10 // do not assign channels to scan #define PARAM5 SKIP_SCAN_ALL // use ground as neg ref for A | use AN11 for input A // configure to sample AN11 SetChanADC10( ADC_CH0_NEG_SAMPLEA_NVREF | ADC_CH0_POS_SAMPLEA_AN11 ); // configure to sample AN4 OpenADC10( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5 ); // configure ADC using the parameters defined above EnableADC10(); // Enable the ADC OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_1, 400); mPORTAClearBits(BIT_0 ); //Clear bits to ensure light is off. mPORTASetPinsDigitalOut(BIT_0 ); //Set port as output int CVRCON_setup; // set up the Vref pin and use as a DAC // enable module| eanble output | use low range output | use internal reference | desired step CVREFOpen( CVREF_ENABLE | CVREF_OUTPUT_ENABLE | CVREF_RANGE_LOW | CVREF_SOURCE_AVDD | CVREF_STEP_0 ); // And read back setup from CVRCON for speed later // 0x8060 is enabled with output enabled, Vdd ref, and 0-0.6(Vdd) range CVRCON_setup = CVRCON; //CVRCON = 0x8060 // Open the desired DMA channel. // We enable the AUTO option, we'll keep repeating the same transfer over and over. DmaChnOpen(dmaChn, 0, DMA_OPEN_AUTO); // set the transfer parameters: source & destination address, source & destination size, number of bytes per event // Setting the last parameter to one makes the DMA output one byte/interrut //DmaChnSetTxfer(dmaChn, sine_table, (void*) &CVRCON, sizeof(sine_table), 1, 1); // set the transfer event control: what event is to start the DMA transfer // In this case, timer2 DmaChnSetEventControl(dmaChn, DMA_EV_START_IRQ(_TIMER_2_IRQ)); // once we configured the DMA channel we can enable it // now it's ready and waiting for an event to occur... //DmaChnEnable(dmaChn); int i; for(i=0; i <256; i++){ ball_scored[i] = 0x60|((unsigned char)((float)255/2*(sin(6.2832*(((float)i)/(float)256))+1))) ; //ball_lost[i] // game_over } // init the threads PT_INIT(&pt_timer); PT_INIT(&pt_adc); PT_INIT(&pt_launch); PT_INIT(&pt_anim); // init the display tft_init_hw(); tft_begin(); tft_fillScreen(ILI9340_BLACK); tft_setRotation(1); // Use tft_setRotation(1) for 320x240 while (1){ PT_SCHEDULE(protothread_timer(&pt_timer)); PT_SCHEDULE(protothread_adc(&pt_adc)); PT_SCHEDULE(protothread_launch_balls(&pt_launch)); PT_SCHEDULE(protothread_anim_balls(&pt_anim)); } } // main