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

Setting up RS-232 with variables from program

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



Joined: 20 Mar 2018
Posts: 21
Location: University of Antwerp

View user's profile Send private message Send e-mail

Setting up RS-232 with variables from program
PostPosted: Mon Jun 28, 2021 2:22 pm     Reply with quote

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

View user's profile Send private message

Re: Setting up RS-232 with variables from program
PostPosted: Mon Jun 28, 2021 5:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 28, 2021 8:16 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 28, 2021 11:57 pm     Reply with quote

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.
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