|
|
View previous topic :: View next topic |
Author |
Message |
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
Puzzled printf |
Posted: Thu Jun 05, 2008 7:55 pm |
|
|
Hi everyone,
I am quite puzzled with my test file popping up errors that stdout is not defined. I am just trying to run a normal printf(). My code for this file is as follows:
Code: |
#include <18F4620.h>
#include <stdio.h>
void main()
{
printf("Hello Cruel World!");
} |
My other included header files in MPLab are 18F4620,ctype,stdio,stddef,stdio,stdlib,string
I'm left scratching my head as to why MPLab IDE is giving me the following error:
Code: | Error 132 "test.c" Line 12(28,29): STDOUT not defined (may be missing #USE RS232) :: |
[/code]
Do I need to include something like #use rs232....... code?
Much help is appreciated |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: Puzzled printf |
Posted: Thu Jun 05, 2008 8:03 pm |
|
|
kevin5k wrote: |
Do I need to include something like #use rs232....... code?
|
Yes. |
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
Re: Puzzled printf |
Posted: Thu Jun 05, 2008 8:09 pm |
|
|
RLScott wrote: | kevin5k wrote: |
Do I need to include something like #use rs232....... code?
|
Yes. |
Another stupid question.
why? Is it something in-built into the CCsc.exe file? |
|
|
Guest
|
|
Posted: Thu Jun 05, 2008 9:08 pm |
|
|
Yes, but you need to configure your RS232 port (which pins are used for input/output/baudrate).
Example:
#use rs232 (baud=9600, xmit=pin_B2,rcv=pin_B1)
defines baud rate @ 9600bps, output on B2 and input on B1. |
|
|
Guest
|
|
Posted: Thu Jun 05, 2008 11:17 pm |
|
|
Anonymous wrote: | Yes, but you need to configure your RS232 port (which pins are used for input/output/baudrate).
Example:
#use rs232 (baud=9600, xmit=pin_B2,rcv=pin_B1)
defines baud rate @ 9600bps, output on B2 and input on B1. |
Well but my code only involves a printf function (to be done locally) and there's no need to transmit anything.
Tks guys anyway for your response, it seems that that is the way the compiler prefers - have to stick to CCS compiler rules |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Jun 06, 2008 1:42 am |
|
|
LOL
When you say locally what are you refering to ?
Do you have an LCD display attached ?
How do you communicate with your display device (SPI, I2C, Serial, other) ?
If there is nothing connected that is capable of displaying an ASCII string then what is the point of having the printf in there ? |
|
|
Ttelmah Guest
|
|
Posted: Fri Jun 06, 2008 2:10 am |
|
|
Think about it for a moment.
In 'C' (the original K&R implementation), you were writing code that ran _inside_ an 'operating system'. This had basic operations being performed, for 'standard input' (the keyboard), and 'standard output'. There was also the idea that the output, could be redirected by the OS (pipe operations), so there was a 'standard error' output, that bypassed this.
Now, with CCS, you are writing code inside a chip, that has no such operating system. As such, _you_ have to provide the input and output code. CCS offers a 'default' way of doing this, where if a #USE_RS232 line is present, the last one defined, is treated as providing the standard IO. If you want instead to route to something else (you have a local LCD for example), then you have to write the output function for this (the default with the CCS LCD code, is 'lcd_putc'), and tell 'printf', to talk to _this_, rather than the 'stdio'. So:
printf(lcd_putc,"What you want to print");
The key point to understand, is that there is no 'OS' outside your code, to display stuff, or get stuff, and by some method or other, _you_ must provide the functions for this.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|