|
|
View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
Is possible use a variable in #Use rs232? |
Posted: Mon Jul 25, 2016 12:44 pm |
|
|
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
|
|
Posted: Mon Jul 25, 2016 2:03 pm |
|
|
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);
} |
|
|
|
|
|
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
|