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

RS232 and Bit/Byte Maping Questions

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



Joined: 14 Jul 2004
Posts: 11

View user's profile Send private message

RS232 and Bit/Byte Maping Questions
PostPosted: Wed Jul 14, 2004 1:54 pm     Reply with quote

Please excuse me if these are a newbie questions, matter of a fact, I am that to PIC and CCS, also excuse different topics, I just put all my questions rather than keep asking questions in different posts.

1) I understood from #Bit & #Byte that I can map a variable to an I/O pin (a bit of a port) and this will allow me to change the output to high/low just by making it = 0 or = 1 without having to use Output_High(PIN) or Output_Low(PIN), I am unable to do that unless my understanding it wrong about #bit or #Byte.

2) By testing, it seems the #int_RDA to interrupt when a byte received from RS232 only interrupt on hardware UART. How can we enable this for Software UART (which was setup using the #use rs232(….) and defining other pins than the HW one.

3) All RS232 related functions such as getc, printf and such can have a stream option, how can I use the kbhit() to test a specific stream for incoming byte, I couldn’t find a stream option in the manual for kbhit(). Note for questions 2 and 3, waiting forever using fgetc wouldn’t be possible as the PIC needs to do other stuff, so either an interrupt or a separate task, but I understand that CCS is not supported for PIC Salvo RTOS

4) I setup a MAX232CPE with the proper Caps to communicate with an RS232 device which uses RS232 Voltage Level. Its not a PC, I thought I would be able to use any I/O pins from the PIC side as I provided a MAX232 circuit for level conversion, however it only work with the HW Pins (PIN_C6,PIN_C7) and the device wont work correctly with any other pins, of course it wont work correctly with HW if I removed the MAX232 circuit.

Thanx for any help
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Jul 14, 2004 2:43 pm     Reply with quote

1) For port mapping look at the help file "Common questions and answers" under the topic "How does one map a variable to an I/O port?"

2) I don't think you can use interrupts at all with a software UART. Use polling with kbhit().

3) Pass the stream name as an argument.
if (kbhit(compass)) {...

4) With a software UART you should be able to use any "normal" I/O pins. Beware some pins have odd characteristics. It is useful to have a scope here, but if you run at a very slow baud rate (like 300 or 10) you can see a lot with a logic probe.
_________________
The search for better is endless. Instead simply find very good and get the job done.
RatherBeFlying



Joined: 14 Jul 2004
Posts: 11

View user's profile Send private message

PostPosted: Wed Jul 14, 2004 2:55 pm     Reply with quote

Thanx SherpaDoug for prompt reply

Reg. the manual and bit/byte map, that what i refered to when i said it was not working! it should work, but i have no idea why it is not. Simple example just like the manual, pin connected to LED (with resistor 1K), using Output_high/low, LED goes on and off, but using #bit for that pin number and = 1 and = 0, nothing happens!

Thanx for the tip about kbhit. I thought it should do that but i didnt actually try it as the manual did not show Kbhit(stream).

I agree about the scope, going to try to get a PC scope as those seems to be cheaper than a normal scope. I am using 9600 baud. Its a PIC16F876A with 20Mh Crystal, MAX232CPE with 5 x 1uF 100V, dont think the 100V rating for the Caps will do any harm compared to the 25V Caps normally used for MAX232.

Thanx again SherpaDoug
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Wed Jul 14, 2004 3:16 pm     Reply with quote

RatherBeFlying wrote:
, but using #bit for that pin number and = 1 and = 0, nothing happens!


As I understand the compiler, if you are going to be using #bit and #byte to map pins to variables, you must also be using "fast I/O" (#use fast_io(A) for example) and setting the pin direction with the appropriate bit in the set_tris_x command.

I'm not sure I understand you question about the Max232 chip. Are you saying that you cannot send and receive except with the hardware UART? I've done several projects with the F87x family where I have multiple RS232 ports. Never had a problem but it is important that you read the data sheet to confirm the pins you have selected don't have any gotchas. I believe it is A4 that is an open-drain output and so requires a pull-up resistor.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Wed Jul 14, 2004 3:17 pm     Reply with quote

Look at the standard and fast IO options.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Jul 14, 2004 3:20 pm     Reply with quote

Port mapping has always just worked for me. Double check you have the TRIS register set properly.

If you have an idea what you want look at scopes on EBAY. You should be able to get something that will do for under US$100. A TEK 453 is a scope no atom bomb can kill (fully transistorized!).
_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Wed Jul 14, 2004 3:32 pm     Reply with quote

I have to admit that the MAX232 issue sounds strange, yeah, pins used are I/O pins that do not have any secondary functions and are not open drain outputs. when using pins other than the HW UART, no results at all! not even wrong results. just dead lines. I think the scope would give more insight.

Will try the Fast_IO again, but i was more focused on the MAX232 issue that i didnt spend enough time debugging the BIT/Byte issue.

Thanx all for the replies.
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