Hello, I want to ask a little bit help. I want to use the printf instruction with the Noice debugger. I can printf char or float fine but when I try to printf int or long I get a totally different numbers throu the serial port. eg. WORKS void main (void) { unsigned char f; for (f=0;f<=255;++f) printf( %bu \n",f); } but DOESN'T WORK void main (void) { unsigned int f; for (f=0;f<=255;++f) printf( %u \n",f); } Thanks for any advice Cheer George
I haven't used that fuction very often yet, but when I was using it, I have noticed, that you should be very accurate with the types of the arguments. It is always helpful to cast the parameter. In that example that doesn't work, you might want to try to cast f.
void main (void) { unsigned int f; for (f=0;f<=255;++f) printf( %u \n", (unsigned int)f ); }
Hello, Thanks for the answers. Of course I read the c51 manual and I know type have to match with variable. I gave two examples in my post and I think both of them have a correct match. I tried to write (integer) in the printf too but still wrong. I forgett to tell when I try that short programs with Dscope both of them work fine so I have to belive the problem is in the Noice remore debugger. Cheer George
Don't forget the <pre> and </pre> tags to make code posts legible:
void main (void) { unsigned char f; for (f=0; f<=255; ++f) printf( %bu \n", f); // Works }
void main (void) { unsigned int f; for (f=0; f<=255; ++f) printf( %u \n", f); // Doesn't Work }
Maybe there is a timing issue. Do these 2 statements work? printf( "%s \n", "x" ); printf( "%s \n", "xyz" );
Hello, Yes the opening quote is in the original program, I made a mistype. What happens when doesn't work?? It's interesting. let say variable is unsigned int c when c=3 it writes me to the screen eg. 832456 I'm going to check again and I'll write the correct answer. I tried the following program printf (" %bu %bu\n",c,c) and I get the high and the low byte of the unsigned int c on the screen. I found a new bug in my system. When I want to use the unsigned int od long in a for statement it count only for 32767. If I want to count more the processor locks and I have to reset. eg. unsigned int c for (c=0; c<= 32767, ++c) it works but for (c=0; c<= 33000, ++c) it doesn't work and the program falls an unfinished cycle as I suppose. Cheer George
I forgett.... No I use the c51 putchar throu the built in serial interface of the 8032. I use the Noice remote debugger and its terminal program. I tried some other terminal programs but the result was allways wrong.
View all questions in Keil forum