PRINTF( ) Statement
Formatted printing to standard output, usually the serial port

if i=0x12ab and j=0x5b, to get the following output...
"Hex = 12AB 5B[cr]"
"Hex = 12ab 5B[cr][lf]"
"Dec = 04779 091[cr]"
//Examples
PRINTF
("Hex = %4lX %2X\r",i,j);
PRINTF("Hex = %4lx %2X\r\n",i,j);
PRINTF("Dec = %5lu %3u\r",i,j);

//1.  'l' signifies a long (16 or 32 bit read "Not 8 bits") value,
//    if omitted, low 8 bits will be used
//2.  %nlu or %nu, n must be >= expected digits
Print a string with no formatted input data to standard output. PRINTF("Hi there!");
Print a formatted string to an array of characters.  The end of the string will be signified by the first character, 0x00. CHAR string[20];

SPRINTF(string,"%lu",1234);
Print a formatted string to a predefined function which accepts character data as input. VOID lcd_putc (CHAR datain){
}


PRINTF
(lcd_putc,"%lu",1234);

PUTC ( ), GETC ( ), PUTS( ) and GETS( ) Statements
Unformatted writing and reading on standard I/O
Unless a stream is specified, standard I/O is the LAST USED the serial port

For the stream examples, this is how CCS PICC specifies a port and assigns a stream name to it. #USE RS232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=pcport)
#USE RS232(baud=19200,parity=N,xmit=PIN_C5,rcv=PIN_C4,bits=8,stream=diagport)
Send a character to standard output. PUTC('x');
Same as above, but sends the character to a specified stream. FPUTC('x',pcport);
FPUTC('y',diagport);
Get acharacter from standard input. CHAR datain;

datain = GETC();
Same as above, but gets the character from a specified stream. CHAR datain1;
CHAR datain2;

datain1 = FGETC(pcport);
datain2 = FGETC(diagport);
Send a string to standard output.  PRINTF( ) is generally a better way to go as this will always append a [cr][lf] to the end of the data. PUTS("This is a test");
Same as above, but sends the data to a specified stream. FPUTS("This is a test",pcport);
FPUTS("This is a test",diagport);
Get a string from standard input and put it into a character array until a [cr], 0x0D, is encountered. CHAR string[20];
 
GETS
(string);
Same as above, but gets the data from a specified stream. CHAR string[20];
 
GETS
(string,pcport);
GETS(string,diagport);

GETC( ) and Interrupt Level Character Reception

When receiving RS232 data from a serial port, especially in a C coding environment, it is important to remember the context save and restore time of the interrupt.  If a new character is read while the first one is dealt with, allowing a new interrupt to handle the next character could eat significant time which may lead to data loss.  Check for new data before exiting... BYTE rx_buffer [64];
BYTE rx_start=0;
BYTE rx_end=0;

#INT_RDA
RDA_isr()
{

DO
    {
    if (
KBHIT())
        {
        rx_buffer[rx_start]=
GETC();
        rx_end=(rx_end+1) & 63;
        }
    }
WHILE(kbhit());
}
 

 

Formatting Characters
(Escape sequences)

Escape Hex Name
\\ 0x5C Back Slash
\' 0x60 Single Quote
\" 0x22 Double Quote
\? 0x3F Question Mark
\a 0x07 Alert / Bell
\b 0x08 Back Space
\f 0x0C Form Feed
\n 0x0A New Line
\r 0x0D Carriage Return
\t 0x09 Horizonatal Tab
\v 0x0B Vertical Tab
\n\r --- Terminal Return
\133 0x5B Insert Octal Character
\x7A 0x7A Insert Hex Character

Any questions or comments?
 This page last updated on August 28, 2011