 | Discussion Forum |  |
|
|
printf statement not giving the required string out.Next Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author arjun pal Posted 21-Nov-2002 08:07 GMT Toolset C51 |  printf statement not giving the required string out. arjun pal Hi All i want following string of bytes to be send by the CPU 80C51RD2 serial port:0xba,0x02,0x01,0xb9 statement:
printf("%c%c%c%c",stxi,select_lnth,select_cmd_char,select_bcc);
output:0xba,0x02,0x01
why 0xb9 is missing ?
i have tried a long cut method to overcome this
unsigned int loop;
unsigned char buf[4];
sprintf(buf,"%c%c%c%c",stxi,select_lnth,select_cmd_char,select_bcc);
for(loop=0;loop<=4;loop++)
printf("%c",buf[loop]);
Above for statement should have worked with condition "loop<=3",but again last byte was missing.By giving "loop<=4" i got all required bytes.
why "for loop" terminating condition have to be kept at " <=4 " ,when it should have worked with " <=3 " ?
Thanks in advance
| | Read-Only Author Stefan Duncanson Posted 21-Nov-2002 10:51 GMT Toolset C51 |  RE: printf statement not giving the required string out. Stefan Duncanson If you have select_bcc declared as an integer type rather than a char type you may well get this sort of result. | | Read-Only Author arjun pal Posted 22-Nov-2002 12:43 GMT Toolset C51 |  RE: printf statement not giving the required string out. arjun pal i have defined it as variable of type char | | Read-Only Author Jon Ward Posted 21-Nov-2002 13:26 GMT Toolset C51 |  RE: printf statement not giving the required string out. Jon Ward Are you waiting one character time after printf returns to be sure the character is transmitted?
The printf and putchar functions return before the last character is actually shifted out the serial port.
If you use the simulator and you set a breakpoint immediately after the printf function exits, the last character will not be sent out the serial port.
Jon | | Read-Only Author arjun pal Posted 22-Nov-2002 12:53 GMT Toolset C51 |  RE: printf statement not giving the required string out. arjun pal i was using simulator to see behaviour of routines and serial window 1 to see the o/p since routines where not behaving as desired,when loaded in the target. | |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|