MSP430/Backlight project
From Teknologisk videncenter
The following code works but need to be documented properly.
; Purpose....: Variable backlight connected to MSP430G2553
; P1.6 (Green led on LaunchPad)
; Ver/Date/by: V1.0 / Date 15. mar 2014 / heth@mercantec.dk
; Principle..: Continouous variable PWM signal sent to led. Brightness can be
; adjusted by attaching a potentiometer to P1.1 variable from VCC
; to GND
; TimerA_0 repeatedly counts from 0 to TACCR0 which is set to 1023
; ADC10 gets triggeded from TimerA_0 each time it reaches 1023
; ADC10 Data Transfer module transfers the converted analog value
; from P1.1 to TimerA_0 TACCR1.
; When TimerA_0 counts from 0 and reaches the value in TACCR1 it
; sets the TACCR1 OUT which is connected to P1.6 and counts to
; 1023 and resets TACCR1 out.
; Caveats....: Needs to be commented in more detail!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV10SCR1
;;;;;RAM setup
RAMSTART EQU 0x0200 ; RAM start
RAMSIZE EQU 512 ; Size of RAM in bytes
;;;;;PORT 1 - Special Function Registers
;;;;;See controllers user guide. P1 and P2 for alternte functions
P1REN EQU 0x0027 ; Resistor enable
P1SEL2 EQU 0x0041 ; Port select 2
P1SEL EQU 0x0026 ; Port select
P1IE EQU 0x0025 ; Interrupt enable
P1IES EQU 0x0024 ; Interrupt edge select
P1IFG EQU 0x0023 ; Interrupt flag
P1DIR EQU 0x0022 ; Direction (0=in, 1 = OUT)
P1OUT EQU 0x0021 ; As output
P1IN EQU 0x0020 ; As input
;;;;;TimerA_0 SFR
TACTL EQU 0x0160 ; Timer A Control
TAR EQU 0x0170 ; Timer A counter
TACCTL0 EQU 0x0162 ; Timer A Capture/Compare control0
TACCR0 EQU 0x0172 ; Timer A capture/compare 0
TACCTL1 EQU 0x0164 ; Timer A Capture/Compare control0
TACCR1 EQU 0x0174 ; Timer A capture/compare 0
;;;;;ADC10 SFR
ADC10AE0 EQU 0x004A
ADC10AE1 EQU 0x004B
ADC10CTL0 EQU 0x01b0
ADC10CTL1 EQU 0x01b2
ADC10MEM EQU 0x01b4
ADC10SA EQU 0X01BC
ADC10DTC0 EQU 0x0048
ADC10DTC1 EQU 0x0049
;;;;; WATCH DOG TIMER - Special Function Registers
WDTCTL EQU 0x0120 ; Watch dog timer
;;;;WATCH DOG TIMER REGISTER VALUES
WDTPW EQU 0x5A00 ; Watch Dog Timer Password (5A)
WDTHOLD EQU 0x0080 ; Hold timer. Timer stopped
ORG 0xC000 ; Where to place code in FLASH
;Startup code
Reset: MOV.W #WDTPW|WDTHOLD, &WDTCTL ; Stop Watch Dog Timer
MOV.W #(RAMSTART + RAMSIZE), R1 ; Set stack Pointer to top of RAM
CALL #TIMAINIT
CALL #ADC10INIT
Loop: jmp Loop ; Your application here !!!
;;;;;Initialize Timer A
TIMAINIT: MOV.W #1000, &TACCR0
MOV.W #011010001000000b, &TACCTL0
MOV.W #0000001011010000b, &TACTL ; Side 370 i family /1
MOV.W #011010001000000b, &TACCTL1
MOV.W #0x0010, &TAR
BIS.B #01000000b, &P1DIR ; Side 49 i data sheet
BIS.B #01000000b, &P1SEL
BIC.B #01000000b, &P1SEL2
RET
ADC10INIT: BIS.W #0x10, &ADC10CTL0
MOV.W #0001100001110000b, &ADC10CTL0
MOV.W #0001100000100000b, &ADC10CTL1
MOV.B #0x2,&ADC10AE0
MOV.B #00000100b, &ADC10DTC0
MOV.B #1, &ADC10DTC1
MOV.W #ADC10SA, R6
MOV.W #TACCR1, 0(R6)
BIS.W #0x04, ADC10CTL1
BIS.W #0x02, &ADC10CTL0 ; ENC on (Enable Conversion)
RET
;Reset Vector. When CPU resets it loads the 16 bit defined in address 0xFFFE
;to the CPU PC (Program Counter = R0) and starts executing code from that address
ORG 0xFFFE
DW Reset
END