Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <msp430.h>
  2. #include <stdint.h>
  3.  
  4. void spewSPI(uint8_t n) {
  5. const char *spiStrTBL[] = {
  6. "parm1",
  7. "parm2",
  8. "...",
  9. "parm99"
  10. };
  11. uint8_t indx; // 0-255 so we get mov.b
  12.  
  13. if ( n > sizeof(spiStrTBL) / sizeof(spiStrTBL[0]) ) {
  14. return; // ignore out of bounds request
  15. }
  16.  
  17. for ( indx = 0; spiStrTBL[n][indx] != 0; ++indx ) {
  18. UCA0TXBUF = spiStrTBL[n][indx];
  19. }
  20. }
  21.  
  22. void callIt() {
  23. spewSPI(0); // send parm1
  24. spewSPI(1); // send parm2
  25. }
  26.  
  27. // generates this with msp430-gcc -mmcu=msp430g2553 -Os -S testme.c
  28.  
  29. .file "tblexample.c"
  30. .arch msp430g2553
  31. .cpu 430
  32. .mpy none
  33.  
  34. .text
  35. .p2align 1,0
  36. .global spewSPI
  37. .type spewSPI,@function
  38. /***********************
  39. * Function `spewSPI'
  40. ***********************/
  41. spewSPI:
  42. sub #8, r1
  43. mov &C.0.2204, @r1
  44. mov &C.0.2204+2, 2(r1)
  45. mov &C.0.2204+4, 4(r1)
  46. mov &C.0.2204+6, 6(r1)
  47. cmp.b #5, r15
  48. jhs .L1
  49. mov.b r15, r15
  50. rla r15
  51. add r1, r15
  52. mov @r15, r13
  53. mov.b #0, r14
  54. jmp .L3
  55. .L4:
  56. mov.b r15, &__UCA0TXBUF
  57. add.b #1, r14
  58. .L3:
  59. mov.b r14, r15
  60. add r13, r15
  61. mov.b @r15, r15
  62. cmp.b #0, r15
  63. jne .L4
  64. .L1:
  65. add #8, r1
  66. ret
  67. .Lfe1:
  68. .size spewSPI,.Lfe1-spewSPI
  69. ;; End of function
  70.  
  71. .p2align 1,0
  72. .global callIt
  73. .type callIt,@function
  74. /***********************
  75. * Function `callIt'
  76. ***********************/
  77. callIt:
  78. mov.b #0, r15
  79. call #spewSPI
  80. mov.b #1, r15
  81. call #spewSPI
  82. ret
  83. .Lfe2:
  84. .size callIt,.Lfe2-callIt
  85. ;; End of function
  86.  
  87. .LC0:
  88. .string "parm1"
  89. .LC1:
  90. .string "parm2"
  91. .LC2:
  92. .string "..."
  93. .LC3:
  94. .string "parm99"
  95. .p2align 1,0
  96. .type C.0.2204,@object
  97. .size C.0.2204,8
  98. C.0.2204:
  99. .word .LC0
  100. .word .LC1
  101. .word .LC2
  102. .word .LC3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement