|
|
View previous topic :: View next topic |
Author |
Message |
SpaceXDebris
Joined: 15 Dec 2009 Posts: 3
|
How to check if RS232 Stream is defined |
Posted: Thu Mar 25, 2010 1:52 pm |
|
|
Hey there,
This is possible:
Code: |
#define FOO 1
#ifdef FOO
//Code
#endif
|
I'm trying to do the something similar with rs232 streams. Ideally:
Code: |
#use rs232(... STREAM=COM_A)
#use rs232(... STREAM=COM_B)
//Code
#ifdef COM_A
#ifdef COM_B
// Code that only compiles when two streams are defined
#endif
#endif
|
#ifdef obviously doesn't work in this case. Is there something similar I could do? It would be especially helpful if users of my lib wouldn't have to change their application code, so I'd like to not have to require them to #define other variables if they are using two streams, but I guess I could last resort.
Thanks as always for the help, and I apologize if this solution was posted elsewhere. I did a quick search and came up empty.
Chris |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 25, 2010 10:15 pm |
|
|
Quote: |
#ifdef obviously doesn't work in this case. Is there something similar I could do?
|
The #if defined() syntax works with vs. 4.105. It can detect if a stream
is defined or not. Use it instead of #ifdef. Example:
Code: |
#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=COM_A)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B2, ERRORS, stream=COM_B)
//======================================
void main()
{
int8 c;
#if defined(COM_A)
c = 0x55;
#else
c = 0xAA;
#endif
while(1);
}
|
|
|
|
|
|
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
|