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