Starter Code for the Boston University Course ENG EK307 Electric Circuits
Total Page:16
File Type:pdf, Size:1020Kb
// ek307starter_code.c [Ver 1 Sept. 2017]
// Starter code for the Boston University Course ENG EK307 “Electric Circuits”
// This file contains many useful commands and prewritten sections of C code
// that can be used as a starting point for writing programs on the TI
// MSP430G2553 microcontroller.
// If a line of code is followed by //keep!!! , do NOT change or remove.
// It is a statement that is required to make the MSP430 chip or your code run properly.
// DO NOT DELETE any statements that are labeled //keep!!!
// Change the statement below to MPS430GXXXX if you are using a different MSP430 chip
#include
//Examples of statements that declare some general integer variables to be used later
int n;
int k;
int count = 0;
// Your C code for the MSP430 goes here:
// ====MAIN PROGRAM HERE ====
void main(void) { //keep!!!
// Some hardware setup commands:
P2SEL=0; //keep!!! WDTCTL = WDTPW + WDTHOLD; //keep!!!
BCSCTL1 = CALBC1_1MHZ; //keep!!!
DCOCTL = CALDCO_1MHZ; //keep!!!
//Examples of Setting Ports to INPUT or OUTPUT:
//Configure Port 1 and 2 Input/Output directions:
//P1DIR = 255; // Configure all pins of Port 1 outputs
//P1DIR = 0; // Configure all pins of Port 1 inputs
//P1DIR = 1 + 2 + 4 + 8 // Configure pins 0-3 as outputs, pins 4-7 as inputs
//P1DIR = 16+32+64+128 // Set Port 1 pins 4-7 as outputs and pins 0-3 as inputs
//P2DIR = 0; // Configure Port 2 pins P2.6=input and P2.7=input
//P2DIR = 64; // Configure Port 2 pins as follows: P2.6=output and P2.7=input
//P2DIR = 128; // Configure Port 2 pins as follows: P2.6=input and P2.7=output
//P2DIR = 128+64; // Configure Port 2 pins as follows: P2.6=output and P2.7=output
//Examples of write commands to Ports that have been configured with all pins 0-7 as outputs:
//P1OUT = 255; // Sets all pins of Port1 to 1
//P1OUT = 0; // Sets all pins of Port1 to 0
//P1OUT = 32 + 128 // Sets P1.5 and P1.7 to 1; all other Port1 pins to 0.
//P1OUT=160; // Same as above, because 128 + 32 = 160
//P2OUT=128; // Sets P2.7 pin to 1, P2.6 pin to 0
//P2OUT=64; // Sets P2.6 pin to 1, P2.7 pin to 0
//P2OUT=0; // Sets P2.6 and P2.7 to 0
//Examples of read commands from Ports that have been configured with all pins 0-7 as inputs: // n = P1IN;
// count = P2IN;
//EXAMPLES of WHAT MIGHT APPEAR IN YOUR CODE:
// The following command will introduce a delay of n microseconds during execution:
// Note that the command begins __ with *two* underscores__. There is only one after delay_
// __delay_cycles(n)
// The following statement will "toggle" an output port pin (change 0 to 1, change 1 to 0):
// P1OUT ^= 8; // toggles the output of pin P1.3
// P2OUT ^= 2; // toggles the output of pin P2.2
//THE EXECUTABLE PART OF YOUR PROGRAM GOES HERE ======
while(1) //keep!!!
{
// Statements placed here will executed forever until
//the microcontroller is stopped or reset
} // END OF WHILE(1) LOOP
} // END OF MAIN(VOID) //keep!!!