We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am working with the C8051F580 MCU.
using my own hardware.
The board is connected to teraterm via UART0
8bits, 115200
I am trying to print a hex number, see very simple code below.
for some reason I always get two extra "zeros" added at the end.
#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdarg.h>#include <float.h>#include <stdlib.h>//#include <math.h> #include <c8051f58x.h>#include "C8051F580_defs.h"#include "compiler_defs.h"#include "PUTCHAR.c"
unsigned char i;
i = 0x12; printf("i = 0x%02Xh", i);
terminal shows:
i = 0x1200h <== two extra zeros, it does not matter if I add the (char) casting before "i" in the print expression.
Any suggestion will be appreciated
Thank you
Fausto Bartra
Do you really need printf? That function is a burden on an 8051. My recommendations would be to use the SiLabs debugger or just create a very simple function to convert a hex byte to ASCII.
Edit: I see you are also using floats. Again if this can be avoided using things like fractional equivalents (integers), then that would be worth considering. The SILabs 8051's are a marvel, but it's an odd choice for someone who expects to use printf() and floats.