- #include "msp430.h" ; #define controlled include file
- NAME main ; module name
- PUBLIC main ; make the main label vissible
- ; outside this module
- ORG 0FFEAh
- DC16 TIMER_A1_Interrupt
- ORG 0FFE8h
- DC16 PORT1_isr ; set PORT1 Interrupt vector
- ORG 0FFFEh
- DC16 init ; set reset vector to 'init' label
- RSEG CSTACK ; pre-declaration of segment
- RSEG CODE ; place program in 'CODE' segment
- sine_table:
- 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
- tempo:
- DB 25d, 50d, 75d, 100d
- init: MOV #SFE(CSTACK), SP ; set up stack
- main:
- MOV.W #WDTPW+WDTHOLD,&WDTCTL; Stop watchdog timer
- MOV.W #1000,&TACCR0; Period for up mode
- MOV.W #CCIE,&TACCTL1; Enable interrupts on Compare 0
- ; Set up Timer A. Up mode, divide clock by 8, clock from SMCLK, clear TAR
- 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
- MOV.B #11, P1IES ; ustaw zbocze opadajace wyzwalajace przerwanie na P1.3 oraz P1.0 i P1.1
- BIC.B #11, P1IFG ; Skasuj flage przerwania od P1.3 oraz P1.0 i P1.1
- MOV.B #0x00, &P4DIR; P4 - input
- BIS.B #0xFF ,&P2DIR; P2 - output
- MOV.B #0x00, &P1DIR; P1 - input
- MOV #0, R4
- MOV.W #255, R6 ; R6 - upper bound
- MOV.W #-255, R7 ; R7 - lower bound
- BIS.W #GIE,SR ; Enable interrupts (just TACCR0)
- JMP $ ; jump to current location '$'
- ; (endless loop)
- TIMER_A1_Interrupt:
- INC R4
- CMP #256, R4
- JNE set_value
- MOV #0, R4
- set_value:
- MOV.W #sine_table, R5
- ADD R4, R5
- MOV.B @R5, R8 ; R8 = sin(x)
- CMP R8, R6 ; sin(x) >= upper_bound ?
- JGE print_upper_bound
- CMP R8, R7 ; sin(x) < lower_bound ?
- JL print_lower_bound
- JMP print_sine
- print_upper_bound:
- MOV.B R6, P2OUT
- JMP TIMER_A1_Interrupt_end
- print_lower_bound:
- MOV.B R7, P2OUT
- JMP TIMER_A1_Interrupt_end
- print_sine:
- MOV.B R8, P2OUT
- TIMER_A1_Interrupt_end:
- MOV.W #1000,&TACCR0; BIC.W #1, &TACCTL1; RETI
- PORT1_isr:
- BIT.B #1, P4IN
- JZ divisor0
- BIT.B #2, P4IN
- JZ divisor1
- BIT.B #4, P4IN
- JZ divisor2
- BIT.B #8, P4IN
- JZ divisor3
- BIT.B #2, P1IN
- JZ upper_bound_inc
- BIT.B #1, P1IN
- JZ upper_bound_dec
- JMP P1_Reti
- divisor0:
- MOV.W #MC_1|ID_0|TASSEL_2|TACLR,&TACTL; JMP P1_Reti
- divisor1:
- MOV.W #MC_1|ID_1|TASSEL_2|TACLR,&TACTL; JMP P1_Reti
- divisor2:
- MOV.W #MC_1|ID_2|TASSEL_2|TACLR,&TACTL; JMP P1_Reti
- divisor3:
- MOV.W #MC_1|ID_3|TASSEL_2|TACLR,&TACTL; JMP P1_Reti
- upper_bound_inc:
- CMP #0xFF, R6
- JEQ P1_Reti
- INC R6
- DEC R7
- JMP P1_Reti
- upper_bound_dec:
- CMP #0, R6
- JEQ P1_Reti
- DEC R6
- INC R7
- P1_Reti:
- BIC.B #11, P1IFG ; reset all P1 pins interrupts
- RETI
- END