Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. ;-------------------------------------------------------------------------------
  2. ; MSP430 Assembler Code Template for use with TI Code Composer Studio
  3. ;
  4. ;
  5. ;-------------------------------------------------------------------------------
  6. .cdecls C,LIST,"msp430.h" ; Include device header file
  7.  
  8. ;-------------------------------------------------------------------------------
  9. .def RESET ; Export program entry-point to
  10. ; make it known to linker.
  11. ;-------------------------------------------------------------------------------
  12. .text ; Assemble into program memory.
  13. .retain ; Override ELF conditional linking
  14. ; and retain current section.
  15. .retainrefs ; And retain any sections that have
  16. ; references to current section.
  17.  
  18. ;-------------------------------------------------------------------------------
  19. RESET mov.w #__STACK_END,SP ; Initialize stackpointer
  20. StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
  21.  
  22.  
  23. ;-------------------------------------------------------------------------------
  24. ; Main loop here
  25. ;-------------------------------------------------------------------------------
  26.  
  27. ;ports are set as input on start so we don't need to set port 2 for hexes
  28. init BIS.B #0FFh,&P3DIR ;set port 3 as output
  29. CLR.B &P3OUT
  30. CLR R9
  31. CLR R5
  32.  
  33. MOV.B #00Ah, &P1IE ;set port 1 as interrupt + input
  34. MOV.B #00Ah, &P1IES
  35.  
  36. ;R5 - state of the counter
  37. ;R6 - button state
  38. ;R7 - loop counter
  39. ;R8 - flag that two buttons were pressed at the same time on load (so ignore clk later)
  40. main
  41. CLR.B &P1IFG
  42. BIS #GIE+CPUOFF+SCG1+SCG0, SR
  43. MOV.B #00Ah, &P1IE ;enable interrupts
  44.  
  45.  
  46. mainloop
  47. MOV.B &P1IN, R6
  48. BIT.B #08h, R6 ;check if the load button was clicked
  49. JZ load
  50. CMP #01h, R8
  51. MOV.B #0, R8 ;reset the flag
  52. JZ main ;there was a load but it's not anymore, so go to sleep
  53. BIT.B #02h, R6 ;just in case test if clock was pressed
  54. JNZ main ;not zero - not pressed
  55.  
  56. jittersetup
  57. MOV.W #007FFh, R7 ;set the loop counter
  58. BIS #GIE, SR ;enable interrupts
  59.  
  60. jitterloop
  61. DEC.W R7 ;2 cycles
  62. MOV.B &P1IN, R6 ;3 cycles
  63. BIT #08h, R6 ;2 cycles
  64. JZ load ;2 cycles
  65. BIT #02h, R6 ;test the clock input - we know "on" is "0" 2 cycles
  66. JNZ main ;if it was 1, go to sleep 2 cycles
  67. CMP.W #0, R7 ;if we got to 2 cycles
  68. JNZ jitterloop ;2 cycles
  69.  
  70. decrease
  71. BIC #GIE, SR ;disable interrupts
  72. BIT.B #01h, R8 ;check if the load button was clicked in the meanwhile
  73. JNZ load ;otherwise, clock was clicked
  74. DEC.B R5 ;decrease, set out and go to sleep
  75. MOV.B R5, &P3OUT
  76. JMP main
  77.  
  78. load
  79. MOV.B &P2IN, R5 ;move the values set by the user
  80. MOV.B R5, &P3OUT
  81. CLR R8
  82. OR #0F5h, R6
  83. CMP #0F5h, R6
  84. JNZ mainloop
  85. is_two
  86. MOV.B #1, R8 ;flag that there was a load
  87. JMP mainloop ;load is enabled by value, not edge, so check it again
  88.  
  89. PORT1_ISR
  90. MOV.B &P1IN, R6 ;set the button state to the register
  91. CLR.B &P1IFG ;clear the interrupt flags
  92. BIC #GIE+CPUOFF+SCG1+SCG0, 0(SP) ;wake up the cpu
  93. RETI
  94.  
  95. ;-------------------------------------------------------------------------------
  96. ; Stack Pointer definition
  97. ;-------------------------------------------------------------------------------
  98. .global __STACK_END
  99. .sect .stack
  100.  
  101. ;-------------------------------------------------------------------------------
  102. ; Interrupt Vectors
  103. ;-------------------------------------------------------------------------------
  104. .sect ".reset" ; MSP430 RESET Vector
  105. .short RESET
  106. .sect ".int04"
  107. .short PORT1_ISR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement