Arizona Picdem 17 User Manual

Page of 92
 2001 Microchip Technology Inc.
DS39024B-page 59
USART.C
 Description
6.6
 
USART.C
 Source Code Listing
//****************************************************
//*   USART.C
//****************************************************
//*   Rodger Richey
//*   Principal Applications Engineer
//*   Microchip Technology Incorporated
//****************************************************
//*   2 December 1998
//*   Compiled using MPLAB C17 C Compiler V2.20
//****************************************************
//*   This program prints an incrementing count from
//*   0 to 255 to the USART. The numbers are displayed
//*   in the Monitor program.
//****************************************************
//*   Uses an oscillator of 16MHz
//****************************************************
#include <p17c756.h>
#include <delays.h>
#include <usart16.h>
#include <stdlib.h>
void PutsUSART2(char *data);
// Function to print a string to USART2 using handshaking
void PutsUSART2(char *data)
{
do
{
// Wait for USART to complete prev operation
while(BusyUSART2());
// Hardware handshaking for CTS
while(PORTBbits.RB4);
// Print a character to USART2
putcUSART2(*data);
} while(*data++);  // Increment pointer and check for NULL
return;
}
void main(void)
{
unsigned char i;
char str[5];
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;