MSP430 C Code Examples from Class: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
---- |
---- |
||
Addressing Modes Demo from Class |
====Addressing Modes Demo from Class==== |
||
<nowiki> |
<nowiki> |
||
#include <msp430.h> |
#include <msp430.h> |
||
Line 25: | Line 26: | ||
} |
} |
||
</nowiki> |
</nowiki> |
||
Recursion Example (Fibonacci Numbers) |
====Recursion Example (Fibonacci Numbers)==== |
||
Don't forget to use mps instead of mspx in your compiler options. It makes the disassembly use only msp instead of mspx instructions. The small memory model is probably also a good idea. |
|||
<nowiki> |
<nowiki> |
||
#include <msp430.h> |
#include <msp430.h> |
||
Line 34: | Line 36: | ||
*/ |
*/ |
||
int main(void) { |
int main(void) { |
||
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer |
|||
int n, i = 0, c, F[10]; |
int n, i = 0, c, F[10]; |
||
Line 60: | Line 62: | ||
</nowiki> |
</nowiki> |
||
====UART Example with Bluetooth==== |
|||
[[C example of using the USCI as a 9600 baud UART to communicate with the HC-06 bluetooth module for the MSP430F5529]] |
Latest revision as of 11:54, 29 November 2016
MSP430 Assembly Code Examples from Class
Addressing Modes Demo from Class
#include <msp430.h> /* * Copy this program, debug it, view the disassembly, and note how the addressing modes work. * main.c */ int dog = 2; int cat; char table[4] = {119,120,121,122}; // 'w','x','y','z' is 119(0x77),120 (0x78), 121 (0x79), 122(0x7A) in ascii char* cow; int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer cat = dog; cat = table[dog]; cow = table; cat = *cow++; cat = *cow; return 0; }
Recursion Example (Fibonacci Numbers)
Don't forget to use mps instead of mspx in your compiler options. It makes the disassembly use only msp instead of mspx instructions. The small memory model is probably also a good idea.
#include <msp430.h> int Fibonacci(int); /* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer int n, i = 0, c, F[10]; n=4; for ( c = 1 ; c <= n ; c++ ) { F[i] = Fibonacci(i); i++; } return 0; } int Fibonacci(int n) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else return ( Fibonacci(n-1) + Fibonacci(n-2) ); }