| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				| Re: Problems with Printf |  
				|  Posted: Wed Feb 05, 2003 2:38 pm |   |  
				| 
 |  
				| <font face="Courier New" size=-1>:=I want to printf an int16 variable on rs232 :=
 -------------------------------------------------
 Chris,
 If you just want to print a 16 bit value with printf,
 you should do this:
 
 main()
 {
 int16 code;
 
 code = 0x55AA;
 
 printf("code = \%lx \n\r", code);
 
 
 while(1);  // Prevent PIC from going to sleep (Very important)
 
 // Extra notes on the "while(1);" line above:
 // CCS puts a hidden sleep instruction after the end of main().
 // The while(1) statement prevents the program from reaching
 // that instruction.  If it did reach that instruction, then
 // the last 2 characters of your printf statement (the "AA")
 // would not be displayed.  So it's very important to put
 // that statement above the end of main().
 
 }
 
 
 On your terminal window, you will see this:
 
 code = 55AA
 
 The number is displayed in hexadecimal notation.
 This is caused by using "lx", which means to display
 a 16-bit number in hex.  To display it in unsigned
 decimal format, use "lu" instead.</font>
 ___________________________
 This message was ported from CCS's old forum
 Original Post ID: 11311
 |  |