-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.s
117 lines (102 loc) · 3.32 KB
/
main.s
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
;****************** main.s ***************
; Program written by: ***Your Names**update this***
; Date Created: 2/4/2017
; Last Modified: 1/17/2020
; Brief description of the program
; The LED toggles at 2 Hz and a varying duty-cycle
; Hardware connections (External: One button and one LED)
; PE1 is Button input (1 means pressed, 0 means not pressed)
; PE2 is LED output (1 activates external LED on protoboard)
; PF4 is builtin button SW1 on Launchpad (Internal)
; Negative Logic (0 means pressed, 1 means not pressed)
; Overall functionality of this system is to operate like this
; 1) Make PE2 an output and make PE1 and PF4 inputs.
; 2) The system starts with the the LED toggling at 2Hz,
; which is 2 times per second with a duty-cycle of 30%.
; Therefore, the LED is ON for 150ms and off for 350 ms.
; 3) When the button (PE1) is pressed-and-released increase
; the duty cycle by 20% (modulo 100%). Therefore for each
; press-and-release the duty cycle changes from 30% to 70% to 70%
; to 90% to 10% to 30% so on
; 4) Implement a "breathing LED" when SW1 (PF4) on the Launchpad is pressed:
; a) Be creative and play around with what "breathing" means.
; An example of "breathing" is most computers power LED in sleep mode
; (e.g., https://www.youtube.com/watch?v=ZT6siXyIjvQ).
; b) When (PF4) is released while in breathing mode, resume blinking at 2Hz.
; The duty cycle can either match the most recent duty-
; cycle or reset to 30%.
; TIP: debugging the breathing LED algorithm using the real board.
; PortE device registers
GPIO_PORTE_DATA_R EQU 0x400243FC
GPIO_PORTE_DIR_R EQU 0x40024400
GPIO_PORTE_AFSEL_R EQU 0x40024420
GPIO_PORTE_DEN_R EQU 0x4002451C
; PortF device registers
GPIO_PORTF_DATA_R EQU 0x400253FC
GPIO_PORTF_DIR_R EQU 0x40025400
GPIO_PORTF_AFSEL_R EQU 0x40025420
GPIO_PORTF_PUR_R EQU 0x40025510
GPIO_PORTF_DEN_R EQU 0x4002551C
GPIO_PORTF_LOCK_R EQU 0x40025520
GPIO_PORTF_CR_R EQU 0x40025524
GPIO_LOCK_KEY EQU 0x4C4F434B ; Unlocks the GPIO_CR register
SYSCTL_RCGCGPIO_R EQU 0x400FE608
CYCLE_TIME EQU 8000000
IMPORT TExaS_Init
THUMB
AREA DATA, ALIGN=2
;global variables go here
AREA |.text|, CODE, READONLY, ALIGN=2
THUMB
EXPORT Start
Start
; TExaS_Init sets bus clock at 80 MHz
BL TExaS_Init ; voltmeter, scope on PD3
; Initialization goes here
LDR R3, =SYSCTL_RCGCGPIO_R
LDR R4, [R3]
ORR R4, #3<<4
STR R4, [R3]
NOP
NOP
LDR R3, =GPIO_PORTE_DIR_R
LDR R4, [R3]
ORR R4, #4
BIC R4, #2
STR R4, [R3]
LDR R3, =GPIO_PORTE_DEN_R
LDR R4, [R3]
ORR R4, #3<<1
STR R4, [R3]
LDR R3, =GPIO_PORTF_DIR_R
LDR R4, [R3]
BIC R4, #1<<4
STR R4, [R3]
LDR R3, =GPIO_PORTF_DEN_R
LDR R4, [R3]
ORR R4, #3
STR R4, [R3]
CPSIE I ; TExaS voltmeter, scope runs on interrupts
loop
; main engine goes here
BL delay
LDR R3, =GPIO_PORTE_DATA_R
MOV R4, #4
STR R4, [R3]
BL delay
LDR R3, =GPIO_PORTE_DATA_R
MOV R4, #0
STR R4, [R3]
B loop
; R0 has delay
wait
SUBS R0, #1
CMP R0, #0
BGT wait
BX LR
; R0 has "on" time
run_cycle
LDR R3, =CYCLE_TIME
SUB R4, R0, R3
ALIGN ; make sure the end of this section is aligned
END ; end of file