Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
vielex
/
bes_labs_2019
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8d194d6c
authored
Mar 19, 2019
by
Víctor Elexpe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Posible solution
parent
42bdbe3f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
2 deletions
Labware/Lab12_TuningFork/TuningFork.c
Labware/Lab12_TuningFork/TuningFork.c
View file @
8d194d6c
...
...
@@ -42,14 +42,34 @@ void DisableInterrupts(void); // Disable interrupts
void
EnableInterrupts
(
void
);
// Enable interrupts
void
WaitForInterrupt
(
void
);
// low power mode
unsigned
long
flag
=
0
;
unsigned
long
temp
=
0
;
unsigned
long
lastState
=
0
;
// input from PA3, output from PA2, SysTick interrupts
void
Sound_Init
(
void
){
unsigned
long
delay
;
SYSCTL_RCGC2_R
|=
0x00000001
;
// activate port A
delay
=
SYSCTL_RCGC2_R
;
GPIO_PORTA_AMSEL_R
&=
~
0x20
;
// no analog
GPIO_PORTA_PCTL_R
&=
~
0x000F0000
;
// regular function
GPIO_PORTA_DIR_R
|=
0x20
;
// make PA5 out
GPIO_PORTA_DR8R_R
|=
0x20
;
// can drive up to 8mA out
GPIO_PORTA_AFSEL_R
&=
~
0x20
;
// disable alt funct on PA5
GPIO_PORTA_DEN_R
|=
0x20
;
// enable digital I/O on PA5
NVIC_ST_CTRL_R
=
0
;
// disable SysTick during setup
NVIC_ST_RELOAD_R
=
39999
;
// reload value for 500us (assuming 80MHz)
NVIC_ST_CURRENT_R
=
0
;
// any write to current clears it
NVIC_SYS_PRI3_R
=
NVIC_SYS_PRI3_R
&
0x00FFFFFF
;
// priority 0
NVIC_ST_CTRL_R
=
0x00000007
;
// enable with core clock and interrupts
EnableInterrupts
();
}
// called at 880 Hz
void
SysTick_Handler
(
void
){
if
(
flag
==
1
)
GPIO_PORTA_DATA_R
^=
0x04
;
else
GPIO_PORTA_DATA_R
&=
~
0x04
;
}
int
main
(
void
){
// activate grader and set system clock to 80 MHz
...
...
@@ -59,5 +79,11 @@ int main(void){// activate grader and set system clock to 80 MHz
while
(
1
){
// main program is free to perform other tasks
// do not use WaitForInterrupt() here, it may cause the TExaS to crash
temp
=
GPIO_PORTA_DATA_R
&
0x08
;
if
(
temp
==
0x08
&&
lastState
==
0x00
)
{
flag
^=
1
;
}
lastState
=
temp
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment