<< Chapter < Page | Chapter >> Page > |
The primary difference between "normal" and embedded C programming is that you will need to write directly to registers 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 ez430 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 (Breakpoints, Watch Window, Locals Window) to help you understand what the code is doing.
Start a new project. Cut and paste the following code into main.c:
#include "msp430x20x3.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);
}
while(1)
statement at the end of the code necessary for all programs we write at this point?printf
over setting a breakpoint?#include "stdio.h";
Then, select
Project->Options , the
Library Options tab in
General Options , and finally select
Tiny in the
Printf formatter drop down menu.
The
printf()
function will print to standard out (when the debugger is running, select
View->Terminal I/O ). For example,
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 header file msp430x20x3.h by right clicking the name in your code and selecting Open "msp430x20x3.h" This file contains the macros and register definitions for the ez430 we are using. Using the ez430 schematic, this header file, and ez430's User Guide 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 7.3 of the User's Guide for more information. Find the macros for this register in the header 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 blink SOS in Morse code repeatedly. In Morse code SOS is S:"..." O:"---" S:"..." where each '.' is a shorter blink and a '-' is a longer blink. According to The International Morse Code Standard (on Wikipedia) the relative lengths of times between dots and dashes are as follows:
Notification Switch
Would you like to follow the 'Introduction to the texas instruments ez430' conversation and receive update notifications?