Mikroelektronika MIKROE-738 Datenbogen
652
mikoC PRO for PIC32
MikroElektronika
Library Example
This is a demonstration of the standard C library sprintf routine usage. Three different representations of the same
floating poing number obtained by using the sprintf routine are sent via UART.
Copy Code To Clipboard
double ww = -1.2587538e+1;
char buffer[15];
void main(){
UART1_Init(4800); // Initialize UART module at 4800 bps
Delay_ms(10);
UART1_Write_Text(“Floating point number representation”); // Write message on UART
sprintf(buffer, “%12e”, ww); // Format ww and store it to buffer
UART1_Write_Text(“rne format:”); // Write message on UART
UART1_Write_Text(buffer); // Write buffer on UART
sprintf(buffer, “%12f”, ww); // Format ww and store it to buffer
UART1_Write_Text(“rnf format:”); // Write message on UART
UART1_Write_Text(buffer); // Write buffer on UART
sprintf(buffer, “%12g”, ww); // Format ww and store it to buffer
UART1_Write_Text(“rng format:”); // Write message on UART
UART1_Write_Text(buffer); // Write buffer on UART
}