/* ******************************************************** pos - moves cursor to coordinates ******************************************************** */ void pos(int x, int y){ int addr; ////y interpretation //quadrant detection if(y >=4 && y <= 7){ //if quad 1 selected display1_en = 1; display2_en = 0; }else if(y >= 0 && y <=3){ //if quad 2 selected display1_en = 0; display2_en = 1; } //even/odd detection if((y % 2) == 0){ //if row is odd addr = 128; }else{ //if row is even addr = 192; } //specific row detection if(y == 5 || y == 4 || y == 1 || y == 0){ //higher rows addr += x; }else{ addr += 20 + x; } send_i(CURMOV); send_i(addr); }
void packet_write(int socket, PACKET *packet) { send_i(socket, packet->command); send_i(socket, packet->args_count); for (int i = 0; i < packet->args_count; i ++) { PACKET_ARG *arg = packet->args[i]; send_i(socket, arg->length); send_d(socket, arg->length, arg->arg); } }
/* ******************************************************** lclr - clear entire screen (both quadrants) ******************************************************** */ void lclr(void){ int save[2]; save[0] = DISP2EN; save[1] = DISP1EN; DISP2EN = 0; DISP1EN = 0; send_i(LCDCLR); DISP2EN = save[0]; DISP1EN = save[1]; }
/* ******************************************************** pos - moves cursor to coordinates ******************************************************** */ void pos(int x, int y){ int addr; ////y interpretation //quadrant detection if(y >=4 && y <= 7){ //if quad 2 selected (DISP2EN low) DISP2EN = 1; //turns off cursor of quad 1 DISP1EN = 0; send_i(CUROFF); DISP2EN = 0; //turns on cursor of quad 2 DISP1EN = 1; send_i(LCDON); }else if(y >= 0 && y <=3){ //if quad 1 selected DISP2EN = 0; //turns off cursor of quad 2 DISP1EN = 1; send_i(CUROFF); DISP2EN = 1; DISP1EN = 0; send_i(LCDON); } //even/odd detection if((y % 2) == 0){ //if row is odd addr = 128; }else{ //if row is even addr = 192; } //specific row detection if(y == 5 || y == 4 || y == 1 || y == 0){ //higher rows addr += x; }else{ addr += 20 + x; } send_i(CURMOV); send_i(addr); }
/* *********************************************************************** Main - Setup *********************************************************************** */ void main(void) { /* put your own code here */ DisableInterrupts; initializations(); EnableInterrupts; //printf("%ld\n",time(0)); //prints time elapsed since 1970 Initial_board(mine); Initial_mask(mask); /* *********************************************************************** Main - Loop *********************************************************************** */ for(;;) { PTT_PTT3 = display1_en; //display1_en = 1 means PTT_PTT3 = 0 (en) PTT_PTT5 = !display2_en; //display2_en = 1 means PTT_PTT5 = 0 (en) //butts(); if(diffrun == 0 && gamerun == 0){ //splash screen if(setflag == 1){ send_i(LCDCLR); splashDisp(); setflag = 0; } if(buttBpb){ //buttBpb (FLAG), as opposed to buttBatd diffrun = 1; setflag = 1; } } if(diffrun == 1 && gamerun == 0){ //difficulty screen if(setflag == 1){ send_i(LCDCLR); diffDisp(); setflag = 0; } difficulty(); if(buttBpb){ gamerun = 1; diffrun = 0; setflag = 1; } } if(diffrun == 0 && gamerun == 1){ if(setflag == 1){ send_i(LCDCLR); Create_board(nbomb,mine); joymove = 99; setflag = 0; } //printf("Mask: \n"); if(joymove != 0){ for(i = 0; i < NROW; i++){ for(j = 0; j < NCOL; j++){ //printf("%2d ",mask[i][j]); pos(i,j); if(mask[i][j] == 9){ pmsglcd("?"); }else if(mask[i][j] == 0){ pmsglcd(" "); }else if(mask[i][j] >= 1 && mask[i][j] <= 8){ dumb = 30 + mask[i][j]; print_c(dumb); }else if(mask[i][j] == 10){ pmsglcd("F"); } } //printf("\n"); } } joymove = joy(); if(joymove == 2){ if(irow != 0){ irow--; } } if(joymove == 4){ if(icol != 0){ icol--; } } if(joymove == 6){ if(icol != (NCOL - 1)){ icol++; } } if(joymove == 8){ if(icol != (NROW - 1)){ irow++; } } nclick = GameControl(irow,icol,nclick,mine,mask); } if(nclick == -1){ fail = 1; for(a = 0; a < NROW; a++){ for(b = 0; b < NCOL; b++){ mask[a][b] = mine[a][b]; } } } //printf("Number Click: %d\n",nclick); nflag = FlagControl(frow,fcol,nflag,mask); if((nflag + nclick) == nbomb){ win = 1; } //printf("Number Flag: %d\n",nflag); //printf("Flag: \n"); for(i = 0; i < NROW; i++){ for(j = 0; j < NCOL; j++){ //printf("%2d ",mask[i][j]); } //printf("\n"); } //printf("Mine: \n"); for(i = 0; i < NROW; i++){ for(j = 0; j < NCOL; j++){ //printf("%2d ",mine[i][j]); } //printf("\n"); } /* //If the left pushbutton if(leftpb && !gamerun){ leftpb = 0; gamerun = 1; send_i(LCDCLR); //display message pmsglcd("Ready, Set..."); } //If the right pushbutton if(rghtpb && gamerun){ rghtpb = 0; gamerun = 0; } */ } /* loop forever */ /* please make sure that you never leave main */ }
void initializations(void) { /* Set the PLL speed (bus clock = 24 MHz) */ CLKSEL = CLKSEL & 0x80; // disengage PLL from system PLLCTL = PLLCTL | 0x40; // turn on PLL SYNR = 0x02; // set PLL multiplier REFDV = 0; // set PLL divider while (!(CRGFLG & 0x08)){ } CLKSEL = CLKSEL | 0x80; // engage PLL /* Disable watchdog timer (COPCTL register) */ COPCTL = 0x40; //COP off, RTI and COP stopped in BDM-mode /* Initialize asynchronous serial port (SCI) for 9600 baud, no interrupts */ SCIBDH = 0x00; //set baud rate to 9600 SCIBDL = 0x9C; //24,000,000 / 16 / 156 = 9600 (approx) SCICR1 = 0x00; //$9C = 156 SCICR2 = 0x0C; //initialize SCI for program-driven operation DDRB = 0x10; //set PB4 for output mode PORTB = 0x10; //assert DTR pin on COM port /* Add additional port pin initializations here */ DDRT = 0xFF; /* Initialize SPI for baud rate of 6 Mbs */ SPIBR = 0b00000001; //SPRx = 1, SPPRx = 0, (0+1)*(2^(1+1)) = 4, 24MHz/4 = 6 Mbps SPICR1 = 0b01010000; //pg156 <- pg159 SPICR2 = 0b00000000; //pg160 <- pg159 /* Initialize digital I/O port pins */ DDRAD = 0; //program port AD for input mode ATDDIEN = 0xC0; //program PAD7 and PAD6 pins as digital inputs /* Initialize the LCD - pull LCDCLK high (idle) - pull R/W' low (write state) - turn on LCD (LCDON instruction) - enable two-line mode (TWOLINE instruction) - clear LCD (LCDCLR instruction) - wait for 2ms so that the LCD can wake up */ PTT_PTT4 = 1; PTT_PTT3 = 0; send_i(LCDON); send_i(TWOLINE); send_i(LCDCLR); lcdwait(2); /* Initialize RTI for 2.048 ms interrupt rate */ CRGINT = CRGINT | 0x80; //enable RTI (pg32) RTICTL = 0x1F; //pg33 /* Initialize TIM Ch 7 (TC7) for periodic interrupts every 1.000 ms - enable timer subsystem - set channel 7 for output compare - set appropriate pre-scale factor and enable counter reset after OC7 - set up channel 7 to generate 1 ms interrupt rate - initially disable TIM Ch 7 interrupts */ TSCR1 = 0b10000000; //enable subsys TIOS = 0b10000000; //chan 7 for output compare TSCR2 = 0b00001100; //set pre-scale factor and enable counter reset TC7 = 1500; //generate 1500clicks = 1 ms interrupt rate from notes TIE = 0b00000000; //interrupt disabled // Add RTI/interrupt initializations here CRGINT = 0b10000000; //enables RTI ATDCTL2 = 0b10000000; //enable atd ATDCTL3 = 0b00010000; // ATDCTL4 = 0b10000110; //set to 10 bit control mode, prescale clock to 2Mhz ATDCTL5 = 0b00010000; //sample across multiple channels ATDCTL2_AFFC = 1; //set to fast flag clear mode }
void chgline(int pos) { send_i(CURMOV); send_i(pos); }
void main(void) { DisableInterrupts; initializations(); EnableInterrupts; for(;;) { /* write your code here */ // If the left pushbutton ("start reaction test") flag is set, then: // - clear left pushbutton flag // - set the "run/stop" flag // - display message "Ready, Set..." on the first line of the LCD // - turn off the left LED (PT1) // - turn on the right LED (PT0) // Endif if (leftpb ==1 && !runstp){ goteam = 0; react = 0; runstp = 1; leftpb = 0; RLed = 1; //Right LED LLed = 0; //Left LED YELLOW = 0; GREEN = 0; RED = 0; send_i(LCDCLR); lcdwait(); pmsglcd("Ready, Set...", 13, LINE2); } // If the "run/stop" flag is set, then: // - If the "goteam" flag is NOT set, then: // + If "random" = $0000, then: // - set the "goteam" flag // - clear TCNT register (of TIM) // - clear "react" variable (2 bytes) // - enable TIM Ch7 interrupts // - turn on YELLOW LED // - display message "Go Team!" on the second line of the LCD // + Endif // - Endif // Endif if(runstp && !goteam && random==0x00){ goteam = 1; react = 0; YELLOW = 1; //Yellow LED send_i(LCDCLR); lcdwait(); pmsglcd("Go team!", 8, LINE2); TIE = 0x80; } // If the right pushbutton ("stop reaction test") flag is set, then: // - clear right pushbutton flag // - clear the "run/stop" flag // - clear the "goteam" flag // - turn off yellow LED // - disable TIM Ch 7 interrupts // - call "tdisp" to display reaction time message // - turn off right LED (PT0) // - turn on left LED (PT1) // Endif if (rghtpb == 1) { rghtpb = 0; if(runstp && goteam){ runstp = 0; goteam = 0; YELLOW = 0; TIE = 0x0; send_i(LCDCLR); lcdwait(); tdisp(); if(react <= 250){ GREEN = 1; pmsglcd("F**K YEAH!", 10, LINE2); }else{ GREEN =0; pmsglcd("Really?", 7, LINE2); } RLed = 0; //Right LED LLed = 1; //Left LED } } // If "react" = 999 (the maximum 3-digit BCD value), then: // - clear the "run/stop" flag // - turn off yellow LED, turn on red LED // - disable TIM Ch 7 interrupts // - display message "Time = 999 ms" on the first line of the LCD // - display message "Too slow!" on the second line of the LCD // - turn off right LED (PT0) // - turn on left LED (PT1) // Endif if(react >= 999 && runstp){ runstp = 0; react =0; YELLOW = 0; //Yellow LED RED = 1; //Red LED TIE = 0x0; send_i(LCDCLR); lcdwait(); pmsglcd("RT = 999ms", 10, LINE1); pmsglcd("Too slow!", 9, LINE2); RLed = 0; //Right LED LLed = 1; //Left LED } _FEED_COP(); }/* loop forever */ } /* do not leave main */
//*********************************************************************** //Initializations //*********************************************************************** void initializations(void) { //Set the PLL speed (bus clock = 24 MHz) CLKSEL = CLKSEL & 0x80; // disengage PLL from system PLLCTL = PLLCTL | 0x40; // turn on PLL SYNR = 0x02; // set PLL multiplier REFDV = 0; // set PLL divider while (!(CRGFLG & 0x08)){ } CLKSEL = CLKSEL | 0x80; // engage PLL //Disable watchdog timer (COPCTL register) COPCTL = 0x40; //COP off, RTI and COP stopped in BDM-mode //Initialize asynchronous serial port (SCI) for 9600 baud, no interrupts SCIBDH = 0x00; //set baud rate to 9600 SCIBDL = 0x9C; //24,000,000 / 16 / 156 = 9600 (approx) SCICR1 = 0x00; //$9C = 156 SCICR2 = 0x0C; //initialize SCI for program-driven operation DDRB = 0x10; //set PB4 for output mode PORTB = 0x10; //assert DTR pin on COM port //Add additional port pin initializations here ATDDIEN = 0xC0; prevpb = 0; prevpbl = 1; prevpbr = 1; //Initialize the SPI to baud rate of 6 Mbs DDRM = 0xFF; SPICR1 = 0x50; SPICR2 = 0x00; SPIBR = 0x01; //Initialize digital I/O port pins DDRT = 0xFF; //Initialize the LCD // - pull LCDCLK high (idle) PTT_PTT4 = 1; // - pull R/W' low (write state) PTT_PTT3 = 0; // - turn on LCD (LCDON instruction) send_i(LCDON); // - enable two-line mode (TWOLINE instruction) send_i(TWOLINE); // - clear LCD (LCDCLR instruction) send_i(LCDCLR); // - wait for 2ms so that the LCD can wake up lcdwait(); lcdwait(); // //Initialize RTI for 2.048 ms interrupt rate RTICTL = 0x41; CRGINT = CRGINT | 0x80; //Initialize TIM Ch 7 (TC7) for periodic interrupts every 1.000 ms // - enable timer subsystem TSCR1 = 0x80; // - set channel 7 for output compare TSCR2 = 0x0C; // - set appropriate pre-scale factor and enable counter reset after OC7 TIOS = 0x80; // - set up channel 7 to generate 1 ms interrupt rate TIE = 0x00; // - initially disable TIM Ch 7 interrupts TC7 = 1500; }
/* *********************************************************************** Main - Setup *********************************************************************** */ void main(void) { /* put your own code here */ DisableInterrupts; initializations(); EnableInterrupts; //printf("%ld\n",time(0)); //prints time elapsed since 1970 Initial_board(mine); Initial_mask(mask); send_i(LCDCLR); //for redundancy purposes /* *********************************************************************** Main - Loop *********************************************************************** */ for(;;) { if(diffrun == 0 && gamerun == 0){ //splash screen if(flag1 == 1){ splashDisp(); flag1 = 0; } if(buttBpb && prevpb == 0){ //buttBpb (FLAG), as opposed to buttBatd diffrun = 1; flag2 = 1; buttBpb = 0; //resets button B } }else if(diffrun == 1 && gamerun == 0){ //difficulty screen if(flag2 == 1){ diffDisp(); flag2 = 0; } difficulty(); if(buttBpb && prevpb == 0){ gamerun = 1; diffrun = 0; flag3 = 1; buttBpb = 0; //resets button B } }else if(diffrun == 0 && gamerun == 1){ if(flag3 == 1){ send_i(LCDCLR); gameDisp(); //game screen flag3 = 0; } minejoy(); //joystick/click func in game stage if(nclick == -1){ fail = 1; for(a = 0; a < NROW; a++){ for(b = 0; b < NCOL; b++){ mask[a][b] = mine[a][b]; } } } //printf("Number Click: %d\n",nclick); nflag = FlagControl(frow,fcol,nflag,mask); if((nflag + nclick) == nbomb){ win = 1; //turn into increment towards win condition or something later } //printf("Number Flag: %d\n",nflag); //printf("Flag: \n"); for(i = 0; i < NROW; i++){ for(j = 0; j < NCOL; j++){ //printf("%2d ",mask[i][j]); } //printf("\n"); } //printf("Mine: \n"); for(i = 0; i < NROW; i++){ for(j = 0; j < NCOL; j++){ //printf("%2d ",mine[i][j]); } //printf("\n"); } } } /* loop forever */ }
/* *********************************************************************** Initializations *********************************************************************** */ void initializations(void) { /* Set the PLL speed (bus clock = 24 MHz) */ CLKSEL = CLKSEL & 0x80; // disengage PLL from system PLLCTL = PLLCTL | 0x40; // turn on PLL SYNR = 0x02; // set PLL multiplier REFDV = 0; // set PLL divider while (!(CRGFLG & 0x08)){ } CLKSEL = CLKSEL | 0x80; // engage PLL /* Disable watchdog timer (COPCTL register) */ COPCTL = 0x40; //COP off, RTI and COP stopped in BDM-mode /* Initialize asynchronous serial port (SCI) for 9600 baud, no interrupts */ SCIBDH = 0x00; //set baud rate to 9600 SCIBDL = 0x9C; //24,000,000 / 16 / 156 = 9600 (approx) SCICR1 = 0x00; //$9C = 156 SCICR2 = 0x0C; //initialize SCI for program-driven operation DDRB = 0x10; //set PB4 for output mode PORTB = 0x10; //assert DTR pin on COM port /* Add additional port pin initializations here */ DDRAD = 0; //program port AD for input mode ATDDIEN = 0xf0; //program PAD7 and PAD6 pins as digital inputs DDRM_DDRM5=1; DDRM_DDRM4=1; DDRT=0xff; ATDCTL2 = 0x80; ATDCTL3 = 0x10; ATDCTL4 = 0x85; //ATDCTL5 = 0x85; /* Initialize SPI for baud rate of 6 Mbs */ SPIBR=0x01; SPICR1=0x50; SPICR2=0x08; /* Initialize digital I/O port pins */ //Initialising PWM /*MODRR=0x02;//pt3 as ch3 0000 1000 PWME=0x02; //enable pwm ch3 PWMPOL=0x00;//active low polarity PWMCTL=0;//no concatenate (8) PWMCAE=0;// left-aligned output mode PWMPER1=0xff; //period ff PWMDTY1=0x00; //duty cycle PWMCLK=0x80; //clock a for cho 0 PWMSCLA=0x00; PWMPRCLK=0x07; //clock a =12m */ PTT_PTT6=1; PTT_PTT7=0; send_i(LCDON); send_i(TWOLINE); send_i(LCDCLR); lcdwait(); /* Initialize RTI for 2.048 ms interrupt rate */ RTICTL=0x50 ; CRGINT_RTIE=1; /* Initialize TIM Ch 7 (TC7) for periodic interrupts every 1.000 ms - enable timer subsystem - set channel 7 for output compare - set appropriate pre-scale factor and enable counter reset after OC7 - set up channel 7 to generate 0.01 ms interrupt rate - initially disable TIM Ch 7 interrupts */ TSCR1=0x80; TIOS = 0x80; TSCR2=0x0c; TC7=15; TSCR2_TCRE=1; //TIE=0xff; TIE_C7I = 0; }
/* *********************************************************************** chgline: Move LCD cursor to position x NOTE: Cursor positions are encoded in the LINE1/LINE2 variables *********************************************************************** */ void chgline(char x) { send_i(CURMOV); send_i(x); }
/* *********************************************************************** Main *********************************************************************** */ void main(void) { DisableInterrupts; initializations(); EnableInterrupts; //shiftout(0x01); while(flag == 0 && counter_pass < 3) { chgline(0x80); pmsglcd("Enter Password"); if(rghtpb == 0) { chgline(0xc0 + counter_pass); tempo = atd_convert() ; print_c(tempo); } if(rghtpb == 1) { rghtpb = 0; temp[counter_pass] = atd_convert() - 48; counter_pass++; } if(counter_pass == 3) { for(i = 0; i < 3; i++) { if(our_pass[i] == temp[i]) { if(flag2 != 1) { flag = 1; } } else { flag2 = 1; flag = 0; counter_pass = 0; temp[0] = 0; temp[1] = 0; temp[2] = 0; chgline(0xc0); send_i(LCDCLR); } } } } send_i(LCDCLR); pmsglcd("Success"); TIE_C7I = 1; //print_c(tempo); for(;;) { /* write your code here */ } /* loop forever */ }/* do not leave main */