int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer _disable_interrupt(); halUCS_set16MFrequency(); _enable_interrupt(); halBioAX12_initialize(); halLed_sx_initialize(); halLed_sx_setLed(LED_RED, ON); halLed_sx_setLed(LED_YELLOW, OFF); halLed_rx_initialize(); halLed_rx_setLed(LED_RX_ALL, OFF); halTimer_b_initialize(TIMER_CLKSRC_ACLK, TIMER_MODE_UP); halTimer_b_setCCRTimedInterruption(TIMER_CCR0, 1000); halTimer_b_enableInterruptCCR0(); halJoystick_initialize(); halJoystick_setInterruptions(JOYSTICK_ALL, ON); halButtons_initialize(); halButtons_setInterruptions(BUTTON_ALL, ON); return 0; }
void main() { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer (good dog) _disable_interrupt(); cron.seconds = 0; cron.minutes = 0; cron.hours = 0; alarm.seconds = 30; alarm.minutes = 2; alarm.hours = 0; initialize_leds(); initialize_lcd(); initialize_buttons(); initialize_timer_b(); initialize_timer_a1(); _enable_interrupt(); halLcdPrintLine(lcd_line, 0, OVERWRITE_TEXT); write_time_base(); write_cron(); while ( 1 ); }
// ----------------------------------------------------------------------- // ----------------------------------------------------------------------- void main(void) { initMSP430(); // Setup MSP to process IR and buttons int32 bitstring=0x00000000; int32 i; int8 packetIndex2=0; stopRobot(); _enable_interrupt(); while(1) { if (new_packet) { _disable_interrupt(); packetIndex2=0; //this part consolidates the incoming packet while (packetData[packetIndex2]!=2) { packetIndex2++; } packetIndex2++; while (packetIndex2<33) { bitstring+=packetData[packetIndex2]; bitstring<<=1; packetIndex2++; } if (bitstring==BUTTON_FIVE) //this part translates the packet { stopRobot(); } else if (bitstring==BUTTON_TWO) { moveRobotForward(); } else if (bitstring==BUTTON_FOUR) { moveRobotLeft(); } else if (bitstring==BUTTON_SIX) { moveRobotRight(); } else if (bitstring==BUTTON_EIGHT) { moveRobotBackwards(); } else if (bitstring==BUTTON_ONE) { moveRobotLeftSlow(); } else if (bitstring==BUTTON_THREE) { moveRobotRightSlow(); } else { stopRobot(); } for (i=0;i<0xFFFFF;i++); bitstring=0x00000000; packetIndex=0; _enable_interrupt(); new_packet=0; } else { bitstring=0x00000000; } } // end infinite loop } // end main
void process_start(void) { //Set up timer A interrupt TACCR0 = 0x00EE;//Period (Timer count value) TACTL = TASSEL_2 + ID_3 + MC_1;//SMCLK clock, Input Divider of 8, Up-mode (count) TACCTL0 = CCIE; // Enable Timer interrupts //Call process_begin()to start execution of processes in queue _disable_interrupt(); process_begin(); }
inline void StopCapture() { _disable_interrupt(); TACTL = MC_0; for (int i = 0; i < _logCnt; i ++) { _logBuf[i] /= CPU_FREQ; } }
__interrupt void timerOverflow (void) { //Turn off Timer A TACTL &= ~MC_0; //Disable Interrupt for timer A _disable_interrupt(); //Clear Packet Index packetIndex = 0; //Set new Packet to true newIrPacket = TRUE; //Clear TAIFG TACTL &= ~TAIFG; }
void flash_write(uint8_t *addr, uint8_t value) { _disable_interrupt(); // Disable interrupts(IAR workbench). FCTL2 = FWKEY + FSSEL_1 + FN0; // Clk = SMCLK/4 FCTL3 = FWKEY; // Clear Lock bit FCTL1 = FWKEY + WRT; // Set WRT bit for write operation *addr=value; // if(option == WRITE_FROM_BUFFER) //// for (i=0; i<64; i++) //// *addr++ = data_buffer[i]; // copy value to flash // // else if(option == WRITE_FROM_DUMP) // for (i=0; i<64; i++) // *addr++ = data_dump[i]; // copy value to flash FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit _enable_interrupt(); }
int process_create(void(*f)(void), int n) { unsigned int sp_create;//Stack pointer (SP) for process /*Create queue_t and process_t (allocate memory)*/ queue_t *elm = (queue_t *)malloc(sizeof(queue_t)); elm->p = (process_t *)malloc(sizeof(process_t)); //Initialize memory allocation for running the process _disable_interrupt(); sp_create = process_init(f,n); _enable_interrupt(); //If memory allocation failed if (sp_create == 0)return -1; else { //Memory Allocation Success. Set process's SP and Add elm to queue elm->p->sp = sp_create; add_queue(elm); return 0; } }
void UCB0I2CRead(unsigned char countByte, unsigned char *RXpnter, unsigned char startRegister){ RXBytes=RXpnter; //assign the local pointer (pnter) to the global pointer for recieving data, instantiated above byteCountRX=countByte; unsigned char IER=UCB1IE; _disable_interrupt(); //First we have to write the start Register and the Slave Address UCB1CTL1|=UCTR+UCTXSTT; // to the Bus. This section does so without transmitting a STOP //condition, preparing us for a repeated START condition UCB1TXBUF=startRegister; while(UCB1CTL1 & UCTXSTT); UCB1IFG&=~UCTXIFG; UCB1CTL1&=~(UCTR+UCTXSTT); __enable_interrupt(); /* This section below triggers the RX ISR */ UCB1CTL1|=UCTXSTT; //set start condition if it does not already exist, ISR handles the rest }
// ----------------------------------------------------------------------- // ----------------------------------------------------------------------- void main(void) { initMSP430(); // Setup MSP to process IR and buttons while(1) { if (newIrPacket) { //Got a new packet! _disable_interrupt(); newIrPacket = FALSE; packetIndex = 0; if(packetBits == ONE){ P1OUT ^= BIT0; //Alternate the Red LED } else if(packetBits == TWO){ P1OUT ^= BIT6; //Alternate the Green LED } _enable_interrupt(); } // end if new IR packet arrived } // end infinite loop } // end main
void main(void) { // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL = WDTPW|WDTHOLD; // stop the watchdog timer initMSP430(); P2DIR |= BIT2; // P2.2 is associated with TA1CCR1 P2SEL |= BIT2; // P2.2 is associated with TA1CCTL1 P2DIR |= BIT4; // P2.2 is associated with TA1CCR2 P2SEL |= BIT4; // P2.2 is associated with TA1CCTL2 TA1CTL = ID_3 | TASSEL_2 | MC_1; // Use 1:8 presclar off MCLK TA1CCR0 = 100; // set signal period TA1CCR1 = 20; TA1CCTL1 = OUTMOD_7; // set TACCTL1 to Reset / Set mode TA1CCR2 = 80; TA1CCTL2 = OUTMOD_3; // P2.0 - Timer1_A, capture: CCI0A input, compare: Out0 output // P2.1 - Timer1_A, capture: CCI1A input, compare: Out1 output // P2.3 - Timer1_A, capture: CCI0B input, compare: Out0 output // P2.5 - Timer1_A, capture: CCI2B input, compare: Out2 output while(1) { if(flagged==1) { _disable_interrupt(); packetCount = 0; while(packetData[packetCount]==2) { packetCount++; } while(packetCount<33) { irPacket+=packetData[packetCount]; irPacket<<=1; packetCount++; } irPacket+=packetData[packetCount]; if(irPacket == SEL) { stopMovingForward(); stopMovingBackward(); movement=0; } if (movement == 0) { if(irPacket == CH_UP) { moveForward(); movement = 1; } if(irPacket == CH_DW) { moveBackward(); movement = 1; } if(irPacket == CH_L) { moveLeft(); } if(irPacket == CH_R) { moveRight(); } } unsigned int i; for(i=0; i<0xFFFF;i++); for(i=0; i<0xFFFF;i++); for(i=0; i<0xFFFF;i++); packetIndex=0; irPacket=0x00000000; flagged =0; _enable_interrupt(); } else { irPacket = 0x00000000; } } // end if new IR packet arrived } //end forever loop
// ----------------------------------------------------------------------- // Main: Initializes the MSP430 and checks input for a known code // ----------------------------------------------------------------------- void main(void) { init(); initNokia(); initMSP430(); // Setup MSP to process IR and buttons clearDisplay(); x=1; y=1; color= BLACK; drawBlock(y,x);//, color); while(1) { if (newIrPacket) { //Got a new packet! _disable_interrupt(); newIrPacket = FALSE; packetIndex = 0; if(IS_BUTTON_ONE){ P1OUT ^= BIT0; //Alternate the Red LED } else if(IS_BUTTON_TWO){ P1OUT ^= BIT6; //Alternate the Green LED } //Check if color is changed by middle button else if(packetBits == BIG_MIDDLE){ color = (color+1)%2; } //Check if up button is pressed else if (packetBits == BIG_UP) { if (y>=1) y=y-1; drawBlock(y,x,color); } //Check if down button is pressed else if (packetBits == BIG_DOWN) { if (y<=6) y=y+1; drawBlock(y,x,color); } //Check if left button is pressed else if (packetBits == BIG_LEFT) { if (x>=1) x=x-1; drawBlock(y,x,color); } //Check if right button is pressed else if (packetBits == BIG_RIGHT) { if (x<=10) x=x+1; drawBlock(y,x,color); } initMSP430(); _enable_interrupt(); } // end if new IR packet arrived } // end infinite loop } // end main
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initMSP430(); while (1) { if (packetIndex > 40) { _disable_interrupt(); while(packetData[i] != 2 && i < 80){ i++; } for(j = 0; j < 31; j++){ i++; irPacket += packetData[i]; irPacket <<= 1; } if(irPacket == CH_UP){ initRobot(); moveForward(50); newPacket = TRUE; } if(irPacket == CH_DW){ initRobot(); moveBackward(50); newPacket = TRUE; } if(irPacket == VOL_UP){ initRobot(); turnRight(50); newPacket = TRUE; } if(irPacket == VOL_DW){ initRobot(); turnLeft(50); newPacket = TRUE; } if(irPacket == ONE){ newPacket = TRUE; } if(irPacket == TWO){ newPacket = TRUE; } if(irPacket == THR){ newPacket = TRUE; } if(irPacket == PWR){ newPacket = TRUE; shutDown(); } if(newPacket == TRUE){ initMSP430(); newPacket = FALSE; } i = 0; packetIndex = 0; _enable_interrupt(); } // end if new IR packet arrived } }
void main(void) { //This sets up the block position unsigned char x, y, c; IFG1=0; // clear interrupt flag1 WDTCTL=WDTPW+WDTHOLD; // stop WD BCSCTL1 = CALBC1_8MHZ; //set up clock DCOCTL = CALDCO_8MHZ; init(); initNokia(); initMSP430(); clearDisplay(); drawBlock(y,x,c); x = 6; y = 4; c=0xFF; initMSP430(); while(1){ // Determine value of IrPacket if(packetIndex == 34){ // if one full signal is recieved, then the loop will iterate _disable_interrupt(); int32 IrPacket = 0; int32 setBit = 0xF0000000; char i; for(i = 2; i<34; i++){ int16 current = packetData[i]; // This is the current element if(current/10 < 100){ IrPacket &= ~setBit; } else { IrPacket |= setBit; } setBit >>= 1; } packetIndex++; // This just makes sure that the loop is not entered into again. initNokia(); // Handle the button presses if (IrPacket == ZERO) { //This is the process in which we pick the "color" of the block if(c == 0xFF){ c = 0; } else if (c == 0){ c = 0xFF; } } if (IrPacket == VOL_UP) { //These just check for button presses in a particular direction. if (y>=1) y=y-1; } else if (IrPacket == VOL_DW) { if (y<=6) y=y+1; } else if (IrPacket == ONE) { if (x>=1) x=x-1; } else if (IrPacket == TWO) { if (x<=10) x=x+1; } drawBlock(y, x, c); //draws the block initMSP430(); //Now we look for another IR input. } }
void getTimeFromTarget(etTargetTime_t *t) { _disable_interrupt(); *t = targetTime; _enable_interrupt(); }
/* * handlePress() * copied from Lab05 * decodes which button was pressed on remote * modified to call appropriate drive function */ void handlePress(){ _disable_interrupt(); int32 result = 0; int32 setter = 0x80000000; //1 in the MSB char i; for(i = 2; i<34; i++){ //traverse array int16 current = packetData[i]; //current element packetData[0] = 0; //clear element if(current/10 < 100){ //is a zero result &= ~setter; //clear bit } else { result |= setter; //set bit } setter >>= 1; //rotate setter } packetIndex++; //ensure the loop is not reentered switch(result){ //take appropriate action case UP: P1OUT ^= BIT0; drive(FORWARD); break; case DOWN: P1OUT ^= BIT6; drive(BACKWARD); break; case LEFT: P1OUT |= (BIT0 | BIT6); drive(LEFT_T); break; case RIGHT: P1OUT ^= (BIT0 | BIT6); drive(RIGHT_T); break; case EXIT: drive(STOP); break; case CH_UP: break; case CH_DW: break; case MUTE: break; } initIR(); }
void main(void) { initMSP430(); moveForward(); P1DIR &= ~BIT3; P1REN |= BIT3; // Left P2DIR |= BIT0; // 1,2EN as OUT P2DIR |= BIT1; // Sets direction of left motor P2DIR |= BIT2; // P2.2 is associated with TA1CCR P2SEL |= BIT2; // P2.2 is associated with TA1CCTL1 // Right P2DIR |= BIT5; // 3,4EN as OUT P2DIR |= BIT3; // direction of right motor P2DIR |= BIT4; // P2.2 is associated with TA1CCR2 P2SEL |= BIT4; // P2.2 is associated with TA1CCTL2 TA1CTL = ID_3 | TASSEL_2 | MC_1; // Use 1:8 presclar off MCLK TA1CCR0 = 100; // set signal period TA1CCR1 = 50; TA1CCTL1 = OUTMOD_7; // set TACCTL1 to Reset / Set mode TA1CCR2 = 50; TA1CCTL2 = OUTMOD_3; // set TACCTL2 to Set / Reset mode while(1) { //This runs if we get a new packet from the remote and decodes it to control the code if(newIRPacket){ _disable_interrupt(); if(packet == VOL_UP){ moveForward(); }else if(packet == VOL_DW){ moveBackward(); }else if(packet == TWO ){ rotateLeft(); __delay_cycles(fullturn); }else if(packet == ONE){ rotateRight(); __delay_cycles(fullturn); }else{ stopMoving(); } //Now we reset the interrupt so we can run through this cycle again. _enable_interrupt(); initMSP430(); newIRPacket= FALSE; } } }