for (;;) { } } Analyze and modify the MSP430 source code in the next page to out
ID: 2085441 • Letter: F
Question
for (;;) {
} }
Analyze and modify the MSP430 source code in the next page to output the last three digits of your home street address using a unary number representation. Here is the result of a quick web search to help you with your assignment: The unary numeral system is the bijective base-1 numeral system. It is the simplest numeral system to represent natural numbers: in order to represent a number N, an arbitrarily chosen symbol representing 1 is repeated N times. This system is used in tallying. For example, using the tally mark. For convenience, your design must replace, i.e., display, each tally mark with an LED blink. Your modification of the source code example must introduce a C function that will display a single decimal digit in the unary system in such a way that it must be easy to tell marks and digits apart. This assignment is due on Wednesday August 30th at the beginning of class. Submit a hard copy of your (well-documented) source code and your implementation of your assignment to demonstrate its function at the beginning of class. You will need a USB power source (which will cost about $10 at various locations including Best Buy, Target, Office Depot, Home Depot, etc.). Your implementation should start running as soon as it gets powered up.Explanation / Answer
//***************************************************************************************
// MSP430 Blink LED / Start Stop Blinking with Button Demo - Software Toggle P1.0 & P1.6
//
// Description; Toggle P1.0 and P1.6 by xor'ing them inside of a software loop. To
// start/stop blink, an interrupt in Port 1 will toggle the condition statement.
// ACLK = n/a, MCLK = SMCLK = default DCO
//
// MSP430x2xx
// -----------------
// /|| XIN|-
// | | |
// --|RST XOUT|-
// | P1.6|-->LED
// Button -->|P1.3 P1.0|-->LED
//
// M.Buccini / L. Westlund
// Texas Instruments, Inc
// October 2005
// Built with Code Composer Studio v4
//***************************************************************************************
#include <msp430g2231.h>
#define LED_0 BIT0
#define LED_1 BIT6
#define LED_OUT P1OUT
#define LED_DIR P1DIR
#define BUTTON BIT3
unsigned int blink = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
LED_DIR |= (LED_0 + LED_1); // Set P1.0 and P1.6 to output direction
LED_OUT &= ~(LED_0 + LED_1); // Set the LEDs off
P1REN |= BUTTON; //Enables a puller-Resistor on the button-pin
P1OUT |= BUTTON; //Writes a "1" to the portpin, tellling the resistor to pullup
P1IES |= BUTTON; //Triggers when you PRESS the button :: Pick one...
//P1IES &= ~BUTTON; // Triggers when you RELEASE the button :: ...or pick the other
P1IE |= BUTTON; //Enables the selector-mask for generating interrupts on the relevant pin
__enable_interrupt(); // Interrupts get enabled *here* - they were disabled thus far..
for (;;)
{
if(blink > 0)
{
P1OUT ^= (LED_0 + LED_1); // Toggle P1.0 and P1.6 using exclusive-OR
__delay_cycles(100000); // SW Delay of 10000 cycles at 1Mhz
}
}
}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
blink ^= 0x01;
P1IFG &= ~BUTTON; // P1.3 IFG cleared
LED_OUT &= ~(LED_0 + LED_1); // Clear the LEDs so they start in OFF state
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.