Hardware Reference
In-Depth Information
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 “humidity
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; /* force compiler to use 32-bit to represent the product */
quo
5
temp/1023;
/* integer part of temperature */
rem
5
temp % 1023;
/* remainder part */
if (quo
55
100)
rem
5
0;
/* force highest humidity to 100% only */
fdigit
5
(rem * 10)/1023;
/* compute the fractional digit */
frem
5
(rem * 10) % 1023;
if (frem
.
511)
fdigit
11
;
if (fdigit
55
10) {
/* round off the fractional digit */
fdigit
5
0;
quo
11
;
}
ptr
5
&buf[0];
int2alpha(quo,ptr);
/* convert the integer part to ASCII string */
ptr
5
&buf[0];
while(*ptr)
/* find the end of the integer string */
ptr
11
;
*ptr
11
5
'.';
/* decimal point */
*ptr
11
5
fdigit
1
0x30;
/* fractional digit */
*ptr
11
5
'%';
*ptr
5
0;
/* terminate the humidity string */
cmd2lcd(0xC0);
/* move cursor to 2nd row */
puts2lcd(blanks);
/* clear the 2nd row */
cmd2lcd(0xC5);
/* set cursor to column 5 row 2 */
puts2lcd(&buf[0]);
/* output the humidity */
delayby100ms(2);
/* wait for 0.2 s */
}
}
void openAD0(void)
{
ATD0CTL2
5
0xE0;
/* enable AD0, fast ATD flag clear, power-down on wait */
ATD0CTL3
5
0x0A;
/* perform one ATD conversion */
ATD0CTL4
5
0x25;
/* prescaler set to 12, select four cycles sample time */
delayby10us(2);
}
▲
Search WWH ::
Custom Search