Implement the code in Listings 6.7 and 6.8 using MSP430 Assembly language. I hav
ID: 3590633 • Letter: I
Question
Implement the code in Listings 6.7 and 6.8 using MSP430 Assembly language. I have the rest of the nessecary assembly coding completed. I just need help coding the main loop for each program.
Listing 6.7 in C
#include <msp430.h.
int a[5] = 1,2,3,4,5;
int *a_pointer; void
main(void) {
WDTCTL = WDTPW|WDTHOLD;
a_pointer = a;
a_pointer + = 3;
*a_pointer = 0;
while(1);
}
Listing 6.8 in C
#include <msp430.h>
int a = 0;
int *a_pointer;
void} main(void)
{
WDTCTL = WDTPW|WDTHOLD;
int count;
a_pointer = &a;
for(count = 1; count<10; count++)
{ a_pointer++;
a_pointer = count; }
while(1);
}
Explanation / Answer
For 6.7, I have done some correction which cannot give any error and it can be execute.
#include "msp430f5418.h"
int test[7680] = { 1 };
#pragma DATA_SECTION(testByte, ".testObjSeg") ;
unsigned char testByte [50];
void main( void )
{
// disable watchdog timer
//------------------------
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
test[3] = test[4];
test[7678] = 0xaa;
test[7679] = 0xa0;
test[0] = test[7679] - test[7678];
}
For 6.8
With the help of below program, you can have the correct loop understanding in program.
/* Example code demonstrating the use of pointers.
* It uses the hardware UART on the MSP430G2553 to receive
* and transmit data back to a host computer over the USB connection on the MSP430
* launchpad.
* Note: After programming using CCS it is necessary to stop debugging and reset the uC before
* connecting the terminal program to transmit and receive characters.
* This demo will transmit the characters AB in response to a S been sent each time S is sent the
* order of the characters is swaped. If agen any other character is sent and unknown command response is sent.
*/
#include "msp430g2553.h"
void UARTSendArray(char *TxArray, int ArrayLength);
void UARTSendChar(char *TxChar);
void SwapChars(char *a, char *b);
volatile char data;
volatile char x1;
volatile char x2;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= BIT0 + BIT6; // Set the LEDs on P1.0, P1.6 as outputs
P1OUT = BIT0; // Set P1.0
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ; // Set DCO to 1MHz
/* Configure hardware UART */
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // Use SMCLK
UCA0BR0 = 104; // Set baud rate to 9600 with 1MHz clock (Data Sheet 15.3.13)
UCA0BR1 = 0; // Set baud rate to 9600 with 1MHz clock
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
x1 = 'A';
x2 = 'B';
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
data = UCA0RXBUF;
switch(data){
case 'S':
{
SwapChars(&x1, &x2); // Pass the pointers to variables x1 and x2 to the function
UARTSendChar(x1);
UARTSendChar(x2);
UARTSendArray(" ", 2);
P1OUT &= ~BIT6; // Set P1.0
}
break;
default:
{
UARTSendArray("Unknown Command: ", 17);
UARTSendChar(data);
UARTSendArray(" ", 2);
}
break;
}
}
void UARTSendArray(char *TxArray, int ArrayLength){
// Send number of bytes Specified in ArrayLength in the array at using the hardware UART 0
// Example usage: UARTSendArray("Hello", 5);
// int data[2]={1023, 235};
// UARTSendArray(data, 4); // Note because the UART transmits bytes it is necessary to send two bytes for each integer hence the data length is twice the array length
while(ArrayLength--){ // Loop until StringLength == 0 and post decrement
while(!(IFG2 & UCA0TXIFG)); // Wait for TX buffer to be ready for new data
UCA0TXBUF = *TxArray++; //Write the character at the location specified by the pointer and post increment
}
}