2001 Microchip Technology Inc. DS39024B-page 63
ANALOG.C Description7.4 ANALOG.C Source Code Listing
//****************************************************
//* ANALOG.C
//****************************************************
//* Rodger Richey
//* Principal Applications Engineer
//* Microchip Technology Incorporated
//****************************************************
//* 2 December 1998
//* Compiled using MPLAB C17 C Compiler V2.20
//****************************************************
//* This program performs an A/D conversion on CH2
//* and prints the result in ASCII to USART2 which
//* displays the result on the Monitor program.
//****************************************************
//* Uses an oscillator of 16MHz
//****************************************************
#include <p17c756.h>
#include <delays.h>
#include <usart16.h>
#include <stdlib.h>
#include <adc16.h>
void PutsUSART2(char *data);
// Prints a string to USART2 using hardware handshaking;
void PutsUSART2(char *data)
{
do
{
// Wait for the USART to finish prev operation
while(BusyUSART2());
// Wait for CTS
while(PORTBbits.RB4);
// Print character to USART2
putcUSART2(*data);
} while(*data++); // Increment pointer and check for NULL
return;
}
void main(void)
{
unsigned int result;
char str[7];
char crlf[3];
// Initialize the carriage return/linefeed string
crlf[0] = 0x0d;
crlf[1] = 0x0a;
crlf[2] = 0;
// Initialize USART2 and the hardware handshaking lines
PORTBbits.RB5 = 1;
DDRBbits.RB5 = 0;