/* * main.c */ #include // Define some numbers (bytes) to be used by the compiler. // Notice that these are defined outside the main program. #define bit0 0x01 // 1 #define bit1 0x02 // 2 #define bit2 0x04 // 4 #define bit3 0x08 // 8 #define bit4 0x10 // 16 #define bit5 0x20 // 32 #define bit6 0x40 // 64 #define bit7 0x80 // 128 int main(void) { // Anything with a type declaration is a parameter we are defining. // Everything else is a defined register or a value defined in the header file. // Stop watchdog timer by setting the control register to the OR of two defined 16 bit words. WDTCTL = WDTPW + WDTHOLD; // Define the directions and sources of digital signals on the P1 terminals. P1DIR |= bit4 | bit0; // Define P1.0 and P1.4 as outputs. P1SEL = bit4 | bit0; // Connect ACLK to P1.0 and SMCLK to P1.4 and set all other bits for digital I/O. P1DIR |= bit6; // Define P1.6 as output. // Set the DCO control register DCOCTL char DCOx = bit7 | bit6; // | bit5; // DCOx = 6 is the max value for RSELx = 15 char MODx = 0x00; // Set the MODx bits to 0. DCOCTL = DCOx | MODx; // OR the two bytes bitwise and write to the 8-bit DCO control register. // Set the clock module control register BCSCTL1 char DIVAx = 0x00; /// bits 4-5 = low char XT2OFFx = bit7; // Setting bit 7 of BCSCTL1 to 1 turns off the high frequency crystal oscillator. char XTSx = 0x00; // Setting bit 6 = 0 turns off the low frequency oscillator. char RSELx = bit3 | bit2 ; //| bit1; // | bit0; // bits 0-3 = high BCSCTL1 = XT2OFFx | XTSx | DIVAx | RSELx; // A byte-size register. // Set the clock module control register BCSCTL2 char DCOR = 0x00; char SELSx =0x00; // SMCLK source is MCLK. char DIVSx = 0x00; // SMCLK divisor is 1. char SELMx = 0x00; // MCLK source is DCOCLK. char DIVMx = 0x00; // MCLK divisor is 1. BCSCTL2 = SELMx | DIVMx | SELSx | DIVSx | DCOR ; // A byte-size register. // Blink the green LED connected to P1.6. for (;;) // Loop forever and ever. { volatile unsigned int i; // volatile to prevent optimization P1OUT ^= bit6; // Toggle P1.6 using exclusive-OR //i = 10000; // Optional delay loop. //do i--; //while (i != 0); } }