Hardware Reference
In-Depth Information
5 V
HCS12
27 k Ω
10 k
Ω
R f
ASCX30AN
+12 V
10 k Ω
1.6 k Ω
V OUT
-
+12 V
R 1
-
741
5 V
V M
AN7
741
+
+
Offset adjust
3.9 k
Ω
R 2
- 12 V
- 12 V
5 V
Figure 12.22 Barometric pressure sensor output scaling and shifting circuit
The barometric pressure ranges from 948 to 1083.8 mbar. The A/D conversion result will
be 0 and 1023 for these two values. Therefore, the A/D conversion result needs to be divided by
7.53 in order to find the corresponding barometric pressure. The following equation shows the
conversion:
Barometric pressure 5 948 1 A/D result/7.53
948 1 (A/D result 3 100)/753
The C program that performs A/D conversion, translates the result into barometric pres-
sure, converts the barometric pressure into an ASCII string, and then displays the pressure on
the LCD is as follows:
#include
“c:\cwHCS12\include\hcs12.h”
#include
“c:\cwHCS12\include\delay.h”
// include delay.c in project
#include
“c:\cwHCS12\include\convert.h”
// include convert.c in project
#include
“c:\cwHCS12\include\lcd_util.h”
// include lcd_util.c in project
void openAD0(void);
char buf[12];
char *msg1 5 “pressure 5 ”;
char *blanks 5 “ ”;
void
main (void)
{
unsigned int quo,rem,frem;
long
temp;
char
*ptr,fdigit;
delayby100ms(2);
/* wait for LCD kit to self-initialize */
openlcd();
/* configure LCD kit */
openAD0();
/* configure AD0 module */
cmd2lcd(0x80);
/* set cursor to upper left corner */
puts2lcd(msg1);
/* output the message “pressure 5 ” */
while(1) {
ATD0CTL5 5 0x87;
/* start a conversion with result right-justified */
while(!(ATD0STAT0&SCF));
/* wait until conversion is done */
temp 5 (long)ATD0DR0 * 100;
quo 5 temp/753;
/* integer part of pressure */
 
Search WWH ::




Custom Search