CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Is possible use a variable in #Use rs232?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Is possible use a variable in #Use rs232?
PostPosted: Mon Jul 25, 2016 12:44 pm     Reply with quote

Hello all,

Someone can tell me if is possible to use a variable within #Use232, I need to change several times the value of TIMEOUT within my code....

Code:
#define  KEYHIT_DELAY   500
#include <18F4620.h>
#DEVICE ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, errors, TIMEOUT = KEYHIT_DELAY)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 25, 2016 2:03 pm     Reply with quote

You can't do it that way, because the Timeout value is hard-coded at
compile time. A delay loop is created in ASM code, and it loads constant
values based on your specified delay. It doesn't get the timeout delay
times from variables.

But you could do it by defining multiple streams. Give each stream a
different timeout. Then use fgetc() and specify the stream to get your
desired timeout. If you do it this way, you must also use fputc, fprintf, etc.
The cost of using multiple streams is a somewhat larger code size for your program.
Example:
Code:

#include <18F4620.h>
#DEVICE ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20MHz)
#use rs232(baud=9600, UART1, errors, TIMEOUT=500, stream=TO_500)
#use rs232(baud=9600, UART1, errors, TIMEOUT=255, stream=TO_255)
#use rs232(baud=9600, UART1, errors, TIMEOUT=10, stream=TO_10)

//=========================================   
void main(void)
{
char c;

c = fgetc(TO_500);

c = fgetc(TO_255);

c = fgetc(TO_10);


while(TRUE);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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