forked from jfalkinburg/ECE382
-
Notifications
You must be signed in to change notification settings - Fork 1
/
badlec5.asm
82 lines (66 loc) · 3.05 KB
/
badlec5.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;-------------------------------------------------------------------------------
; Name: Capt Jeff Falkinburg
; Term: Fall 2016
; MCU: MSP430G2553
; Lecture: 5
; Date: 25 August 2016
; Note: CCS exercise - this file has errors
;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; BOILERPLATE Include device header file
;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
.text ; BOILERPLATE Assemble into program memory
.retain ; BOILERPLATE Override ELF conditional linking and retain current section
.retainrefs ; BOILERPLATE Retain any sections that have references to current section
.global main ; BOILERPLATE Project -> Properties and select the following in the pop-up
; Build -> Linker -> Advanced -> Symbol Management
; enter main into the Specify program entry point... text box
;-------------------------------------------------------------------------------
; main
;-------------------------------------------------------------------------------
main:
RESET mov.w #__STACK_END,SP ; BOILERPLATE Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; BOILERPLATE Stop watchdog timer
call #initMSP
mov.w #0x20, &R5+ ; R5 is the duty cycle
pwmLoop:
mov.w #0x40, R4 ; initialize R4 with the period
bis.w #0x01, &P1OUT ; set P1 logic 1
pinHigh:
dec.w R4 ; decrement the counter
cmp.w R5, R4 ; until its less than
jge pinHigh ; the duty cycle
bis.w #0x01, &P1OUT ; set P1 logic 0
pinLo:
dec.w R4 ; decrement counter
cmp.w #0, R4 ; until its less than zero
jl pinLo ; portion of PWM cycle
bit.w #0x08, &P1IN ; check P1.3 - the button
jnz pwmLoop ; if button not pressed redo PWM
updatePWM:
bit.b #8, &P1IN ; bit 3 of P1IN being pressed?
jz updatePWM ; Yes, branch back and wait
add.w #0x04, R5 ; decrease the duty cycle
and.w #0x3F, R5 ; makre sure to clear any cout bits
jmp pwmLoop ; and do it again
;-------------------------------------------------------------------------------
; initMSP
; pin dir function
; P1.0 out red LED
; P1.3 in button
;-------------------------------------------------------------------------------
initMSP:
bis.b #8, &P1REN ; Pullup/Pulldown Resistor Enabled on P1.3
bis.b #8, &P1OUT ; Assert output to pull-ups pin P1.3
bis.b #1, &P1DIR ; Set P1.0 as output (red LED)
bic.b #1, &P1OUT ; Clear P1.1 - turn the LED off on start
ret
;-------------------------------------------------------------------------------
; System Initialization
;-------------------------------------------------------------------------------
.global __STACK_END ; BOILERPLATE
.sect .stack ; BOILERPLATE
.sect ".reset" ; BOILERPLATE MSP430 RESET Vector
.short main ; BOILERPLATE