Chapter 9 – Digital Meets Analog – ADC and DAC
0);
t, 10);
C
g is ");
C, and copy the Demonstrator and PC_Comm .c and .h
t. Change the Demonsrator.c by adding the following
ctions. Compile, load, and test.
nclude "Demonstrator.h"
USA
y to communicate.\r");
cally
he ADC demo.\r");
;
e value\r");
ADCresult = ADC_read();
intpart = ADCresult/50;
fractpart = ADCresult%50;
itoa(intpart, voltintpart, 1
itoa(fractpart, voltfractpar
// Send the voltage to the P
sendString("The readin
sendChar(voltintpart [0]);
sendChar('.');
sendChar(voltfractpart [0]);
sendString(" volts.\r");
}
The initializer and the parseInput functions:
Open a new directory, AD
files from the last projec
functions and the above fun
#i
i
nclude "PC_Comm.h"
void initializer()
{
// Calibrate the oscillator:
OSCCAL_calibration();
// Initialize the USART
RTinit();
ADC_init(1);
// say hello
sendString("\rPC_Comm.c read
// identify yourself specifi
ndString("You are talking to t se
// show commands
sendString("Commands:\r");
sendString("light - returns a light value\r");
sendString("temp - returns the temperature in fahrenheit\r")
sendString("volt - returns a voltag
}