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 support@ccsinfo.com

Enabling and disabling #USE RS232 ...

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



Joined: 22 Sep 2003
Posts: 101
Location: Cape Town (South africa)

View user's profile Send private message Send e-mail Visit poster's website

Enabling and disabling #USE RS232 ...
PostPosted: Fri May 26, 2006 6:18 am     Reply with quote

I need to sense a non-uart pin. The data may be 19200 8N1 or it may be a completely different pulse train.

I can use #use RS232 to test the pin initially to see if the data is RS232 data, but...

How do I disable the #use RS232 if the data is found to be invalid?
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Fri May 26, 2006 7:24 am     Reply with quote

You can always disable/enable/reconfigure any feature of the PIC by writing the appropriate register bits directly. I often do this rather than depend on the idiosyncracies of the compiler. I find that I, and I assume others, sometimes forget that it is OK to not use the predefined functions.
Ttelmah
Guest







PostPosted: Fri May 26, 2006 7:27 am     Reply with quote

In order for RS232 I/O to take place (assuming this is a hardware UART), the TRIS register must be set to allow the UART to have control of the pin. The setting for this varies with different PICs. You can use a UART pin for something else, by simply changing this setting (this is very useful, where you want to use for example a hardware receive pin, but use the other UART pin for something else). Alternatively, you can turn the UART peripheral itself off, by just clearing the SPEN bit in the control register.

Best Wishes
hillcraft



Joined: 22 Sep 2003
Posts: 101
Location: Cape Town (South africa)

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri May 26, 2006 7:43 am     Reply with quote

Let me clarify the problem:

I have the following:
18F2550, running USB and RS232 via the standard UART.

I now have data coming in via pin B1. B1 is configured to interrupt on L_H. This information is used and then passed to the PC via USB.

There is a situation though, where the data coming in via B1 is perfect 19200 8N1. I would like to be able to switch to using the built in CCS rs232 code if this occurs.

The problem is really this:

if I have place #use RS232 (baud=19200, rcv=PIN_B1) in my code, how do I stop CCS from applying this routine, when I no longer want it to be used:

Pseudo Code:

Disable interrupt on B1
Set rs232 rec on B1
Read data for a while
Is this properly formatted data?
No
Disable rs232 rec on B1
Enable interrupt on B1
Use B1 interrupt received data as is.

I really need to be able to do the following

void Set_Rs232_B1_ON() {
#use RS232 (baud=19200, rcv=PIN_B1) ;
}

void Set_Rs232_B1_OFF() {
??
}
Ttelmah
Guest







PostPosted: Fri May 26, 2006 10:05 am     Reply with quote

If you are on 'B1', then you are using a 'soft' serial implementation. No hardware. As such, the serial code, is only used _when you call it_. You can perfectly well do any I/O you want on the pin, and the code will do nothing. If you want to perform serial input, set the pin as an input, and call the getc routine. You can do your own input functions on the pin at any time you want, and the RS232 code will not care at all.

Best Wishes
hillcraft



Joined: 22 Sep 2003
Posts: 101
Location: Cape Town (South africa)

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri May 26, 2006 1:38 pm     Reply with quote

Ah, of course.

I will try it in the morning.

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