View previous topic :: View next topic |
Author |
Message |
Jent
Joined: 04 Feb 2012 Posts: 20
|
Error on "printf" by using int16 |
Posted: Wed Feb 15, 2012 10:06 am |
|
|
Hi.
I have a little problem I'm not able to solve on the coding. Hope the experts here can help me.
Below is my one part of coding:
Code: |
void main()
{
int16 heading;
while(true)
{
heading=(HMC6352_read_heading())/10;
lcd_init();
printf(lcd_putc, "\fHeading degree:");
printf(lcd_putc, "\n %1u\r", heading);
delay_ms(1000);
}
}
|
However, the problem exists on the "printf"----> Printf format type is invalid. But I really need to use 16bit, so i used int16. Anyone can help me please. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Feb 15, 2012 10:21 am |
|
|
If you press F11 when your project is open, the CCS onscreen Help files come up...locate the 'functions' and scroll down to printf..... it'll show you what you need to know...
I think you've mistyped the required format for an Int16.
lower case 'L's and 1s look very much the same depending on the font . |
|
|
Jent
Joined: 04 Feb 2012 Posts: 20
|
|
Posted: Wed Feb 15, 2012 10:57 am |
|
|
Thanks informing...i really mistyped with 1 but actually is l...
actually I followed the previous post message from this ccs forum, and also intend to try this testing..
actually i did not really understand regarding this part:
Code: |
printf(lcd_putc, "\n %lu\r", heading);
|
if %u is regarding to unsigned decimal integer, but for %lu, i really couldn't understand. I checked the ccs manual, but discovered nothing.. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Feb 15, 2012 1:03 pm |
|
|
Open CCS Help ( press F11) when project is open...
Goto Contents....
Open Data Definitions...
Open Basic Types.....
read what are the various types of data...
then
Goto Contents...
Open Built-in Functions...
Open All Built-in Functions...
Open printf()....
read.......
You should be able to see that an Unsigned INTeger is a value represented by 8 bits( a BYTE) of 0 to 255.
INT16 means a 16 bit integer( 2 bytes, a WORD in my world....).If Unsigned, 0 to 65535.
A Long Unsigned(Lu) can represent 0 to 65535, 16 bits of data, no negative numbers allowed. |
|
|
|