Facebook
From tytjan, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 156
  1. #include "msp430.h"                     ; #define controlled include file
  2.  
  3.         NAME    main                    ; module name
  4.  
  5.         PUBLIC  main                    ; make the main label vissible
  6.                                         ; outside this module
  7.        
  8.         ORG 0FFEAh
  9.         DC16 TIMER_A1_Interrupt
  10.        
  11.         ORG     0FFE8h                  
  12.         DC16    PORT1_isr               ; set PORT1 Interrupt vector
  13.        
  14.         ORG     0FFFEh
  15.         DC16    init                    ; set reset vector to 'init' label
  16.  
  17.         RSEG    CSTACK                  ; pre-declaration of segment
  18.         RSEG    CODE                    ; place program in 'CODE' segment
  19.  
  20. sine_table:
  21. DB 0x80, 0x83, 0x86, 0x89, 0x8c, 0x8f, 0x92, 0x95,0x98, 0x9b, 0x9e, 0xa2, 0xa5, 0xa7, 0xaa, 0xad,0xb0, 0xb3, 0xb6, 0xb9, 0xbc, 0xbe, 0xc1, 0xc4,0xc6, 0xc9, 0xcb, 0xce, 0xd0, 0xd3, 0xd5, 0xd7,0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8,0xea, 0xeb, 0xed, 0xee, 0xf0, 0xf1, 0xf3, 0xf4,0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfa, 0xfb, 0xfc,0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfd,0xfd, 0xfc, 0xfb, 0xfa, 0xfa, 0xf9, 0xf8, 0xf6,0xf5, 0xf4, 0xf3, 0xf1, 0xf0, 0xee, 0xed, 0xeb,0xea, 0xe8, 0xe6, 0xe4, 0xe2, 0xe0, 0xde, 0xdc,0xda, 0xd7, 0xd5, 0xd3, 0xd0, 0xce, 0xcb, 0xc9,0xc6, 0xc4, 0xc1, 0xbe, 0xbc, 0xb9, 0xb6, 0xb3,0xb0, 0xad, 0xaa, 0xa7, 0xa5, 0xa2, 0x9e, 0x9b,0x98, 0x95, 0x92, 0x8f, 0x8c, 0x89, 0x86, 0x83,0x80, 0x7c, 0x79, 0x76, 0x73, 0x70, 0x6d, 0x6a,0x67, 0x64, 0x61, 0x5d, 0x5a, 0x58, 0x55, 0x52,0x4f, 0x4c, 0x49, 0x46, 0x43, 0x41, 0x3e, 0x3b,0x39, 0x36, 0x34, 0x31, 0x2f, 0x2c, 0x2a, 0x28,0x25, 0x23, 0x21, 0x1f, 0x1d, 0x1b, 0x19, 0x17,0x15, 0x14, 0x12, 0x11, 0x0f, 0x0e, 0x0c, 0x0b,0x0a, 0x09, 0x07, 0x06, 0x05, 0x05, 0x04, 0x03,0x02, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02,0x02, 0x03, 0x04, 0x05, 0x05, 0x06, 0x07, 0x09,0x0a, 0x0b, 0x0c, 0x0e, 0x0f, 0x11, 0x12, 0x14,0x15, 0x17, 0x19, 0x1b, 0x1d, 0x1f, 0x21, 0x23,0x25, 0x28, 0x2a, 0x2c, 0x2f, 0x31, 0x34, 0x36,0x39, 0x3b, 0x3e, 0x41, 0x43, 0x46, 0x49, 0x4c,0x4f, 0x52, 0x55, 0x58, 0x5a, 0x5d, 0x61, 0x64,0x67, 0x6a, 0x6d, 0x70, 0x73, 0x76, 0x79, 0x7c
  22. tempo:
  23. DB 25d, 50d, 75d, 100d
  24.  
  25. init:   MOV     #SFE(CSTACK), SP        ; set up stack
  26. main:
  27.         MOV.W   #WDTPW+WDTHOLD,&WDTCTL;  Stop watchdog timer
  28.        
  29.         MOV.W   #1000,&TACCR0;  Period for up mode
  30.         MOV.W   #CCIE,&TACCTL1;  Enable interrupts on Compare 0
  31.  
  32.         ; Set up Timer A. Up mode, divide clock by 8, clock from SMCLK, clear TAR
  33.         MOV.W   #MC_1|ID_3|TASSEL_2|TACLR,&TACTL; MOV.B   #11, P1IE                ; zezwolenie na przerwanie z pinu P1.3 oraz P1.0 i P1.1
  34.         MOV.B   #11, P1IES               ; ustaw zbocze opadajace wyzwalajace przerwanie na P1.3 oraz P1.0 i P1.1
  35.         BIC.B   #11, P1IFG               ; Skasuj flage przerwania od P1.3 oraz P1.0 i P1.1
  36.        
  37.         MOV.B   #0x00, &P4DIR;  P4 - input
  38.         BIS.B   #0xFF ,&P2DIR;  P2 - output
  39.         MOV.B   #0x00, &P1DIR;  P1 - input
  40.  
  41.         MOV     #0, R4
  42.         MOV.W   #255, R6               ; R6 - upper bound
  43.         MOV.W   #-255, R7              ; R7 - lower bound
  44.        
  45.         BIS.W   #GIE,SR                   ; Enable interrupts (just TACCR0)
  46.         JMP $                           ; jump to current location '$'
  47.                                         ; (endless loop)
  48.  
  49. TIMER_A1_Interrupt:  
  50.         INC     R4
  51.         CMP     #256, R4
  52.         JNE     set_value
  53.         MOV     #0, R4
  54. set_value:
  55.         MOV.W   #sine_table, R5
  56.         ADD     R4, R5
  57.         MOV.B   @R5, R8                 ; R8 = sin(x)
  58.        
  59.         CMP     R8, R6                  ; sin(x) >= upper_bound ?
  60.         JGE     print_upper_bound
  61.        
  62.         CMP     R8, R7                  ; sin(x) < lower_bound ?
  63.         JL      print_lower_bound
  64.        
  65.         JMP     print_sine
  66.        
  67. print_upper_bound:
  68.         MOV.B   R6, P2OUT
  69.         JMP     TIMER_A1_Interrupt_end
  70. print_lower_bound:
  71.         MOV.B   R7, P2OUT
  72.         JMP     TIMER_A1_Interrupt_end
  73. print_sine:
  74.         MOV.B   R8, P2OUT
  75. TIMER_A1_Interrupt_end:
  76.         MOV.W   #1000,&TACCR0; BIC.W   #1, &TACCTL1; RETI
  77.  
  78.  
  79. PORT1_isr:
  80.         BIT.B     #1, P4IN
  81.         JZ      divisor0
  82.        
  83.         BIT.B     #2, P4IN
  84.         JZ      divisor1
  85.        
  86.         BIT.B     #4, P4IN
  87.         JZ      divisor2
  88.        
  89.         BIT.B   #8, P4IN
  90.         JZ      divisor3
  91.        
  92.         BIT.B   #2, P1IN
  93.         JZ      upper_bound_inc
  94.        
  95.         BIT.B   #1, P1IN
  96.         JZ      upper_bound_dec
  97.        
  98.         JMP     P1_Reti
  99. divisor0:
  100.         MOV.W   #MC_1|ID_0|TASSEL_2|TACLR,&TACTL; JMP     P1_Reti
  101. divisor1:
  102.         MOV.W   #MC_1|ID_1|TASSEL_2|TACLR,&TACTL; JMP     P1_Reti
  103. divisor2:
  104.         MOV.W   #MC_1|ID_2|TASSEL_2|TACLR,&TACTL; JMP     P1_Reti
  105. divisor3:
  106.         MOV.W   #MC_1|ID_3|TASSEL_2|TACLR,&TACTL; JMP     P1_Reti
  107.        
  108. upper_bound_inc:
  109.         CMP     #0xFF, R6
  110.         JEQ     P1_Reti
  111.         INC     R6
  112.         DEC     R7
  113.         JMP     P1_Reti
  114. upper_bound_dec:
  115.         CMP     #0, R6
  116.         JEQ      P1_Reti
  117.         DEC     R6
  118.         INC     R7
  119. P1_Reti:
  120.         BIC.B   #11, P1IFG      ; reset all P1 pins interrupts
  121.         RETI
  122.        
  123.         END
  124.