;-------------------------------------------------------------------------------
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;
;
;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file
;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
LookupNibble .macro Position
mov.w R4, R13
and.b #0x0f, R13
mov.b DisplayAsciiHexTable(R13), Position (R15)
.endm
;-------------------------------------------------------------------------------
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
.text ; program start
.global _main ; define entry point
_main:
NOP
mov.w #WDTPW+WDTHOLD,&WDTCTL ; stop watchdog timer
;Set the I/O port that controls the RED LED to an output.
; To do this set bit 0 in the P1DIR register. Leave all
; all other I/O lines as inputs
call #IOportsSetup
call #SetupADC
call #SetupTimer
Mainloop:
bis.w #0000000000000001b, ADC12CTL0
call #HalfSecondDelay
bic.w #0000000000000001b, ADC12CTL0
mov.w ADC12MEM0, R5 ;move values into register
mov.w ADC12MEM1, R6
mov.w ADC12MEM2, R9
bit.w #0x8000, R5 ;check if number is negative
jz AfterCheck1
xor.w #0xffff, R5 ;use two's complement to get positive value
add.w #1, R5 ;use two's complement to get positive value
AfterCheck1:
bit.w #0x8000, R6 ;check if number is negative
jz AfterCheck2
xor.w #0xffff, R6 ;use two's complement to get positive value
add.w #1, R6 ;use two's complement to get positive value
AfterCheck2:
bit.w #0x8000, R9 ;check if number is negative
jz AfterCheck3
xor.w #0xffff, R9 ;use two's complement to get positive value;-------------------------------------------------------------------------------
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;
;
;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file
;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
LookupNibble .macro Position
mov.w R4, R13
and.b #0x0f, R13
mov.b DisplayAsciiHexTable(R13), Position (R15)
.endm
;-------------------------------------------------------------------------------
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
.text ; program start
.global _main ; define entry point
_main:
NOP
mov.w #WDTPW+WDTHOLD,&WDTCTL ; stop watchdog timer
;Set the I/O port that controls the RED LED to an output.
; To do this set bit 0 in the P1DIR register. Leave all
; all other I/O lines as inputs
call #IOportsSetup
call #SetupADC
call #SetupTimer
Mainloop:
bis.w #0000000000000001b, ADC12CTL0
call #HalfSecondDelay
bic.w #0000000000000001b, ADC12CTL0
mov.w ADC12MEM0, R5 ;move values into register
mov.w ADC12MEM1, R6
mov.w ADC12MEM2, R9
bit.w #0x8000, R5 ;check if number is negative
jz AfterCheck1
xor.w #0xffff, R5 ;use two's complement to get positive value
add.w #1, R5 ;use two's complement to get positive value
AfterCheck1:
bit.w #0x8000, R6 ;check if number is negative
jz AfterCheck2
xor.w #0xffff, R6 ;use two's complement to get positive value
add.w #1, R6 ;use two's complement to get positive value
AfterCheck2:
bit.w #0x8000, R9 ;check if number is negative
jz AfterCheck3
xor.w #0xffff, R9 ;use two's complement to get positive value
add.w #1, R9 ;use two's complement to get positive value
AfterCheck3:
mov.w R5,&TA0CCR1
mov.w R6,&TA0CCR2
mov.w R9,&TA0CCR3
jmp Mainloop
NOP
SetupADC:
bic.w #0000000000000010b, ADC12CTL0
mov.w #0000111110010000b, ADC12CTL0
mov.w #0000001011100110b, ADC12CTL1
mov.w #0000000100101000b, ADC12CTL2
mov.b #00000000b, ADC12MCTL0
mov.b #00000001b, ADC12MCTL1
mov.b #00000010b, ADC12MCTL2
mov.b #10001010b, ADC12MCTL3
bis.w #0000000000000010b, ADC12CTL0
ret
IOportsSetup:
mov.b #00111100b,P1OUT
mov.b #00000000b,P1REN
mov.b #00111100b,P1DIR
mov.b #00011100b,P1SEL
ret
SetupTimer:
mov.w #0000001000010100b, &TA0CTL
mov.w #0000100011100000b, &TA0CCTL1
mov.w #0000100011100000b, &TA0CCTL2
mov.w #0000100011100000b, &TA0CCTL3
mov.w #0x0fff,&TA0CCR0
mov.w #0x000f,&TA0CCR1
mov.w #0x000f,&TA0CCR2
mov.w #0x000f,&TA0CCR3
ret
HalfSecondDelay:
mov #0x1,R12
OuterTimercountLoop:
mov #0xffff,R15
TimercountLoop:
nop
sub #1,R15
jnz TimercountLoop
sub #1,R12
jnz OuterTimercountLoop
ret
;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
add.w #1, R9 ; 2;s comp values
AfterCheck3:
mov.w R5,&TA0CCR1
mov.w R6,&TA0CCR2
mov.w R9,&TA0CCR3
jmp Mainloop
NOP
SetupADC:
bic.w #0000000000000010b, ADC12CTL0 ; ADC12_A Control Register 0 CONFIGURATIONS
mov.w #0000111110010000b, ADC12CTL0 ; ADC12_A Control Register 0 CONFIGURATIONS
mov.w #0000001011100110b, ADC12CTL1 ; ADC12_A Control Register 1 CONFIGURATIONS
mov.w #0000000100101000b, ADC12CTL2 ; ADC12_A Control Register 2 CONFIGURATIONS
mov.b #00000000b, ADC12MCTL0 ; Conversion Memory Control Register 0
mov.b #00000001b, ADC12MCTL1 ; Conversion Memory Control Register 1
mov.b #00000010b, ADC12MCTL2 ; Conversion Memory Control Register 2
mov.b #10001010b, ADC12MCTL3 ; Conversion Memory Control Register 3
bis.w #0000000000000010b, ADC12CTL0 ;ADC12_A Control Register 2 CONFIGURATIONS
ret
IOportsSetup:
mov.b #00111100b,P1OUT ;setup p1
mov.b #00000000b,P1REN ;setup pull up pull down
nop
nop
mov.b #00111100b,P1DIR ;set up data dir
mov.b #00011100b,P1SEL ;set up chip select
ret
SetupTimer:
mov.w #0000001000010100b, &TA0CTL ;TA ctrl0 configurations
mov.w #0000100011100000b, &TA0CCTL1 ;;TA ctrl 1 configurations
nop
mov.w #0000100011100000b, &TA0CCTL2 ;TA ctr2 configurations
nop
mov.w #0000100011100000b, &TA0CCTL3 ;TA ctrl3 configurations
nop
mov.w #0x0fff,&TA0CCR0 ; Timer_A0 CCR0 capture input
mov.w #0x000f,&TA0CCR1 ; Timer_A0 CCR1 capture input
mov.w #0x000f,&TA0CCR2 ;Timer_A0 CCR2 capture input
mov.w #0x000f,&TA0CCR3 ;Timer_A0 CCR3 capture input
ret
HalfSecondDelay:
mov #0x1,R12 ; HALF SECONED ROTUNE
OuterTimercountLoop:
mov #0xffff,R15
TimercountLoop:
nop
sub #1,R15
jnz TimercountLoop
sub #1,R12
jnz OuterTimercountLoop
ret
;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET