Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; --COPYRIGHT--,BSD_EX
  2. ;  Copyright (c) 2012, Texas Instruments Incorporated
  3. ;  All rights reserved.
  4. ;
  5. ;  Redistribution and use in source and binary forms, with or without
  6. ;  modification, are permitted provided that the following conditions
  7. ;  are met:
  8. ;
  9. ;  *  Redistributions of source code must retain the above copyright
  10. ;     notice, this list of conditions and the following disclaimer.
  11. ;
  12. ;  *  Redistributions in binary form must reproduce the above copyright
  13. ;     notice, this list of conditions and the following disclaimer in the
  14. ;     documentation and/or other materials provided with the distribution.
  15. ;
  16. ;  *  Neither the name of Texas Instruments Incorporated nor the names of
  17. ;     its contributors may be used to endorse or promote products derived
  18. ;     from this software without specific prior written permission.
  19. ;
  20. ;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. ;  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22. ;  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. ;  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. ;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. ;  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. ;  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. ;  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. ;  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. ;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. ;  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ;
  32. ; ******************************************************************************
  33. ;  
  34. ;                        MSP430 CODE EXAMPLE DISCLAIMER
  35. ;
  36. ;  MSP430 code examples are self-contained low-level programs that typically
  37. ;  demonstrate a single peripheral function or device feature in a highly
  38. ;  concise manner. For this the code may rely on the device's power-on default
  39. ;  register values and settings such as the clock configuration and care must
  40. ;  be taken when combining code from several examples to avoid potential side
  41. ;  effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
  42. ;  for an API functional library-approach to peripheral configuration.
  43. ;
  44. ; --/COPYRIGHT--
  45. ;******************************************************************************
  46. ;   MSP430xG46x Demo - Timer_A, Toggle P5.1, TACCR0 Cont. Mode ISR, DCO SMCLK
  47. ;
  48. ;   Description: Toggle P5.1 using software and TA_0 ISR. Toggles every
  49. ;   50000 SMCLK cycles. SMCLK provides clock source for TACLK.
  50. ;   During the TA_0 ISR, P5.1 is toggled and 50000 clock cycles are added
  51. ;   to TACCR0. TA_0 ISR is triggered every 50000 cycles. CPU is normally off
  52. ;   and used only during TA_ISR.
  53. ;   ACLK = 32.768kHz, MCLK = SMCLK = TACLK = default DCO
  54. ;
  55. ;                 MSP430xG461x
  56. ;             -----------------
  57. ;         /|\|              XIN|-
  58. ;          | |                 |  32kHz
  59. ;          --|RST          XOUT|-
  60. ;            |                 |
  61. ;            |             P5.1|-->LED
  62. ;
  63. ;   S. Karthikeyan/ K.Venkat
  64. ;   Texas Instruments Inc.
  65. ;   Dec 2006
  66. ;   Built with IAR Embedded Workbench Version: 3.41A
  67. ;******************************************************************************
  68. #include <msp430.h>
  69. ;-------------------------------------------------------------------------------
  70.             RSEG    CSTACK                  ; Define stack segment
  71. ;-------------------------------------------------------------------------------
  72.             RSEG    CODE                    ; Assemble to Flash memory
  73. ;-----------------------------------------------------------------------------
  74. ; ******************* 1. Инициализация таймера и LCD-дисплея ******************
  75.  
  76. RESET       mov.w #SFE(CSTACK), SP      ; Initialize stackpointer
  77.         mov.b #LCDON + LCD4MUX + LCDFREQ_128, &LCDACTL  ; 4mux LCD, ACLK/128
  78.         mov.b #0x0F, &LCDAPCTL0     ; Segments 0-13
  79.         mov.b #0x1C, &P5SEL         ; set COM pins for LCD
  80. ClearLCD    mov.w #20, R15          ; 15 LCD memory bytes to clear
  81. Clear1      mov.b #0, LCDM1(R15)        ; Write zeros in LCD RAM locations
  82.                         ; to clear display
  83.         dec R15             ; All LCD mem clear?
  84.         jc Clear1           ; More LCD mem to clear go, use JC
  85. StopWDT     mov.w #WDTPW+WDTHOLD, &WDTCTL   ; Stop WDT
  86. SetupFLL    bis.b #XCAP14PF, &FLL_CTL0  ; Configure load caps
  87. OFIFGcheck  bic.b #OFIFG, &IFG1         ; Clear OFIFG
  88.         mov.w #047FFh, R15      ; Wait for OFIFG to set again if
  89. OFIFGwait   dec.w R15           ; not stable yet
  90.         jnz OFIFGwait
  91.         bit.b #OFIFG, &IFG1         ; Has it set again?
  92.         jnz OFIFGcheck          ; If so, wait some more
  93. SetupP5     bis.b #002h, &P5DIR         ; P5.1 output
  94. SetupC0     mov.w #CCIE, &TACCTL0       ; TACCR0 interrupt enabled
  95.  
  96. ; CCIE and CCIFG (bits 4 and 0) are
  97. ;more interrupts associated
  98. ; with the CCR's.
  99.         mov.w #50000, &TACCR0       ;
  100. SetupTA     mov.w #TASSEL_2+MC_2, &TACTL    ; SMCLK, continuous mode
  101.  
  102. ; ****************** 2. Установка начальных значений **************************
  103. Mainloop    mov.w #01024d, R7       ; number
  104.         mov.w #10d, R8          ; skip
  105.                
  106.                
  107.                
  108.                 ;LAB3
  109.                 MOV #16, R13                    ; Underline
  110.                 MOV #0, R9                      ; Counter
  111.                 MOV #0, R10                     ; Number
  112.                 MOV #0, R14                     ; Loop
  113.                 ;LAB3
  114.                
  115.         bis.w #CPUOFF+GIE, SR       ; CPU off, interrupts enabled
  116.         nop                 ; Required for debugger
  117.                
  118.                 ;bis.w #GIE, SR         ; interrupts enabled
  119.                 ;jmp $
  120.                 ;nop
  121.  
  122. ; ****************** 3. Обработчик прерывания *********************************
  123.  
  124. TA0_ISR; DEC NUMBER
  125. ;------------------------------------------------------------------------------
  126.         add.w #50000, &TACCR0       ; Add Offset to TACCR0
  127.         dec.w R8
  128.         jz run
  129.         reti
  130. run:       
  131.         dec.w R7            ; number
  132.         mov.w R7, R4
  133.         call #ITOA          ; int to string
  134.                 mov.w #10d, R8
  135. reti
  136.  
  137. ; * 4. Функция ITOA, переводящая число в строку и выводящая его на LCD-дисплей *
  138. ITOA:
  139.         MOV R4, R12
  140.         MOV.W #00d, R6
  141.  
  142.  
  143. lp     
  144.                 MOV.B LCD_Tab(R13), LCDM3(R6)
  145.         INC R6
  146.         CMP #06d, R6
  147.         JL lp
  148. update        
  149.                 MOV #0, R10
  150.                 MOV #5, R6
  151.  
  152.  
  153.                
  154.                
  155. num
  156.                 MOV.B LCD_Tab(R9), LCDM3(R6)
  157.                 INC R10
  158.                 INC R9
  159.                 INC R14
  160.                 DEC R6
  161.                 CMP #16d, R14
  162.                 JZ loop
  163.                 loop2:
  164.                 CMP #06d, R10
  165.                 JL num
  166.                 JGE update
  167.  
  168.                 ; MOYA VSTAVKA
  169.                 DEC R13
  170.                 JNZ ext
  171.                 MOV #9, R13
  172. ext:        RET
  173.  
  174. loop:           MOV #0, R9
  175.                 JMP loop2
  176.    
  177. ;       Digits code for 4-mux mode
  178. a               EQU 080h        ; .
  179. b               EQU 040h        ; left bottom
  180. c               EQU 020h        ; middle      
  181. d               EQU 001h        ; top
  182. e               EQU 002h        ; right top
  183. f               EQU 008h        ; bottom
  184. g               EQU 004h        ; right bottom
  185. h               EQU 010h        ; left top
  186.  
  187. LCD_Tab     DB      b+d+e+f+g+h      +a           ; Displays '0'
  188.             DB      e+g              +a           ; Displays '1'
  189.             DB      d+e+c+b+f        +a           ; Displays '2'
  190.             DB      d+e+c+g+f        +a           ; Displays '3'
  191.             DB      h+c+e+g          +a           ; Displays '4'
  192.             DB      d+h+c+g+f        +a           ; Displays '5'
  193.             DB      d+h+c+b+f+g      +a           ; Displays '6'
  194.             DB      d+e+g            +a           ; Displays '7'
  195.             DB      b+c+d+e+f+g+h    +a           ; Displays '8'
  196.             DB      c+d+e+f+g+h      +a           ; Displays '9'
  197.             DB      b+c+d+e+g+h    +a           ; Displays 'A'
  198.             DB      b+h+f+g+c        +a           ; Displays 'B'
  199.             DB      f+d+h+b          +a           ; Displays 'C'
  200.             DB      e+g+f+b+c        +a           ; Displays 'D'
  201.             DB      b+c+d+f+h        +a           ; Displays 'E'
  202.             DB      b+c+d+h          +a           ; Displays 'F'
  203.             DB      0h                            ; Displays '_'
  204.                                            
  205. ;------------------------------------------------------------------------------
  206.             COMMON  INTVEC                  ; Interrupt Vectors
  207. ;------------------------------------------------------------------------------
  208.             ORG     RESET_VECTOR            ; MSP430 RESET Vector
  209.             DW      RESET                   ;
  210.             ORG     TIMERA0_VECTOR          ; Timer_A0 Vector
  211.             DW      TA0_ISR                 ;
  212.             END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement