Skip to content

Instantly share code, notes, and snippets.

@RickKimball
Created June 30, 2011 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickKimball/1057217 to your computer and use it in GitHub Desktop.
Save RickKimball/1057217 to your computer and use it in GitHub Desktop.
#include <msp430.h>
#include <stdint.h>
void spewSPI(const uint8_t n) {
static const uint8_t *spiStrTBL[] = {
"parm1",
"parm2",
"...",
"parm99"
};
uint8_t indx; // 0-255 so we get mov.b
if ( n > sizeof(spiStrTBL) / sizeof(spiStrTBL[0]) ) {
return; // ignore out of bounds request
}
for ( indx = 0; spiStrTBL[n][indx] != 0; ++indx ) {
UCA0TXBUF = spiStrTBL[n][indx];
}
}
void callIt() {
spewSPI(0); // send parm1
spewSPI(1); // send parm2
}
.file "tblexample.c"
.arch msp430g2553
.cpu 430
.mpy none
.text
.p2align 1,0
.global spewSPI
.type spewSPI,@function
/***********************
* Function `spewSPI'
***********************/
spewSPI:
cmp.b #5, r15
jhs .L1
mov.b r15, r15
rla r15
mov spiStrTBL.1369(r15), r13
mov.b #0, r14
jmp .L3
.L4:
mov.b r15, &__UCA0TXBUF
add.b #1, r14
.L3:
mov.b r14, r15
add r13, r15
mov.b @r15, r15
cmp.b #0, r15
jne .L4
.L1:
ret
.Lfe1:
.size spewSPI,.Lfe1-spewSPI
;; End of function
.p2align 1,0
.global callIt
.type callIt,@function
/***********************
* Function `callIt'
***********************/
callIt:
mov.b #0, r15
call #spewSPI
mov.b #1, r15
call #spewSPI
ret
.Lfe2:
.size callIt,.Lfe2-callIt
;; End of function
.LC0:
.string "parm1"
.LC1:
.string "parm2"
.LC2:
.string "..."
.LC3:
.string "parm99"
.p2align 1,0
.type spiStrTBL.1369,@object
.size spiStrTBL.1369,8
spiStrTBL.1369:
.word .LC0
.word .LC1
.word .LC2
.word .LC3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment