View previous topic :: View next topic |
Author |
Message |
Miniman
Joined: 30 Apr 2007 Posts: 44
|
#define, how? |
Posted: Sun Dec 02, 2007 8:59 am |
|
|
Hi
I'm using usb_cdc.h and I do not want to write printf(usb_cdc_putc,"something") every time i want to write to rs232 via USB. Is there a way to make a define so that I only need to write cdc_printf("Something")? Or is there another way? I have tried to make a define, but I don't know how to do..
/miniman |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 02, 2007 2:19 pm |
|
|
The following macro allows you to display a string by using the syntax
shown in your post.
Code: |
#define cdc_printf(x) printf(usb_cdc_putc, "%s", x)
//======================================
void main()
{
cdc_printf("Hello World\n\r");
while(1);
} |
|
|
|
Miniman
Joined: 30 Apr 2007 Posts: 44
|
|
Posted: Mon Dec 03, 2007 11:40 am |
|
|
Thank you.
But that willl only work for a string. Isn't there a way of doing it so that there are NO limitations, just lite the printf itself? I guess not.. I can not come up with any way of doing it.. Do you? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 03, 2007 1:36 pm |
|
|
Look in this CCS example file for another example:
Quote: | c:\Program Files\picc\Examples\Ex_Macro.c |
|
|
|
Storic
Joined: 03 Dec 2005 Posts: 182 Location: Australia SA
|
|
Posted: Mon Dec 03, 2007 2:05 pm |
|
|
why not do a function
maybe something like this, I have not tested however compiles
Code: | unsigned char myprint(char *pntchr) {
unsigned int8 cnt = 0;
while (pntchr[cnt]) {
putc(pntchr[cnt]);
cnt++;
}
}//~ |
_________________ What has been learnt if you make the same mistake? |
|
|
Miniman
Joined: 30 Apr 2007 Posts: 44
|
|
Posted: Tue Dec 04, 2007 9:34 am |
|
|
Quote: | why not do a function |
Simply because then I won't be able to use %-statements lite %u %X etc... |
|
|
|