|
|
View previous topic :: View next topic |
Author |
Message |
Dutch Guy
Joined: 20 Mar 2018 Posts: 21 Location: University of Antwerp
|
Setting up RS-232 with variables from program |
Posted: Mon Jun 28, 2021 2:22 pm |
|
|
PIC18F8722
CCSC 5.074
Greetings,
I need advice on how to setup a rs232 stream using variables from my program.
I have an initial
Code: | #use rs232(baud=MODBUS_SERIAL_BAUD, UART1, bits=8, stop=1, parity=E, stream=MODBUS_SERIAL, errors) |
with the needed defines to work.
Now in my program I have a setup struct that can set and hold baudrates and parity by using a button menu.
Redefining baudrate with #use rs232(baud=x) is provided but HOW do I redefine parity with an int?
Nowhere I can find defines for N,E,U or the string like "EVEN". I tried numbers 0,1,2 and ASCII values for N,E,U
Is it even possible?
Where do I find the code generated by #use RS232 where the parity is implemented? Maybe I can shuffle in a extern variable? _________________ I just can`t get it all in my head.... But wait, there is a new hole opening up.... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Setting up RS-232 with variables from program |
Posted: Mon Jun 28, 2021 5:41 pm |
|
|
Dutch Guy wrote: |
Where do I find the code generated by #use RS232 where the parity is implemented? |
Look under the #use rs232() statement in the .LST file. You will see
a loop that does XOR's. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9224 Location: Greensville,Ontario
|
|
Posted: Mon Jun 28, 2021 8:16 pm |
|
|
I would think a simple 'switch' function for 3 different 'use rs232(....)' should work ?
something like ...
switch (myparity) {
case(0):#use rs232(.....parity=none...);break;
case(1):#use rs232(....parity=odd...);break;
case(2):#use rs232(.....parity=even...);break;
}
...
where '0' means none,'1'=odd,'2'=even parity (easy for an dinosaur like me to remember...
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Mon Jun 28, 2021 11:57 pm |
|
|
You cannot use variables for streams.
Key to understand is that a stream actually generates different compiled
code.
However you can (of course), use a variable to select which stream is
actually used.
So for parity:
Code: |
#use rs232(baud=MODBUS_SERIAL_BAUD, UART1, bits=8, stop=1, parity=E, stream=MODBUS_EVEN, errors)
#use rs232(baud=MODBUS_SERIAL_BAUD, UART1, bits=8, stop=1, parity=O, stream=MODBUS_ODD, errors)
#use rs232(baud=MODBUS_SERIAL_BAUD, UART1, bits=8, stop=1, parity=N, stream=MODBUS_NONE, errors)
#define NONE 0
#define EVEN 2
#define ODD 1
byte Parity=NONE;
void my_putc(char chr)
{
switch(Parity)
{
case NONE:
putc(chr, MODBUS_NONE);
break;
case EVEN:
putc(chr, MODBUS_EVEN);
break;
case ODD:
putc(chr, MODBUS_ODD);
break;
}
}
char my_getc(void)
{
switch(Parity)
{
case NONE:
return getc(MODBUS_NONE));
break;
case EVEN:
return getc(MODBUS_EVEN);
break;
case ODD:
return getc(MODBUS_ODD);
break;
}
}
|
Then just use my_putc, and my_getc to put/get the characters, setting
the variable 'Parity' to the value required.
On baud rates, look at the example in the manual entry for
'set_uart_speed', which shows using two bits read from the input
port to change the baud rate. |
|
|
|
|
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
|