You are on page 1of 2

.cdecls C,LIST,"msp430x22x4.

h" ; Include device header file


;------------------------------------------------------------------------------.text
; Progam Start
.global _main
;------------------------------------------------------------------------------_main:
RESET:
mov.w #300h,SP
; Initialize stac pointer
mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
bis.b #0x01,&P1DIR
; P1.0 output
;------------------------------------------------------------------------------; Don't change the setup above this line unless you now what you are doing!
;------------------------------------------------------------------------------;
;

Change the number here to test your code


---- YOUR ASSEMBLY GOES HERE ----

mov.b #0x04,
mov.b #0x03,
s input, the rest are default
mov.b #0x04,
mov.b #0x04,
rd bit of P1
mov.b #0x04,
he critical transition is high-low
bis #0x08,
doItAgain:
waitLoop:

&P1OUT
&P1DIR

; everything starts off


; first two are outputs, third i

&P1REN
&P1IE

; protect against high voltages


; Enable interrupts from the thi

&P1IES

; The button is active low, so t

SR

; enable interrupts

; LED Toggle Loop


mov #0xFFFF, R12
dec R12
cmp #0 , R12
jne waitLoop
xor #0x02, &P1OUT
jmp doItAgain

; wait for a set time


; toggle green LED
; repeat forever

INTERRUPT:
mov.w #0, &P1IFG
push R12
push R13
mov #0x1000, R12

; We need a count variable


; we only need to wait a couple

milliseconds
interruptLoop:

dec R12
; wait for a set time
mov.w &P1IN, R13
and #0x4, R13
cmp #0x00, R13 ; test if the button is still set
jne exitInterrupt
; if it isn't, this was a false

alarm
cmp #0 , R12

; otherwise, wait until the loop

jl interruptLoop
xor #0x01, &P1OUT

; toggle red LED

exits

exitInterrupt:

pop R13
pop R12
reti

; return from interrupt


;------------------------------------------------------------------------------; Instructions that turn the red LED on/off
;------------------------------------------------------------------------------bic.b #0x01,&P1OUT
; turn off LED
bis.b #0x01,&P1OUT
; turn on LED
bic.b #0x01,&P1OUT
; turn off LED
forever:
jmp forever
; wait h
ere forever
;------------------------------------------------------------------------------;
Interrupt Vectors: don't change
;------------------------------------------------------------------------------.sect ".reset"
; MSP430 RESET Vector
.short RESET
;
.sect ".int02"
.short INTERRUPT
.end