void spi_sends(uint8_t * texts, uint8_t length) { uint8_t i=0; //P1OUT &= ~chip_select; //P2OUT &= ~chip_select; for(i = 0; i<length; i++) { UCB0TXBUF = texts[i]; // write INT to TX buffer while (!(IFG2 & UCB0TXIFG)); _delay_cycles(300); } while ((UCB0STAT & UCBUSY)); //P1OUT |= chip_select; }
/* * function name:System_Initial() * description: Initialize the system. include I/O, LCD and ADS1118 and meat select. */ void System_Initial() { flag = 0; //reset flag flag ^= BIT8; // Default to farenheit Thr_state = 0; //threshold temperature setting state machine counter time_state = 0; //time setting state machine counter Thr_temp = 100; //configure threshold temperature to 100; Act_temp = 250; meatState = 0; //No meat selected yet customThreshold = 0; //Clear custom threshold flag // IO initial P1OUT = 0x09; P2OUT = 0x3F; LCD_init(); // LCD initial LCD_clear(); // LCD clear //Display startup message for 2 seconds LCD_display_string(0," THERMOMEATER "); int i; for (i = 0; i < 2; i++) { _delay_cycles(1000000); } LCD_clear(); //Output Temperature read screen labels LCD_display_string(0,"Des:"); LCD_display_time(0,8,time); // display current time LCD_display_string(1," Probe :"); //Initially reading probe LCD_display_char(1,13,0xDF); //Degrees symbol LCD_display_char(1,14,'F'); //Initially farenheit LCD_display_number(0,4,Thr_temp); // display threshold temp number ADS_Config(0); // set ADS1118 to convert local temperature, //and start convertion. }
// reset radio and load configuration data void radio_configure(void) { // reset radio: SDN=1, wait >1us, SDN=0 RADIO_POUT |= RADIO_SDN; _delay_cycles(1000); RADIO_POUT &= ~RADIO_SDN; while (!RADIO_READY); // wait for chip to wake up // transfer radio configuration const uint8_t *cfg = radio_configuration; while (*cfg) { // configuration array stops with 0 char count = (*cfg++) - 1; // 1st byte: number of bytes, incl. command char cmd = *cfg++; // 2nd byte: command send_command(cmd, cfg, count, 0); // send bytes to chip cfg += count; // point at next line while (!RADIO_READY); // wait for chip to complete operation } return; }
//------------------------------------------------------------------------------ // Send colors to the strip and show them. Disables interrupts while processing. void showStrip() { // __bic_SR_register(GIE); // disable interrupts Interrupt_disableMaster(); // send RGB color for every LED int i, j; for (i = 0; i < NUM_LEDS; i++){ u_char rgb[4] = {leds[i].green, leds[i].red, leds[i].blue, leds[i].white}; // get RGB color for this LED // send green, then red, then blue, then white for (j = 0; j < 4; j++){ u_char mask = 0x80; // b1000000 // check each of the 8 bits while(mask != 0){ while ((UCB1IFG&0x0002)==0x0000); // wait until empty to transmit if (rgb[j] & mask) { // most significant bit first // SPI_transmitData(EUSCI_B1_MODULE, HIGH_CODE); UCB1TXBUF = HIGH_CODE; // send 1 } else { // SPI_transmitData(EUSCI_B1_MODULE, LOW_CODE); UCB1TXBUF = LOW_CODE; // send 0 } mask >>= 1; // check next bit } } } // send RES code for at least 50 us _delay_cycles(800); // __bis_SR_register(GIE); // enable interrupts Interrupt_enableMaster(); }
/* * drive() * accepts a direction and moves the robot in that direction */ void drive(direction movement){ GO_STOP; _delay_cycles(SHORT_T); switch(movement){ case FORWARD: TA1CCTL1 = OUTMOD_7; TA1CCTL2 = OUTMOD_7; GO_FORWARD; break; case BACKWARD: TA1CCTL1 = OUTMOD_3; TA1CCTL2 = OUTMOD_3; GO_BACKWARD; break; case LEFT_T: TA1CCTL1 = OUTMOD_7; TA1CCTL2 = OUTMOD_3; GO_FORWARD; GO_LEFT; break; case RIGHT_T: TA1CCTL1 = OUTMOD_3; TA1CCTL2 = OUTMOD_7; GO_FORWARD; GO_RIGHT; break; case STOP: GO_STOP; break; }//end switch ENABLE_MOTORS; }
__interrupt void USCI0RX_ISR(void) { char Input_Char = 0; if((IFG2 & UCA0RXIFG)) { Input_Char =UCA0RXBUF; if(Input_Char == '\r') { Run_Command(Command_Buffer); Clear_Command_Buffer(); } else { while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF = Input_Char; //while (UCA0STAT & UCBUSY); Add_Char_To_Command_Buffer(Input_Char); } } if((IFG2 & UCB0RXIFG)) { _delay_cycles(1); } }
/* * turns the robot CW */ void rotateRight(int deg_delay) { go(); LEFT_OM_HI; RIGHT_OM_LO; // LEFT MOTOR LEFT_SET_CCW; // RIGHT MOTOR RIGHT_SET_CCW; GREEN_ON; // green LED ON RED_OFF; // red LED OFF int i; switch(deg_delay) { case 15: _delay_cycles(DELAY_15); break; case 45: _delay_cycles(DELAY_45); break; case 90: _delay_cycles(DELAY_90); break; case 180: _delay_cycles(DELAY_180); break; case 360: _delay_cycles(DELAY_360); break; default: for(i=0; i<deg_delay; i++) { _delay_cycles(DELAY_360/DEG_360); } } }
int main(void) { // configure WDT WDTCTL = WDTPW | WDTHOLD; // stop watch dog timer _25mhz(); #ifdef TEST // when compiled in test mode, use different main // disconnect radio when testing to avoid damage! test_main(); #endif // configure LED1 and turn it off, we'll use that for error and other stuff P1DIR |= LED1; LED1_OFF; P4DIR |= LED2; LED2_ON; // setup uart uart_init(); #ifdef DEBUG_MESSAGES uart_send_string("Hola mundo!\r\n"); #endif // setup packet handler ph_setup(); // setup an configure radio radio_setup(); radio_configure(); // self-calibrate image rejection radio_calibrate_ir(); // verify that radio configuration was successful radio_get_chip_status(0); if (radio_buffer.chip_status.chip_status & RADIO_CMD_ERROR) { // check for command error uart_send_string("Error inicializando radio!!!\r\n"); while (1) { LED1_TOGGLE; _delay_cycles(8000000); // blink LED if there was an error } } // start packet receiving ph_start(); #ifdef DEBUG_MESSAGES uart_send_string("dAISy 0.2 started\r\n"); LED2_OFF; #endif while (1) { LPM0; // deep sleep until something worthwhile happens __no_operation(); ph_loop(); // packet handler house-keeping, e.g. channel hopping #ifdef DEBUG_MESSAGES uint8_t channel; int16_t rssi; // debug code to monitor signal strength (RSSI) if (ph_get_state() == PH_STATE_PREFETCH) { // found preamble and start flag // record current channel and signal strength channel = ph_get_radio_channel(); // read current channel rssi = ph_get_radio_rssi(); // read current RSSI } #endif // retrieve last packet handler error uint8_t error = ph_get_last_error(); #ifdef DEBUG_MESSAGES // report error if packet handler failed if (error != PH_ERROR_NONE) { dec_to_str(str_output_buffer, 3, rssi); // convert to decimal string (reuse radio buffer) str_output_buffer[4] = 0; // terminate string uart_send_string("sync "); // send debug message to UART uart_send_byte(channel + 'A'); uart_send_string(" RSSI="); uart_send_string(str_output_buffer); uart_send_string("dBm\r\n"); uart_send_string("error: "); switch (error) { case PH_ERROR_NOEND: uart_send_string("no end flag"); break; case PH_ERROR_STUFFBIT: uart_send_string("invalid stuff bit"); break; case PH_ERROR_CRC: uart_send_string("CRC error"); break; case PH_ERROR_RSSI_DROP: uart_send_string("RSSI drop"); break; } uart_send_string("\r\n"); ph_loop(); // house keeping, sending over UART takes time } #else // toggle LED if packet handler failed after finding preamble and start flag if (error == PH_ERROR_NOEND || error == PH_ERROR_STUFFBIT || error == PH_ERROR_CRC) LED1_TOGGLE; #endif // check if a new valid packet arrived uint16_t size = fifo_get_packet(); if (size > 0) { // if so, process packet #ifdef DEBUG_MESSAGES dec_to_str(str_output_buffer, 3, rssi); // convert to decimal string (reuse radio buffer) str_output_buffer[4] = 0; // terminate string uart_send_string("sync "); // send debug message to UART uart_send_byte(channel + 'A'); uart_send_string(" RSSI="); uart_send_string(str_output_buffer); uart_send_string("dBm\r\n"); #endif LED2_ON; nmea_process_packet(); // process packet (NMEA message will be sent over UART) fifo_remove_packet(); // remove processed packet from FIFO LED2_OFF; } // enter low power mode LPM0 (everything off) // TODO: wait for UART to complete transmission // TODO: suspend UART } }
//***************************************************************************** // Delay for t milliseconds //***************************************************************************** void delay_ms (int t) { int i; for (i = 0; i<t; i++ ) _delay_cycles(MCLK_F*1000); }
//***************************************************************************** // Delay for t microseconds // The delay is not exact when t is too small //***************************************************************************** void delay_us (int t) { int i; for (i = 0; i<t; i++ ) _delay_cycles(MCLK_F); }
void main(void) { WDTCTL = WDTPW | WDTHOLD; // stop the watchdog timer unsigned char i = 0; IFG1 = 0; // clear interrupt flag1 BCSCTL1 = CALBC1_8MHZ; // 8MHz clock DCOCTL = CALDCO_8MHZ; P1DIR = BIT0 | BIT6; while (1) { // Configure P1.4 to be the ADC input LEFT ADC10CTL0 = 0; // Turn off ADC subsystem ADC10CTL1 = INCH_4 | ADC10DIV_3; // Channel 4, ADC10CLK/4 ADC10AE0 = BIT4; // Make P1.4 analog input ADC10CTL0 = SREF_0 | ADC10SHT_3 | ADC10ON | ENC;// Vcc & Vss as reference ADC10CTL0 |= ADC10SC; // Start a conversion while (ADC10CTL1 & ADC10BUSY) ; // Wait for conversion to complete sampleL[i] = ADC10MEM; // collect that 10-bit value if (sampleL[i] > 0x0200) { P1OUT |= BIT0; turnRight(); _delay_cycles(10000); stopMotor(); _delay_cycles(1000000); } else { P1OUT &= ~BIT0; } //i = (i+1) & 0xF; // This is a mod 16 increment // Configure P1.3 to be the ADC input RIGHT ADC10CTL0 = 0; // Turn off ADC subsystem ADC10CTL1 = INCH_3 | ADC10DIV_3; // Channel 3, ADC10CLK/4 ADC10AE0 = BIT3; // Make P1.3 analog input ADC10CTL0 = SREF_0 | ADC10SHT_3 | ADC10ON | ENC;// Vcc & Vss as reference ADC10CTL0 |= ADC10SC; // Start a conversion while (ADC10CTL1 & ADC10BUSY) ; // Wait for conversion to complete sampleR[i] = ADC10MEM; // collect that 10-bit value if (sampleR[i] > 0x0200) P1OUT |= BIT6; else P1OUT &= ~BIT6; //i = (i+1) & 0xF; // This is a mod 16 increment // Configure P1.5 to be the ADC input CENTER ADC10CTL0 = 0; // Turn off ADC subsystem ADC10CTL1 = INCH_5 | ADC10DIV_3; // Channel 2, ADC10CLK/4 ADC10AE0 = BIT5; // Make P1.2 analog input ADC10CTL0 = SREF_0 | ADC10SHT_3 | ADC10ON | ENC;// Vcc & Vss as reference ADC10CTL0 |= ADC10SC; // Start a conversion while (ADC10CTL1 & ADC10BUSY) ; // Wait for conversion to complete sampleC[i] = ADC10MEM; // collect that 10-bit value if (sampleC[i] > 0x0200) { P1OUT |= BIT0 | BIT6; turnRight(); _delay_cycles(2500000); stopMotor(); _delay_cycles(10000000); // turnRight(); // _delay_cycles(1000000); // stopMotor(); } else { P1OUT &= ~(BIT0 | BIT6); goForward(); _delay_cycles(1800000); stopMotor(); _delay_cycles(10000000); } i = (i + 1) & 0xF; // This is a mod 16 increment } // end infinite loop } // end main
uint8_t test_power(uint16_t TEST_PIN, uint16_t INCH) { uint8_t power = 0, samples = 5; uint16_t adc_val = 0; ADCChannelSelect_GEN(TEST_PIN, INCH); _delay_cycles(30); while(--samples != 0) { ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start _delay_cycles(100); adc_val += (uint16_t)ADC10MEM; } adc_val = adc_val >> 2; _delay_cycles(5); power = (adc_val <= 324 ? 0 : // Accounts for reserve energy to check level (adc_val <= 331 ? 1 : (adc_val <= 338 ? 2 : (adc_val <= 345 ? 3 : (adc_val <= 352 ? 4 : (adc_val <= 359 ? 5 : (adc_val <= 366 ? 6 : (adc_val <= 373 ? 7 : (adc_val <= 380 ? 8 : (adc_val <= 387 ? 9 : (adc_val <= 394 ? 10 : (adc_val <= 401 ? 11 : (adc_val <= 408 ? 12 : (adc_val <= 415 ? 13 : (adc_val <= 422 ? 14 : (adc_val <= 429 ? 15 : (adc_val <= 436 ? 16 : (adc_val <= 443 ? 17 : (adc_val <= 450 ? 18 : (adc_val <= 457 ? 19 : (adc_val <= 464 ? 20 : (adc_val <= 471 ? 21 : (adc_val <= 478 ? 22 : (adc_val <= 485 ? 23 : (adc_val <= 492 ? 24 : (adc_val <= 499 ? 25 : (adc_val <= 506 ? 26 : (adc_val <= 513 ? 27 : (adc_val <= 520 ? 28 : (adc_val <= 527 ? 29 : (adc_val <= 534 ? 30 : (adc_val <= 541 ? 31 : (adc_val <= 548 ? 32 : (adc_val <= 555 ? 33 : (adc_val <= 562 ? 34 : (adc_val <= 569 ? 35 : (adc_val <= 576 ? 36 : (adc_val <= 583 ? 37 : (adc_val <= 590 ? 38 : (adc_val <= 597 ? 39 : (adc_val <= 604 ? 40 : (adc_val <= 611 ? 41 : (adc_val <= 618 ? 42 : (adc_val <= 625 ? 43 : (adc_val <= 632 ? 44 : (adc_val <= 639 ? 45 : (adc_val <= 646 ? 46 : (adc_val <= 653 ? 47 : (adc_val <= 660 ? 48 : (adc_val <= 667 ? 49 : (adc_val <= 674 ? 50 : (adc_val <= 681 ? 51 : (adc_val <= 688 ? 52 : (adc_val <= 695 ? 53 : (adc_val <= 702 ? 54 : (adc_val <= 709 ? 55 : (adc_val <= 716 ? 56 : (adc_val <= 723 ? 57 : (adc_val <= 730 ? 58 : (adc_val <= 737 ? 59 : (adc_val <= 744 ? 60 : (adc_val <= 751 ? 61 : (adc_val <= 758 ? 62 : (adc_val <= 765 ? 63 : (adc_val <= 772 ? 64 : (adc_val <= 779 ? 65 : (adc_val <= 786 ? 66 : (adc_val <= 793 ? 67 : (adc_val <= 800 ? 68 : (adc_val <= 807 ? 69 : (adc_val <= 814 ? 70 : (adc_val <= 821 ? 71 : (adc_val <= 828 ? 72 : (adc_val <= 835 ? 73 : (adc_val <= 842 ? 74 : (adc_val <= 849 ? 75 : (adc_val <= 856 ? 76 : (adc_val <= 863 ? 77 : (adc_val <= 870 ? 78 : (adc_val <= 877 ? 79 : (adc_val <= 884 ? 80 : (adc_val <= 891 ? 81 : (adc_val <= 898 ? 82 : (adc_val <= 905 ? 83 : (adc_val <= 912 ? 84 : (adc_val <= 919 ? 85 : (adc_val <= 926 ? 86 : (adc_val <= 933 ? 87 : (adc_val <= 940 ? 88 : (adc_val <= 947 ? 89 : (adc_val <= 954 ? 90 : (adc_val <= 961 ? 91 : (adc_val <= 968 ? 92 : (adc_val <= 975 ? 93 : (adc_val <= 982 ? 94 : (adc_val <= 989 ? 95 : (adc_val <= 996 ? 96 : (adc_val <= 1003? 97 : (adc_val <= 1010? 98 : (adc_val <= 1017? 99 : 100) )))))))))))))))))))))))))))))))))))) )))))))))))))))))))))))))))))))))))) ))))))))))))))))))))))))))); ADC10CTL0 &= ~ENC; P1DIR &= ~TEST_PIN; P1REN &= ~TEST_PIN; return power; }
void delayMilli() { _delay_cycles(1650); }
void timeToBroadcast(void) { P1OUT |= BIT4; _delay_cycles(250000); P1OUT &= ~BIT4; }
//1.65 ms delay void LCDDELAY2(){ _delay_cycles(1817); }
//40.5 us delay void LCDDELAY1(){ _delay_cycles(45); }
void NFC_ALIGN_SEND (uint16_t bpm, uint16_t temp, uint16_t transit, uint16_t hydro, uint8_t time, uint8_t day, uint8_t pwr, uint16_t addr, uint8_t PWR_PIN, uint8_t PULL_PIN) { /* * Data alignment: * * BPM_H | BPM_L | TRANSIT TIME_H | TRANSIT TIME_L * TEMP_H | TEMP_L | HYDRO_H | HYDRO_L * TIME | DAY | PWR | 0xFF * */ uint16_t l_addr = addr; aligned[0][0] = (uint8_t)(l_addr >> 8); aligned[0][1] = (uint8_t)l_addr; aligned[0][2] = (uint8_t)(bpm >> 8); aligned[0][3] = (uint8_t)bpm; aligned[0][4] = (uint8_t)(transit >> 8); aligned[0][5] = (uint8_t)transit; l_addr += 0x0004; aligned[1][0] = (uint8_t)(l_addr >> 8); aligned[1][1] = (uint8_t)(l_addr); aligned[1][2] = (uint8_t)(temp >> 8); aligned[1][3] = (uint8_t)temp; aligned[1][4] = (uint8_t)(hydro >> 8); aligned[1][5] = (uint8_t)hydro; l_addr += 0x0004; aligned[2][0] = (uint8_t)(l_addr >> 8); aligned[2][1] = (uint8_t)(l_addr); aligned[2][2] = time; aligned[2][3] = day; aligned[2][4] = pwr; aligned[2][5] = 0xFF; /*l_addr += 0x0004; aligned[3][0] = (uint8_t)(l_addr >> 8); aligned[3][1] = (uint8_t)(l_addr); aligned[3][2] = 0xDE; aligned[3][3] = 0xAD; aligned[3][4] = 0xBE; aligned[3][5] = 0xEF; */ P2DIR |= (PULL_PIN); P2OUT |= (PULL_PIN); P2DIR |= (PWR_PIN); P2OUT |= (PWR_PIN); I2C_TO_M24LRXX(aligned[0], PWR_PIN); _delay_cycles(16000); I2C_TO_M24LRXX(aligned[1], PWR_PIN); _delay_cycles(16000); I2C_TO_M24LRXX(aligned[2], PWR_PIN); _delay_cycles(16000); /* I2C_TO_M24LRXX(aligned[3], PWR_PIN); _delay_cycles(16000);*/ P2OUT &= ~(PWR_PIN); P2DIR &= ~(PWR_PIN); P2OUT &= ~(PULL_PIN); P2DIR &= ~(PULL_PIN); }
void MoveLeftMotorForwardSmall() { TA0CCTL0 = OUTMOD_5; _delay_cycles(10000); TA0CCR1 = 30; }
int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT /*g_power = test_power(PWR_SENSE, PWR_ADC_INCH); if(g_power == 0) { g_delay = 2700000; // 15 minutes }*/ g_delay = 1500; // 5 seconds WDTCTL = WDT_MDLY_32; // I just met you IE1 |= WDTIE; // Enable WatchDog Interrupt __bis_SR_register(LPM1_bits + GIE); // Enter LPM1 w/ interrupt while(1) { if(--g_delay==0) // Everything happens in here, woken from watchdog { P1DIR |= BIT4; P1OUT |= BIT4; WDTCTL = WDTPW + WDTHOLD; // Stop WDT IE1 &= ~WDTIE; // Disable WatchDog Interrupt /*g_power = test_power(PWR_SENSE, PWR_ADC_INCH); if(g_power == 0) { g_delay = 2700000; // 15 minutes WDTCTL = WDT_MDLY_32; // But heres my number IE1 |= WDTIE; // Enable WatchDog Interrupt __bis_SR_register(LPM1_bits + GIE); // Enter LPM1 w/ interrupts }*/ _delay_cycles(50); // And this is crazy g_heart_data = measHRTR(HEART_ON_TIME, HR_FOOT_SENSE, HR_LEG_SENSE,HR_ADC_INCH, HR_FOOT_PWR, HR_KNEE_PWR); uint16_t bpm = g_heart_data.bpm; uint16_t ptt = g_heart_data.transit; _delay_cycles(50); g_temp = measTEMP(TEMP_ON_TME, TEMP_SENSE, TEMP_ADC_INCH, TEMP_PWR); _delay_cycles(50); g_hyd = measHYDR(); _delay_cycles(50); NFC_ALIGN_SEND ( bpm, // Measured Beats Per Minute g_temp, // Measured Temp ptt, // Measured Transit Time g_hyd, // Measure Hydration g_timestamp, // Accumulated Timestamp g_daystamp, // Accumulated Daystamp g_power, // Device Power g_addr, // Pointer to next address I2C_PWR, // Power the NFC Transponder PUR_PWR // Power pullups ); g_addr = 0x0000; //g_addr += 0x000C; g_timestamp = g_timestamp + 1; if(g_timestamp == 92) { g_daystamp = g_daystamp + 1; //g_addr = 0x0000; g_timestamp = 0; } /*g_delay = 15000; WDTCTL = WDT_MDLY_32; // But heres my number IE1 |= WDTIE; // Enable WatchDog Interrupt __bis_SR_register(LPM1_bits + GIE); // Enter LPM1 w/ interrupts*/ P1DIR &= ~BIT4; P1OUT &= ~BIT4; break; } } /* Design day demo */ P2DIR |= (HR_FOOT_PWR); P2DIR |= (HR_KNEE_PWR); P2DIR |= (TEMP_PWR); P2OUT |= (HR_FOOT_PWR); P2OUT |= (HR_KNEE_PWR); P2OUT |= (TEMP_PWR); while(1) { g_hyd = measHYDR(); } /* End design day demo */ }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer char * endMessageTop = "You am "; char * endMessageBottomLose = "lose "; char * endMessageBottomWin = "Not lose"; char * deadMessage = "Dead "; unsigned char player; unsigned char mines[NUM_MINES]; while (1) { timer = 0; button = 0; player = initPlayer(); initProgram(); printPlayer(player); generateMines(mines); //run while none of the end-game situations have occurred while ((timer < 4) && !didPlayerWin(player) && !didPlayerHitMine(player, mines)) { if (button) { switch (button) { case BIT0: player = movePlayer(player, RIGHT); break; case BIT1: player = movePlayer(player, LEFT); break; case BIT2: player = movePlayer(player, UP); break; case BIT3: player = movePlayer(player, DOWN); break; } button = 0; } } //if the timer hits 2 seconds, or if the player hits a mine, the game is over if (timer == 4 || didPlayerHitMine(player, mines)) { //displays a special message if the player lost due to hitting a mine if (didPlayerHitMine(player, mines)) { cursorToLineOne(); writeString(deadMessage, 8); _delay_cycles(500000); } button = 0; //displays game over message cursorToLineOne(); writeString(endMessageTop, 8); cursorToLineTwo(); writeString(endMessageBottomLose, 8); } //if the player hits 0xC7 they win, display the win message else if (didPlayerWin(player)) { button = 0; cursorToLineOne(); writeString(endMessageTop, 8); cursorToLineTwo(); writeString(endMessageBottomWin, 8); } // Waits for a button input and then resets the game while (button != 0) { } } }
void sys_reset() { WDTCTL = WDT_MRST_32 + ~WDTHOLD; _delay_cycles(120000); }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // disable WDT initMSP430(); blip(); _delay_cycles(160000); // wait initLCD(); while (1) { _delay_cycles(1600000); blip(); clearScreen(1); set_font(&font_5x7); // FONT_SM setColor(COLOR_16_RED); draw_string(5, 5, "Texas Instruments"); set_font(&font_8x12); // FONT_MD setColor(COLOR_16_WHITE); draw_string(5, 20, "2.2\" 320x240 BoosterPack"); setColor(COLOR_16_BLUE); draw_string(5, 40, "& MSP430F5529 LaunchPad"); setColor(COLOR_16_ORANGE); draw_string(5, 60, "RobG's graphics library"); setColor(COLOR_16_PURPLE); draw_string(5, 80, "Works with:"); setColor(COLOR_16_YELLOW); /* set_font(&font_11x16); // FONT_LG draw_string(5, 100, "F5172 F5510 F5529"); setColor(COLOR_16_GREEN_YELLOW); draw_string(5, 120, "G2553 G2955 & more"); */ set_font(&font_Dyson_8x9); draw_string(5, 120, "DYSON FONT ABC..."); blip(); _delay_cycles(40000000); clearScreen(1); drawTILogo(56, 56, COLOR_16_RED); drawTILogo(55, 56, COLOR_16_RED); drawTILogo(56, 55, COLOR_16_RED); drawTILogo(55, 55, COLOR_16_RED); drawTILogo(50, 50, COLOR_16_WHITE); _delay_cycles(32000000); blip(); shesGotColors(100); _delay_cycles(12000000); blip(); clearScreen(1); drawLogicLines(8); _delay_cycles(16000000); blip(); /*!!sz: drawSpirograph(40, 20, 15); _delay_cycles(16000000); !!*/ setOrientation(++orientation & 0x03); } }
void delayMicro() { _delay_cycles(40); }
void leftMotorForward() { TA0CCTL0 |= OUTMOD_5; _delay_cycles(10000); TA0CCR1 = 60; }
int main(void) { WDTCTL = WDTPW|WDTHOLD; initTimer(); while(1) { RobotMovement(FORWARD); _delay_cycles(1000000); Stop(); _delay_cycles(1000000); RobotMovement(LEFT); _delay_cycles(250000); Stop(); _delay_cycles(1000000); RobotMovement(RIGHT); _delay_cycles(250000); Stop(); _delay_cycles(1000000); RobotMovement(REVERSE); _delay_cycles(1000000); Stop(); _delay_cycles(1000000); RobotMovement(LEFT); _delay_cycles(1000000); Stop(); _delay_cycles(1000000); RobotMovement(RIGHT); _delay_cycles(1000000); Stop(); _delay_cycles(1000000); } return 0 ; }
/* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_8MHZ; // 8MHz clock DCOCTL = CALDCO_8MHZ; P2DIR |= BIT2; // P2.2 is associated with TACCTL1 P2SEL |= BIT2; P2DIR |= BIT4; // P2.4 is associated with TACCTL2 P2SEL |= BIT4; TA1CTL = ID_3 | TASSEL_2 | MC_1; //set duty cycle and MCLK TA1CCR0 = 100; TA1CCR1 = 50; TA1CCTL1 = OUTMOD_7; // set TACCTL1 to Reset / Set mode TA1CCR2 = 50; // set TACCTL2 to Set / Reset mode TA1CCTL2 = OUTMOD_3; ADC10CTL0 = ADC10SHT_3 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled ADC10CTL1 = ADC10DIV_7; ADC10CTL1 |= ADC10SSEL1|ADC10SSEL0; // Select SMCLK for (;;){ stopMovement(); _delay_cycles(110000); if(leftSensor() < 0x190) // two if statements to stay close to left wall { turnLeftLittle(); _delay_cycles(9000); stopMovement(); _delay_cycles(100000); } if(leftSensor() >= 0x170) { turnRightLittle(); _delay_cycles(9000); stopMovement(); _delay_cycles(100000); } if (centerSensor() >=0x170 && leftSensor() >= 0x165) // statement to turn right if both left and center sensors triggered { turnRightBig(); _delay_cycles(7500); stopMovement(); _delay_cycles(100000); } if (centerSensor() < 0x170 && leftSensor() >= 0x170) // has robot move forward when neither sensors are triggered { moveForward(); _delay_cycles(100000); } else if (centerSensor() < 0x190) { moveForward(); _delay_cycles(100000); } } return 0; }
void rightMotorBackwards() { TA1CCTL0 &= ~OUTMOD0; TA1CCTL0 |= OUTMOD_4; _delay_cycles(10000); TA1CCR1 = 0; }
__interrupt void Timer_A(void) { if (CCTL0 & CAP) { bitCounter++; CCR0 += T65; CCTL0 &= ~CAP; } else { switch (bitCounter) { case 0x1000: bitCounter = 0; switch (irSignal & 0x001F) { case 21: // power off all led P2 P2OUT = 0x00; uart_printf("_turn off all led \r\n"); break; case 20: // mute on all led P2 P2OUT |= 0xFF; uart_printf("_turn on all led \r\n"); break; case 3: // digit key 4 P2OUT |= 0x0f; break; case 5: //degit key 6 P2OUT |= 0xf0; break; case 1: // digit key 2 for(;;){ _delay_cycles(500000); P2OUT =~ devRun; devRun >>=1; if(devRun < 0x01)devRun = 0x80; uart_printf("_debug move off right: %u\r\n",devRun); break; } break; case 7: //degit key 8 for(;;){ _delay_cycles(500000); P2OUT = devRun; devRun >>=1; if(devRun < 0x01)devRun = 0x80; uart_printf("_debug move right: %u\r\n",devRun); break; } break; case 4: //degit key 5 for(;;){ _delay_cycles(500000); P2OUT = devRun; devRun <<=1; if(devRun > 0x80)devRun = 0x01; uart_printf("_debug move left: %u\r\n",devRun); break; } break; #ifdef _debug_key case 0: //degit key 1 for(;;){ showled(2,0x10); showled(0,0x20); showled(1,0x40); showled(4,0x80); // break; } break; #endif } irSignal = 0; CCTL0 |= CAP; break; default: if (CCTL0 & SCCI) { CCR0 += T2; } else { irSignal |= bitCounter; CCR0 += T3; } bitCounter <<= 1; break; } } }
void rightMotorForward() { TA1CCTL0 |= OUTMOD_5; _delay_cycles(10000); TA1CCR1 = 60; }
/* * main.c */ void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer unsigned char black, notBlack, button_press, y; // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ button_press = FALSE; black = TRUE; notBlack = FALSE; init(); initNokia(); clearDisplay(0,0,notBlack); vector2d pos = {2,2}; vector2d vel = {1,1}; unsigned char rad = 2; y=1; ball myBall; myBall.position = pos; myBall.velocity = vel; myBall.radius = rad; while(1){ if (UP_BUTTON == 0) { while(UP_BUTTON == 0); if (y>=1) y=y-1; button_press = TRUE; } else if (DOWN_BUTTON == 0) { while(DOWN_BUTTON == 0); if (y<=6) y=y+1; button_press = TRUE; } else if(AUX_BUTTON == 0){ while(AUX_BUTTON == 0); black = !black; notBlack = !black; clearDisplay(0,0,notBlack); drawBlock(myBall.position.y, myBall.position.x, black); drawPaddle(y,0,black); } if (button_press) { button_press = FALSE; //clearDisplay(); drawBlock(myBall.position.y, myBall.position.x, black); drawPaddle(y,0,black); } moveBall(&myBall,y); clearDisplay(0,0,notBlack); drawBlock(myBall.position.y, myBall.position.x, black); drawPaddle(y,0,black); _delay_cycles(5333333); } }