Summary: Programming basic C on an embedded processor.
With the MSP430, With the MSP430, the primary difference between "normal" C and programming C in the embedded space is that you will need to write to registers directly to control the operation of the processor. Fortunately, the groundwork has already been laid for you to make this easier. All of the registers in the MSP430 have been mapped to macros by Texas Instruments. Additionally, the important bit combinations for each of these registers have macros that use the same naming convention as the user’s guide. Other differences from the C used on most platforms include:
int value is 2 bytes (16 bits) long. In this exercise, you may want to use some of the debugging tools to help you understand what the code is doing. You may use any of the following items:
#include <msp430x16x.h>
#include <__cross_studio_io.h>
void main(void){
int i,j,tmp;
int a[20]={0x000C,0x0C62,0x0180,0x0D4A,0x00F0,0x0CCF,0x0C35,0x096E,0x02E4,
0x0BDB,0x0788,0x0AD7,0x0AC9,0x0D06,0x00EB,0x05CC,0x0AE3,0x05B7,0x001D,0x0000};
for (i=0; i<19; i++){
for (j=0; j<9-i; j++){
if (a[j+1] < a[j]) {
tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp;
}
}
}
while(1);
}
#include <__cross_studio_io.h>debug_printf() function will print to standard out. For example, debug_printf("x equals %d\n", x); will print out the value of x to the window. The %d means that x is a number, and \n will produce a line break.Multiplications and division are very complex operations to do on any microprocessor. The operations should be avoided if possible or should be replaced with simpler, equivalent operations.
multiply(int x, int y) that takes parameter x and multiplies it by y by using a bit shift. It must return an int. For symplicity, it is OK to assume that y is a power of 2. divide(int x, int y) that takes parameter x and divides it by y by using a bit shift. It must also return an int.
Open the file msp430x16x.h which should be located in C:\Program Files\Rowley Associates Limited\CrossWorks MSP430 x.x.x\include. This file contains the macros and register definitions for the MSP430F169 we use in this class. Using the MSP430 User’s Guide and the msp430x16x.h file, please answer the following questions.
WDTPW (watchdog timer password) and WDTHOLD (watchdog timer hold) section of the Watchdog Timer Control Register (WDTCTL). Refer to Section 10.3 of the User's Guide for more information. Find the macros for this register in the msp430x16x.h file. How are they different from their description in the User's Guide? Finally, write the C code required to disable it. Write a program to do the following:
" Programming basic C on an MSP430"