static void EnterShippingMode(void) { /* Turn off the watchdog timer */ WDTCTL = WDTPW | WDTHOLD; EnableRstPin(); __delay_cycles(100000); __disable_interrupt(); __no_operation(); /* * the radio draws more current in reset than it does after * the patch is loaded */ DISABLE_DISPLAY_POWER(); DISABLE_LCD_ENABLE(); BATTERY_CHARGE_DISABLE(); LIGHT_SENSOR_SHUTDOWN(); BATTERY_SENSE_DISABLE(); HARDWARE_CFG_SENSE_DISABLE(); APPLE_POWER_DISABLE(); ACCELEROMETER_INT_DISABLE(); DISABLE_BUTTONS(); SELECT_ACLK(SELA__REFOCLK); SELECT_FLLREF(SELREF__REFOCLK); UCSCTL8 &= ~SMCLKREQEN; UCSCTL6 |= SMCLKOFF; /* disable aclk */ P11SEL &= ~BIT0; XT1_Stop(); /* turn off the regulator */ unsigned char temp = PMMCTL0_L; PMMCTL0_H = PMMPW_H; PMMCTL0_L = PMMREGOFF | temp; LPM4; __no_operation(); __no_operation(); /* should not get here without a power event */ SoftwareReset(); }
int clock_main(void) { char ch; WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1DIR = 0b00000011; P1OUT = 0x00; // Enable P2 interrupts for buttons. P2OUT = BUTTON_BITS; P2DIR &= ~BUTTON_BITS; P2REN = BUTTON_BITS; P2SEL &= ~BUTTON_BITS; P2IE = BUTTON_BITS; P2IES = BUTTON_BITS; P2IFG &= ~(BUTTON_BITS); load_and_reset(); uart_init(); lcd_init(); // Setup timer B0 to count exactly each second. TB0CCTL0 = CCIE; TB0CCR0 = 32758; TB0CTL = TBSSEL_1 // Input source: ACLK. + MC_1 + TBCLR; __bis_SR_register(GIE); while (1) { __delay_cycles(0x47FF); while (receiveBufferSize > 0) { ch = rcvbuff[--receiveBufferSize]; cmdbuff[cmdbuff_size++] = ch; uart_send_char(ch); if (ch == 0x0D) { //uart_send_char('\r'); uart_send_char('\n'); parse_time(cmdbuff); cmdbuff_size = 0; } } } }
// ************************************************************************************************* // @fn Strobe // @brief Send command to radio. // @param none // @return none // ************************************************************************************************* unsigned char Strobe(unsigned char strobe) { uint8_t statusByte = 0; uint16_t int_state, gdo_state; // Check for valid strobe command if ((strobe == 0xBD) || ((strobe > RF_SRES) && (strobe < RF_SNOP))) { ENTER_CRITICAL_SECTION(int_state); // Clear the Status read flag RF1AIFCTL1 &= ~(RFSTATIFG); // Wait for radio to be ready for next instruction while (!(RF1AIFCTL1 & RFINSTRIFG)); // Write the strobe instruction if ((strobe > RF_SRES) && (strobe < RF_SNOP)) { gdo_state = ReadSingleReg(IOCFG2); // buffer IOCFG2 state WriteSingleReg(IOCFG2, 0x29); // c-ready to GDO2 RF1AINSTRB = strobe; if ((RF1AIN & 0x04) == 0x04) { // chip at sleep mode if ((strobe == RF_SXOFF) || (strobe == RF_SPWD) || (strobe == RF_SWOR)) { } else { while ((RF1AIN & 0x04) == 0x04); // c-ready ? __delay_cycles(9800); // Delay for ~810usec at 12MHz CPU clock } } WriteSingleReg(IOCFG2, gdo_state); // restore IOCFG2 setting } else { // chip active mode RF1AINSTRB = strobe; } statusByte = RF1ASTATB; while (!(RF1AIFCTL1 & RFSTATIFG)); EXIT_CRITICAL_SECTION(int_state); } return statusByte; }
__interrupt void Port1 (void) { if(P1OUT & BIT0) { P1OUT&=~BIT0; //LED ausschalten P1OUT^=BIT6; //LED 2 Einschalten } else { P1OUT^=BIT0; //LED Einschalten P1OUT&=~BIT6; //LED 2 ausschalten } __delay_cycles(300000); P1IFG &= ~BIT3; // P1.3 Interrupt Flag cleared }
void main() { WDTCTL=WDTPW+WDTHOLD; ADC10_init(); LCD_Init(); while(1) { ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start // _bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled __delay_cycles(1000); //-----ADC转换完成中断唤醒CPU后才执行以下代码----- temp = ADC10MEM; //读取AD采样值 IntDeg= temp*4225/1024 - 2777; //转换为摄氏度,并10倍处理 // IntDeg=-123; //由于难以获得负温,直接给负值以测试LCD显示 LCD_Display(); //调用LCD显示函数 } }
int main( void ) { WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer P1DIR = 0b01000111; // IN:UltraEcho(P1.6) Colour1(P1.1),Colour2(P1.2),Colour3(P1.3) OUT:UltraTrig(P1.7) P2DIR = 0b00110110; // OUT:MotorOppCap(P2.1 and P2.2), MotorCap(P2.3 and P2.4) // Configure the Basic Clock Module DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; // Main loop repeats forever while(1) { if (detected() == 1) // If ultrasonic detects within 77cm { led(1); // Turn on the LED forward(); // Drive both motors forward } else // If ultrasonic doesn't detect within 74cm { led(0); // Turn off the LED turn_left(); // Begin Spinning to the left. } if (colourFor() == 1) { backward(); // Drive both motors forward. } if (colourBkL() == 1) { turn_right(); // Spin the robot to the right. } if (colourBkR() == 1) { turn_left(); // Spin the robot to the left. } __delay_cycles(50000); // Delay for 50ms to allow echo pulse to die down } }
/* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //Set clk = 1MHz DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; //End set clk = 1MHz //Config I2C control registries USICTL0 |= USIPE7 + USIPE6 + USISWRST; //Enable port function and reset regitries USICTL1 |= USII2C + USISTTIE + USIIE; //Enable I2C and enable interrupts USICKCTL |= USICKPL; //Set clk polarity as inactive state high //End config I2C control registries USICTL0 &= ~USISWCLK; //start USI USICTL1 &= ~USIIFG; //Clear interrupt flag //Set ports P1DIR = 0xF7; //All output less P1.3 (switch) P1OUT = 0x01; //End set ports _EINT(); //Enable interrupt while(1) { if(i2cDataRX == 0x0F) //Command to start counting { while(~(P1IN & 0x04)) //While s2 not pressed { i2cDataTX ++; //Increase counting P1OUT ^= 0x01; //Toggle LED __delay_cycles(1000); //Delay }//End while i2cDataTX = 0; //Reset count } else { P1OUT = 0x01; i2cDataTX = 0; } } }
void plot(){ unsigned int sample1,sample2,i=0; buttonsPressed=0; Dogs102x6_init(); Dogs102x6_backlightInit(); Dogs102x6_setBacklight(11); Dogs102x6_setContrast(11); Dogs102x6_clearScreen(); Dogs102x6_stringDraw(7, 0, "*S2=Esc*", DOGS102x6_DRAW_NORMAL); while(1) { if(buttonsPressed){ buttonsPressed=0; lcd_init(); //initialise grlib break; } if(i == 101) { Dogs102x6_clearScreen(); Dogs102x6_stringDraw(7, 0, "*S2=Esc*",DOGS102x6_DRAW_NORMAL); i = 0; } ADC12CTL0 |= ADC12SC + ADC12ENC; // Start sampling/conversion while (ADC12CTL1 & ADC12BUSY) __no_operation(); sample1 = ADC12MEM0 & 0x0FFF; __delay_cycles(1000000); ADC12CTL0 |= ADC12SC + ADC12ENC; // Start sampling/conversion while (ADC12CTL1 & ADC12BUSY) __no_operation(); sample2 = ADC12MEM0 & 0x0FFF; Dogs102x6_lineDraw(i,56-sample1/86,i+1,56-sample2/86,0); /*if(buttonsPressed && BUTTON_S1) { buttonsPressed = 0; while(!(buttonsPressed && BUTTON_S1)); buttonsPressed = 0; }*/ ++ i; } }
void main(void) { WDTCTL = WDTPW + WDTHOLD; P2DIR = 0xff; while(1) { for(j=0;j<256;j++) { P2OUT=0xff; // initialization P2OUT &=~ j ; //assign pins with binary values __delay_cycles(100000); //software delay } } }
/** Commands that will be recognized by the * microcontroller. */ uint8_t console_execute_command(void) { if(strncmp(command, "quit", 4) == 0) { DEBUG("Logging out\r\n"); return 1; } if(strncmp(command, "exit", 4) == 0) { DEBUG("Logging out\r\n"); return 1; } if(strncmp(command, "bsl", 3) == 0) { DEBUG("Entering bsl\r\n"); __delay_cycles(1000); msp_reset_to_bsl(); return 0; } DEBUG("Unknown command\r\n"); return 0; }
__interrupt void PORT1ISR(void) { //if switch two was pressed, debounce and then clear flag if(SW_PxIFG & SW2) { __delay_cycles(5000); FLAGS |= SW2FLAG; SW_PxIFG &= ~SW2; } else if (GDO0_PxIFG & GDO0_PIN) //SW2 { FLAGS |= GDO0FLAG; GDO0_PxIFG &= ~GDO0_PIN; } LPM3_EXIT; }
void main(){ volatile uint32_t gpio; /* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */ CT_CFG.SYSCFG_bit.STANDBY_INIT = 0; /* Toggle GPO pins TODO: Figure out which to use */ gpio = 0x000F; /* TODO: Create stop condition, else it will toggle indefinitely */ while(1){ __R30 ^= gpio; __delay_cycles(100000000); } /* Halt the PRU core */ __halt(); }
void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1DIR |= LED; // Set LED pin -> Output P1DIR &= ~SW; // Set SW pin -> Input P1REN |= SW; // Enable Resistor for SW pin P1OUT |= SW; // Select Pull Up for SW pin while(1) { if(!(P1IN & SW)) // If SW is Pressed { __delay_cycles(20000); // Wait 20ms to debounce while(!(P1IN & SW)); // Wait till SW Released P1OUT ^= LED; // Toggle LED } } }
uint8_t ov7670_get(uint8_t addr) { uint8_t retval; i2c_start(); i2c_write8(OV7670_ADDR); i2c_write8(addr); i2c_stop(); __delay_cycles(16 * 1000); i2c_start(); i2c_write8(OV7670_ADDR + 1); retval = i2c_read8(0xFF); i2c_stop(); return retval; }
/** * Initializes FLL of the UCS and wait till settled * * \param fsystem required system frequency (MCLK) in kHz * \param ratio ratio between MCLK and FLLREFCLK */ void Init_FLL_Settle(uint16_t fsystem, uint16_t ratio) { volatile uint16_t x = ratio * 32; // save actual state of FLL loop control uint16_t globalInterruptState = __get_SR_register() & SCG0; __bic_SR_register(SCG0); // Enable FLL loop control Init_FLL(fsystem, ratio); while(x--) { __delay_cycles(30); } __bis_SR_register(globalInterruptState); // restore previous state }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT IFG1 &=~WDTIFG; IE1 &=~WDTIE; WDTCTL = WDTPW + WDTHOLD; WDTCTL = WDT_MDLY_32; // We jump to the WDT interrupt every 32 ms IE1 |= WDTIE; P1DIR |= BIT0; // Set P1.0 to output and P1.3 to input direction P1DIR |= BIT6; // Set P1.6 to output and P1.3 to input direction P1OUT &= ~BIT0; // set P1.0 to Off P1OUT &= ~BIT6; // set P1.0 to Off P1IE |= BIT3; // P1.3 interrupt enabled P1IFG &= ~BIT3; // P1.3 interrupt flag cleared __bis_SR_register(GIE); // Enable all interrupts BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz P1SEL |= TXD; // P1DIR |= TXD; // __bis_SR_register(GIE); // interrupts enabled\ /* Main Application Loop */ while(1) { if ((--uartUpdateTimer == 0)) // Transmit the current counter status, a blank, the current rate (last minute) and CRLF // over com port. { TransmitNumber(counter); TransmitByte(0x20); TransmitNumber(currentRate); TransmitByte(10); TransmitByte(13); //wait 1 second __delay_cycles(1000000); } } }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // Configure GPIO P1DIR |= BIT0; // Output for LED P1OUT |= BIT0; PJSEL0 |= BIT4 | BIT5; // Set J.4 & J.5 to accept crystal input for ACLK // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Clock setup CSCTL0_H = CSKEY >> 8; // Unlock CS registers CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK; // Set ACLK = LFXTCLK; MCLK = DCO CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1 CSCTL4 &= ~LFXTOFF; // Turn on LFXT // Check for clock faults // do // { // CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag // SFRIFG1 &= ~OFIFG; // Clear Oscillator fault flag // }while (SFRIFG1&OFIFG); // Test oscillator fault flag // Lock CS registers - Why isn't PUC created? CSCTL0_H = 0; __delay_cycles(2000000); P1OUT ^= BIT0; // Setup timer TB0CCTL0 = CCIE; // TBCCR0 interrupt enabled TB0CCR0 = 8192; // When input divider=8 and clock=32768kHz, this is 32768kHz/8*2s = 8192 TB0CTL = TBSSEL__ACLK | MC__UP | 0xC0; // ACLK, up mode, input divider = 8 __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 w/ interrupt // On return, do stuff P1OUT ^= BIT0; __no_operation(); // For debugger }
int main() { WDTCTL = WDTPW + WDTHOLD; //Stop WDT ucs_clockinit(FREQ, 1, 0); gpio_init(); // Timer 0 for output PWM (for 8bit values) TA0CTL = TASSEL_2 | MC_1; TA0CCR0 = 255; TA0CCTL1 |= OUTMOD_7; TA0CCR1 = 0; // Added for 0 output after reset // Timer 1 to interrupt at sample speed TA1CTL = TASSEL_2 | MC_1; TA1CCR0 = FREQ / SAMPLES_PER_SECOND - 1; TA1CCTL0 |= CCIE; _BIS_SR(GIE); // Enable global interrupts while(1){ if ( counter <= binary_data_size ) { // If data is still playing do LPM0 to keep // the timer running and audio playing. sample = audio_raw[counter++]; LPM0; } else { // If done playing go to LPM4 so that only // the button wakes MCU up. sample = 0; TA0CCR1 = 0; // Added for guaranteed 0 output. __delay_cycles(500); // Needed to not have random pin output // We really dont want Vcc going through speaker when idle P1OUT &= ~RED_LED; LPM4; } } }
//courtesy of C2C Steinmiller... void scrollString(char *string1, char *string2) { unsigned int i = 0; char *count1 = string1, *count2 = string2; while (1) { cursorToLineOne(); char *currentChar = count1; for (i = 0; i < 8; i++) { writeDataByte(*currentChar); //send data in the string to be written currentChar++; if (*currentChar == 0) currentChar = string1; } count1++; if (*count1 == 0) { count1 = string1; } cursorToLineTwo(); char *currentChar2 = count2; for (i = 0; i < 8; i++) { writeDataByte(*currentChar2); //send data in the string to be written currentChar2++; if (*currentChar2 == 0) currentChar2 = string2; } count2++; if (*count2 == 0) { count2 = string2; } __delay_cycles(600000); LCDclear(); } }
int main(void) { WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer PMAPPWD = 0x02D52; // Get write-access to port mapping regs //P2MAP0 = PM_UCA0SIMO; // Map UCA0SIMO output to P2.0 //P2MAP2 = PM_UCA0SOMI; // Map UCA0SOMI output to P2.2 //P2MAP4 = PM_UCA0CLK; // Map UCA0CLK output to P2.4 P1MAP4 = PM_UCB0CLK; P1MAP3 = PM_UCB0SIMO; P1MAP2 = PM_UCB0SOMI; PMAPPWD = 0; // Lock port mapping registers P2OUT |= BIT6 + BIT7; // Set P1.0 for LED // Set P1.2 for slave reset P2DIR |= BIT6 + BIT7; // Set P1.0, P1.2 to output direction P1DIR |= BIT2 + BIT3 + BIT4; // ACLK, MCLK, SMCLK set out to pins P1SEL |= BIT2 + BIT3 + BIT4; // P2.0,2,4 for debugging purposes. UCB0CTL1 |= UCSWRST; // **Put state machine in reset** UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB; // 3-pin, 8-bit SPI master // Clock polarity high, MSB UCB0CTL1 |= UCSSEL_2; // SMCLK UCB0BR0 = 0x02; // /2 UCB0BR1 = 0; // UCA0MCTL = 0; // No modulation UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** UCB0IE |= UCRXIE; // Enable USCI_A0 RX interrupt // P1OUT &= ~0x02; // Now with SPI signals initialized, // P1OUT |= 0x02; // reset slave __delay_cycles(100); // Wait for slave to initialize MST_Data = 0x01; // Initialize data values SLV_Data = 0x1F; // while (!(UCB0IFG&UCTXIFG)); // USCI_A0 TX buffer ready? UCB0TXBUF = MST_Data; // Transmit first character __bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts }
/* * ======== System_graceInit ======== * Initialize MSP430 Status Register */ void System_graceInit(void) { /* USER CODE START (section: System_graceInit_prologue) */ /* User initialization code */ /* USER CODE END (section: System_graceInit_prologue) */ /* Clear oscillator fault flag with software delay */ do { // Clear OSC fault flag IFG1 &= ~OFIFG; // 50us delay __delay_cycles(800); } while (IFG1 & OFIFG); /* * IFG1, Interrupt Flag Register 1 * * ~ACCVIFG -- No interrupt pending * ~NMIIFG -- No interrupt pending * ~OFIFG -- No interrupt pending * WDTIFG -- Interrupt pending * * Note: ~<BIT> indicates that <BIT> has value zero */ IFG1 &= ~(WDTIFG); /* * IE1, Interrupt Enable Register 1 * * ~ACCVIE -- Interrupt not enabled * ~NMIIE -- Interrupt not enabled * ~OFIE -- Interrupt not enabled * WDTIE -- Interrupt enabled * * Note: ~<BIT> indicates that <BIT> has value zero */ IE1 |= WDTIE; /* USER CODE START (section: System_graceInit_epilogue) */ /* User code */ /* USER CODE END (section: System_graceInit_epilogue) */ }
static void EnterLpm3(void) { #if LPM_ENABLED /* * we are already in critical section so that we do not get switched out by the * OS in the middle of stopping the OS Scheduler. */ DisableRtosTick(); /* errata PMM11 + PMM12 divide MCLK by two before going to sleep */ if ( QueryErrataGroup1() ) { MCLK_DIV(2); } DEBUG1_HIGH(); __enable_interrupt(); LPM3; __no_operation(); DEBUG1_LOW(); /* errata PMM11 + PMM12 - wait to put MCLK into normal mode */ if ( QueryErrataGroup1() ) { __delay_cycles(100); MCLK_DIV(1); } /* Generate a vTickIsr by setting the flag to trigger an interrupt * You can't call vTaskIncrementTick and vTaskSwitchContext from within a * task so do it with an ISR. We need to cause an OS tick here so that tasks * blocked on an event sent by an ISR will run. FreeRTOS queues them for * the next system tick. */ EnableRtosTick(); RTOS_TICK_SET_IFG(); __no_operation(); #endif }
// ***************************************************************************** // @fn Strobe // @brief Send a command strobe to the radio. // @param unsigned char strobe The strobe command to be sent // @return unsigned char statusByte The status byte that follows the strobe // ***************************************************************************** unsigned char Strobe(unsigned char strobe) { unsigned char statusByte = 0; unsigned int gdo_state; // Check for valid strobe command if((strobe == 0xBD) || ((strobe >= RF_SRES) && (strobe <= RF_SNOP))) { // Clear the Status read flag RF1AIFCTL1 &= ~(RFSTATIFG); // Wait for radio to be ready for next instruction while( !(RF1AIFCTL1 & RFINSTRIFG)); // Write the strobe instruction if ((strobe > RF_SRES) && (strobe < RF_SNOP)) { gdo_state = ReadSingleReg(IOCFG2); // buffer IOCFG2 state WriteSingleReg(IOCFG2, 0x29); // chip-ready to GDO2 RF1AINSTRB = strobe; if ( (RF1AIN&0x04)== 0x04 ) // chip at sleep mode { if ( (strobe == RF_SXOFF) || (strobe == RF_SPWD) || (strobe == RF_SWOR) ) { } else { while ((RF1AIN&0x04)== 0x04); // chip-ready ? // Delay for ~810usec at 1.05MHz CPU clock, see Section 22.3.3.7 // Radio Control – Crystal Control of the CC430 User’s Guide (SLAU 259)” __delay_cycles(850); } } WriteSingleReg(IOCFG2, gdo_state); // restore IOCFG2 setting while( !(RF1AIFCTL1 & RFSTATIFG) ); } else // chip active mode (SRES) { RF1AINSTRB = strobe; } statusByte = RF1ASTATB; } return statusByte; }
void radio_Send(uint8_t source_ID){ uint8_t l = 0; while (!g_bufferEmpty){ Packetizer(source_ID, 0); while (P2IN & radio_Busy){} while (j < 39) { write_UART (get_Data(j,source_ID)); // if (source_ID == 0){MOCK0_write_UART[j + (39 * l)] = get_Data(j,source_ID);} // if (source_ID == 1){MOCK1_write_UART[j + (39 * l)] = get_Data(j,source_ID);} // if (source_ID == 2){MOCK2_write_UART[j + (39 * l)] = get_Data(j,source_ID);} j++; } __delay_cycles(5000000); // Radio time for one packet j = 0; l++; } l = 0; }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer - SET BREAKPOINT HERE P1DIR |= 0x01; // Set P1.0 to output direction TA0R = 0x3FFF; // Valid opcode (for "jmp $") while(1) { P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR __delay_cycles(50000); // Delay loop // C code to directly call an address location ((void (*)())0x350)(); // Invalid fetch ("call #0350h") /* 0x350 is address of TA0R register and is within the module register memory address range (0x0100 --0x0FEF) */ } }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR |= BIT6; // P1.6 output direction P1SEL |= BIT6; // Select CBOUT function on P1.6/CBOUT // Setup ComparatorB CBCTL0 |= CBIPEN + CBIPSEL_1; // Enable V+, input channel CB1 CBCTL1 |= CBPWRMD_1; // normal power mode CBCTL2 |= CBRSEL; // VREF is applied to -terminal CBCTL2 |= CBRS_3+CBREFL_2; // R-ladder off; Bandgap voltage amplifier ON and generates 2.0V reference CBCTL3 |= BIT1; // Input Buffer Disable @P6.1/CB1 CBCTL1 |= CBON; // Turn On ComparatorB __delay_cycles(75); // delay for the reference to settle __bis_SR_register(LPM4_bits); // Enter LPM4 __no_operation(); // For debug }
void init_Hbridge() { // configure FIN and RIN on H-Bridge P4SEL0 &= ~FIN; P4SEL1 &= ~FIN; P4DIR |= FIN; P4OUT &= ~FIN; // set FIN low to select open state of H-Bridg P2SEL0 &= ~RIN; P2SEL1 &= ~RIN; P2DIR |= RIN; P2OUT &= ~RIN; // set RIN low to select open state on direction on H-Bridge // put dac in known state and set vref to zero uint16_t zero = 0; write_uint16_SPI(zero, DAC); motorOpen(); // set motor in open direction __delay_cycles(100); }
/**********************************************************************//** * \brief FLL Initialization Routine * * This function sets up FLLN (the FLL frequency multiplier) based on the * provided target frequency and the on-board LF reference oscillator (REFO) * * \retval -1 The FLL multiplier computed was out-of-bounds * \returns The resulting target frequency for the FLL feedback control *************************************************************************/ long setFLL(unsigned long TargetFreq) { unsigned int fllMult = (unsigned int)(TargetFreq >> 15); // fllMult = TargetDCO/32768 // Basic Universal Clock System (UCS) Init UCSCTL3 = SELREF_2; // Set FLL Reference to REF0 (internal reference oscillator) UCSCTL4 = SELA_2 + SELS_4 + SELM_4; // Set ACLK = REF0, SMCLK = MCLK = DCOCLKDIV if(fllMult > 1024) // If FLL multiplier cannot be represented in 10 bits return -1; // Return failure __bis_SR_register(SCG0); // Disable the FLL control loop UCSCTL0 = 0; // Set lowest possible DCOx and MODx bits // DCO Resistor Selection (RSEL) if(fllMult <= 30) // TargetFreq < 1MHz UCSCTL1 = DCORSEL_0; else if(fllMult <= 62) // 1MHz < TargetFreq < 2MHz UCSCTL1 = DCORSEL_1; else if(fllMult <= 123) // 2MHz < TargetFreq < 4MHz UCSCTL1 = DCORSEL_2; else if(fllMult <= 245) // 4MHz < TargetFreq < 8 MHz UCSCTL1 = DCORSEL_3; else if(fllMult <= 490) // 8MHz < TargetFreq < 16MHz UCSCTL1 = DCORSEL_4; else if(fllMult <= 611) // 16MHz < TargetFreq < 20MHz UCSCTL1 = DCORSEL_5; else // 20MHz < TargetFreq < 33MHz UCSCTL1 = DCORSEL_6; UCSCTL2 = fllMult & FLLN_MASK; // Set FLLN (FLL Multiplier) __bic_SR_register(SCG0); // Enable the FLL control loop __delay_cycles(CLOCK_STAB_PERIOD); // Delay and let clock stabilize // Loop until XT1,XT2 & DCO fault flag is cleared do { UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags } while (SFRIFG1&OFIFG); // Test oscillator fault flag return (fllMult << 15); // Return DCO frequency }
void main(void) { /* Configure GPI and GPO as Mode 0 (Direct Connect) */ CT_CFG.GPCFG0 = 0x0000; /* Clear GPO pins */ __R30 &= 0xFFFF0000; /* Spin in loop until interrupt on HOST 1 is detected */ while (1) { if (__R31 & HOST1_MASK) { TOGGLE_BLUE; /* Clear interrupt event */ CT_INTC.SICR = 16; /*TODO: Clear event 16*/; /* Delay to ensure the event is cleared in INTC */ __delay_cycles(5); } } }
void main(void) { WDTCTL = WDTPW + WDTHOLD; _disable_interrupts(); clkInit(DCO_FREQ); CHG_CONFIG(); //LED_RED_CONFIG(); //LED_GREEN_CONFIG(); //SW1_CONFIG(); _enable_interrupts(); #ifdef CDC_CONT //register ADC with default codeword for continuous sampling myCDC = registerCDC(CDC_CHEN1 | CDC_CHEN2 | CDC_SAMPLEC); // resetCDC(); __delay_cycles(250000); setCDC(myCDC); writeRegCDC(CDC_POS, CDC_DACPEN | 0x01); //setup the CAPDAC (vertical offset capacitance compensation) writeRegCDC(CDC_SETUP1, CDC_SE_25pF); //set the full scale range startCDC(); while (1) { _nop(); // writeRegCDC(testReg, testVal); _nop(); readRegCDC(CDC_STATUS, 16); } #else myADC = registerADS(ADS_01, ADS_DEFAULT1); //register ADc with default codeword for 1 shot sampling setADS(myADC); while(1) { a = singleShotADS(); } #endif }