Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Program #include /* * Swtich S1 - P1.1 * LED1 - P1.0 */ void delay(void) { volatile unsigned loops = 50000; // Start the

C Program

#include

/* * Swtich S1 - P1.1 * LED1 - P1.0 */

void delay(void) { volatile unsigned loops = 50000; // Start the delay counter at 50,000 while (--loops > 0); // Count down until the delay counter reaches 0 }

void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1REN |= BIT1; // Connect resistor on P1.1 to P1OUT P1OUT |= BIT1; // Set output register for P1.1 to '1' P1DIR |= BIT0; // Make P1.0 an output PM5CTL0 &= ~LOCKLPM5; // Unlock ports from power manager

for (;;) { delay(); // Run the delay sub-routine if (!(P1IN & BIT1)) // Read the input from P1.1 and check its state P1OUT |= BIT0; // If the button was pressed, turn on the LED else P1OUT &= ~BIT0; // If the button wasn't pressed, turn off the LED. } }

Assembly Program

;------------------------------------------------------------------------------- ; MSP430 Assembler Code Template for use with TI Code Composer Studio ; ; ;------------------------------------------------------------------------------- .cdecls C,LIST,\"msp430.h\" ; Include device header file

;------------------------------------------------------------------------------- .def RESET ; Export program entry-point to ; make it known to linker. ;------------------------------------------------------------------------------- .text ; Assemble into program memory. .retain ; Override ELF conditional linking ; and retain current section. .retainrefs ; And retain any sections that have ; references to current section.

;------------------------------------------------------------------------------- RESET mov.w #__STACK_END,SP ; Initialize stackpointer StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer

;------------------------------------------------------------------------------- ; Main loop here ; NOTES: The input button is on P1.1 and the output LED is on P1.0 ;-------------------------------------------------------------------------------

setup: bis.b #BIT1, &P1REN ; Connect resistor on P1.1 to P1OUT bis.b #BIT1, &P1OUT ; Set output register for P1.1 to '1' bis.b #BIT0, &P1DIR ; Make P1.0 an output bic.w #LOCKLPM5, &PM5CTL0 ; Unlock ports from power manager

mainloop: ; The main polling loop

mov.w #50000, R4 ; Start the delay counter at 50,000 delay: dec.w R4 ; Decrement the delay counter for each loop jnz delay ; Keep looping until the counter becomes 0

readinput: bit.b #BIT1, &P1IN ; Read the input from P1.1 and check its state jnz notpressed pressed: bis.b #BIT0, &P1OUT ; If the button was pressed, turn on the LED jmp mainloop notpressed: bic.b #BIT0, &P1OUT ; If the button wasn't pressed, turn off the LED jmp mainloop

;------------------------------------------------------------------------------- ; Stack Pointer definition ;------------------------------------------------------------------------------- .global __STACK_END .sect .stack

;------------------------------------------------------------------------------- ; Interrupt Vectors ;------------------------------------------------------------------------------- .sect \".reset\" ; MSP430 RESET Vector .short RESET

From the MSP 430 C and ASM Program above:

1. Why does a delay loop of 50,000 results in a 0.5 second delay? Show the formula

2 .Why is there a difference in delay between the asm and c code?

3. Include a high-level software flow diagram and function descriptions. Provide additional explanations as required, in particular when interrupts and/or polling methods have been used.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions