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

runtime Parametric rs232 settings-read,write parametric port

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



Joined: 03 May 2006
Posts: 3

View user's profile Send private message

runtime Parametric rs232 settings-read,write parametric port
PostPosted: Wed May 03, 2006 1:19 pm     Reply with quote

Hello everybody,

I want to move from PicBasic language to CCS C language, to do this I have to solve before some ‘’minor’’ Very Happy problems.

1th existential problem)

I need to change the Rs232 configuration (e.g baudrate, parity) at run-time;
I mean (and for me it’s really hard to explain it in english Very Happy the Rs232 configuration port settings are saved in EEPROM (something like a SW configuration), during the execution of the program the setting values are read and used to set the Rs232 parameters.
In PicBasic language (you pardon to me) and the command more less this:

Var_port = 1 //1= PortA.0 2= PortA.1 etc
B_rate=9600
SERIN Var_port,B_rate,8,N,Var_input


2th existential problem)

I need also to read and set a parametric port;
In basic I use poke and peek command to read and write a generic pic port addressed by a variable during the program execution.
E.g.
Var_A= $7B // that’s means portA
Peek (Var_A, reade_val)

Does anyone could help a poor boy that want to move to C?

Thank you, really.
Alan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 03, 2006 1:41 pm     Reply with quote

1. Use the CCS library code for RS232 with "streams". Each stream
will be defined for different i/o pins. However, it's best to use
the hardware UART. A software UART will be created for streams
that don't use the hardware UART pins.
See the #use rs232() statement in the compiler manual.

2. Use the #byte directive to declare an i/o port as a variable.
Then write directly to it. Or, use the built-in CCS port i/o functions.
See the manual. Download it from this page:
http://www.ccsinfo.com/downloads.php
passstill



Joined: 03 May 2006
Posts: 3

View user's profile Send private message

Thank you but.....
PostPosted: Wed May 24, 2006 11:13 am     Reply with quote

About the point two it's ok.
But for the point one I think I need more information Very Happy
I understood that the mentioned "streams" are defined at compile time and it's not possible to change the configuration during the program execution.
I need something more complex, I would like to change the Rs232 configuration (E.g. Baud rate) at run-time.


Grazie
Alan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 24, 2006 11:50 am     Reply with quote

For a hardware UART, you can change the baud rate at run-time with
the set_uart_speed() function. Example:
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=HW_UART)

//============================   
void main()
{
fputc(0x55, HW_UART);

set_uart_speed(4800, HW_UART);

fputc(0xAA, HW_UART);

while(1);
}
passstill



Joined: 03 May 2006
Posts: 3

View user's profile Send private message

Ooops
PostPosted: Wed May 24, 2006 12:17 pm     Reply with quote

WOW this is what I mean a quick answer Very Happy
I'll try to stress you again..... Very Happy ....

Using a picbasic library for "Software Rs232", With 16F877 I make a board that receive a message from one of the four (SW)USART (Rs485, V23, Rs232(A), Rs232(B)) and resend it in one of the four (SW)USART (Rs485, V23, Rs232(A), Rs232(B)).

The user can change the configuration of the board (E.g. choosing baud rate, parity and so on) then reset it and use the board with the new configuration.
The problem now is to understand if it is possible to use CCS C RS232 library and use pins (and change at runtime the configuration) other then HW pins provided by Microchip HW USART.

Thank you again.
Alan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 24, 2006 1:11 pm     Reply with quote

I don't think you can do it with the CCS soft UART library code.

The parameters specified in each #use rs232() statement for a soft UART
are "hard coded" at compile-time. The soft UART library code does not
permit changing the parameters at run-time.

I think you will have to write your own soft UART code.
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