Using RS232 to connect PIC16F876A to PIC16F877A

Forum for problems or queries regarding Flowcode Comms Components. Eg LIN, I2C, SPI, RS232, CAN, IrDA etc

Moderators: Benj, Mods

Post Reply
sptcarl
Flowcode V4 User
Posts: 36
Joined: Thu Feb 18, 2010 10:53 am
Has thanked: 3 times
Contact:

Using RS232 to connect PIC16F876A to PIC16F877A

Post by sptcarl »

I am looking for a bit of help with a project where I need to connect 2 circuit boards over a distance of around 3 metres. The remote board contains the PIC16F876 which controls a 3 digit LED display and 5 LED lamps.
Serial comms seems the easiest way of doing this, although it is a field of electronics that I know very little about.

I have connected the 2 circuits together with single core shielded cable, the transmit pin (25) from the F877 to the receive pin (18) of the F876. I have written a test program for the F877 that sends a byte at every timer interrupt, scaled at 1:2. This side of things works ok as I have tested it by connecting to my PC running Hyperterminal.

My question is, how do I get the F877 to look for the sent information? At the moment I have it set up to read the RS232 signal on every timer interrupt scaled at 1:1 however this doesn't work.

I have read that the later revision of Flowcode V3 has a built in RS232 interrupt function, but it doesn't seem to exist on mine.
Could someone please let me know what I am doing wrong?

Thanks, Carl.

sptcarl
Flowcode V4 User
Posts: 36
Joined: Thu Feb 18, 2010 10:53 am
Has thanked: 3 times
Contact:

Re: Using RS232 to connect PIC16F876A to PIC16F877A

Post by sptcarl »

I've changed the PICs to 16F886 and 16F887 now (as the recomended substitution for new designs by Microchip) Still I am no closer to getting them to communicate.
I'm guessing I need to make a custom interrupt for the RS232, but where do I start? I found one in the examples for a F88, but I'm assuming I need to modify it slightly?
I have also tried creating a loop that continuously reads the 232 macro, only exiting when the variable is not 255, that doesn't work either!

What little hair I've got left is rapidly being pulled out, has anyone got any ideas before I'm totally bald..?!

Please? :-)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Using RS232 to connect PIC16F876A to PIC16F877A

Post by Benj »

Hello,

Before you start with interrupts it should be quite easy to get the system up and running. This way you at least know that the system is working ok.

Firstly have you prooved that the chips are running and at the right speed. Have you created a 1 second LED flasher program to confirm that your chip is running at the right rate? Otherwise the Baud rate may not be correct.

Secondly have you connected the ground between the boards as well as the RX and TX signals? The ground is reuired for the transmissions to be detected correctly.

Thirdly if you are sending the signals through a noisy environment then you may need to use driver chips such as a MAX232 chip to boost the voltage and allow for the signals to travel further. To test this you could start by trying on a small cable and work your way up.

Finally if your still stuck then why not create a simple set of transmit and recieve programs and post them up on the forum. I will have a quick look and ensure your not doing anything out of the ordinary.

sptcarl
Flowcode V4 User
Posts: 36
Joined: Thu Feb 18, 2010 10:53 am
Has thanked: 3 times
Contact:

Re: Using RS232 to connect PIC16F876A to PIC16F877A

Post by sptcarl »

Hi Ben,
Thanks for the pointers. I checked everything that you mentioned but still no luck
I started again with the program laid out as it would be in real life and all is working as it should!
I think my test program was simply too simple and sending too much data, too fast.

I have also managed to transmit an integer to the display circuit, by splitting it up into two bytes then combining them again.

This has now thrown up another problem which I realise shouldn't be in this forum, but here goes...

How do I get this integer to display over 3 x 7 segment displays?

I'm not sure if this is the correct method of sending a 3 digit integer to the displays, but below is how I normally do it, and it works fine with values up to 255...

Calculation
Display_0 = Integer
Display_1 = Integer / 10
Display_2 = Integer / 100

Then the respective Display_* variable get written to the appropriate 7seg display macro.

So, say I need to display the Integer value 324, the actual display will show 320 because the 7seg display macro only works with Bytes.
What do I need to do to the Integer value so that the units value shows on the display?

I hope this makes sense!

Thanks in advance for any input.
Carl.

sptcarl
Flowcode V4 User
Posts: 36
Joined: Thu Feb 18, 2010 10:53 am
Has thanked: 3 times
Contact:

Re: Using RS232 to connect PIC16F876A to PIC16F877A

Post by sptcarl »

Scrap that last bit, I think Ive found it on another thread. :)

Post Reply