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
ce5af639
authored
Mar 26, 2019
by
vielex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final version of MeasurementOfDistance.c
parent
65bcb57a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
9 deletions
Labware/Lab14_MeasurementOfDistance/MeasurementOfDistance.c
Labware/Lab14_MeasurementOfDistance/MeasurementOfDistance.c
View file @
ce5af639
...
...
@@ -50,16 +50,40 @@ unsigned long Flag; // 1 means valid Distance, 0 means Distance is empty
// Input: sample 12-bit ADC sample
// Output: 32-bit distance (resolution 0.001cm)
unsigned
long
Convert
(
unsigned
long
sample
){
return
0
;
// replace this line with real code
return
(
2
*
1000
*
sample
)
/
4095
.
0
;
// replace this line with real code
}
// Initialize SysTick interrupts to trigger at 40 Hz, 25 ms
void
SysTick_Init
(
unsigned
long
period
){
NVIC_ST_CTRL_R
=
0
;
NVIC_ST_RELOAD_R
=
period
;
NVIC_ST_CURRENT_R
=
0
;
NVIC_SYS_PRI3_R
=
(
NVIC_SYS_PRI3_R
&
0x00FFFFFF
)
|
0x40000000
;
NVIC_ST_CTRL_R
=
0x00000007
;
}
unsigned
long
PF1_Configure
(
void
){
unsigned
long
volatile
delay
;
SYSCTL_RCGC2_R
|=
0x00000020
;
// activate port A
delay
=
SYSCTL_RCGC2_R
;
//
GPIO_PORTF_AMSEL_R
&=
~
0x02
;
// no analog
GPIO_PORTF_PCTL_R
&=
~
0x00000F0
;
// regular function
GPIO_PORTF_DIR_R
|=
0x02
;
// make PA2 out
GPIO_PORTF_PDR_R
|=
0x02
;
// make PA2 out
GPIO_PORTF_DR8R_R
|=
0x02
;
// can drive up to 8mA out
GPIO_PORTF_AFSEL_R
&=
~
0x02
;
// disable alt funct on PA5
GPIO_PORTF_DEN_R
|=
0x02
;
// enable digital I/O on PA5
return
0
;
}
// executes every 25 ms, collects a sample, converts and stores in mailbox
void
SysTick_Handler
(
void
){
//GPIO_PORTF_DATA_R ^= 0x02;
ADCdata
=
ADC0_In
();
Distance
=
Convert
(
ADCdata
);
Flag
=
1
;
//GPIO_PORTF_DATA_R ^= 0x02;
}
//-----------------------UART_ConvertDistance-----------------------
...
...
@@ -74,8 +98,24 @@ void SysTick_Handler(void){
// 2210 to "2.210 cm"
//10000 to "*.*** cm" any value larger than 9999 converted to "*.*** cm"
void
UART_ConvertDistance
(
unsigned
long
n
){
// as part of Lab 11 you implemented this function
// as part of Lab 11 you implemented this function
if
(
n
<
10000
)
{
String
[
0
]
=
n
/
1000
+
0x30
;
String
[
1
]
=
'.'
;
String
[
2
]
=
(
n
/
100
)
%
10
+
0x30
;
String
[
3
]
=
(
n
/
10
)
%
10
+
0x30
;
String
[
4
]
=
n
%
10
+
0x30
;
}
else
{
String
[
0
]
=
'*'
;
String
[
1
]
=
'.'
;
String
[
2
]
=
'*'
;
String
[
3
]
=
'*'
;
String
[
4
]
=
'*'
;
}
String
[
5
]
=
' '
;
String
[
6
]
=
'c'
;
String
[
7
]
=
'm'
;
String
[
8
]
=
0
;
}
// main1 is a simple main program allowing you to debug the ADC interface
...
...
@@ -106,16 +146,28 @@ int main2(void){
int
main
(
void
){
volatile
unsigned
long
delay
;
TExaS_Init
(
ADC0_AIN1_PIN_PE2
,
SSI0_Real_Nokia5110_Scope
);
// initialize ADC0, channel 1, sequencer 3
// initialize Nokia5110 LCD (optional)
// initialize SysTick for 40 Hz interrupts
// initialize profiling on PF1 (optional)
// wait for clock to stabilize
// initialize ADC0, channel 1, sequencer 3
ADC0_Init
();
// initialize Nokia5110 LCD (optional)
Nokia5110_Init
();
// initialize SysTick for 40 Hz interrupts
SysTick_Init
(
1999999
);
// initialize profiling on PF1 (optional)
PF1_Configure
();
EnableInterrupts
();
// print a welcome message (optional)
Nokia5110_Clear
();
//Nokia5110_SetCursor(0, 0);
Nokia5110_OutString
((
unsigned
char
*
)
""
);
while
(
1
){
// read mailbox
// output to Nokia5110 LCD (optional)
if
(
Flag
)
{
UART_ConvertDistance
(
Distance
);
Nokia5110_SetCursor
(
0
,
0
);
Nokia5110_OutString
(
String
);
Flag
=
0
;
}
}
}
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