Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic16f877a+uart+max232+rs232

Status
Not open for further replies.

Cry87heart

New Member
i have problem about connect PIC16F877A with pc
when connect microcontroller to pc using serial port and max23
received zero
and when i send any char received zero too
hex works in proteus (send and receive)
and microcontroller works
and max232 works too
--hex--
Code:
void main()
{
USART_init(9600);
trisb=00000000;
portb=00000000;
while  (1)
          {
          portb.f0=1;
           if (usart_data_ready()==1)
              {

                 if(usart_read()=='1')
                {
                     usart_write('A');
                  }

              }
        }

 }
**broken link removed**

What causes this problem?
 
First of all, post your schematic.

Second of all, post your compiler version and name.

Thirdly, is that all of your code? If not post all of it, if it is, it will never work!

What causes the problem is not easy to tell at this stage, could be clock, could be caps, could be connections. What are the pins you are using / connecting on the serial connector (DB9 I assume?)
 
Thanks MS : Wilksey

This is the full code just to test
Schematic In simulation
**broken link removed**
**broken link removed**
JDM Programmer
**broken link removed**
**broken link removed**

Use MAX232
(MAXIM) MAX232EPE

I hope that the information is sufficient

Thanks for your interest
 
Hmm, doesn't really help with your hardware wiring! However, if that is all of the code you have then I am not surprised it wont work.

You must have at least some header files? And what compiler did you use?
 
Do you have an actual schematic or did you wire it up as per the proteus sim? What capacitors are you using for the MAXIM chip?

Internal or external crystal?
 
yes i have actual schematic

about max232 circuit obtained from the electronics shop
I tested it by connecting the rx to tx and found that what sent to the pic he was received in the pc

*use external crystal with pic 4Mhz
 
Last edited:
Can you post the actual schematic then?
Do you have a osilloscope to test the output of the PIC?

4 MHz should be sufficient.
 
This is the full code just to test
**broken link removed**
Use MAX232
(MAXIM) MAX232EPE

The above circuit looks unnecessarily complicated. Is the transistor even needed? What I did is that I followed this schema:

**broken link removed**

You have to put in every capacitors in each of their places with the exact values (well, my MAX232PE works with all 1uf electrolytic caps), or else it wont work. I'm guessing that's the reason why your rig didn't work outside Proteus.

Also, I'm not familiar with MikroC code(I'm using MPLAB with Hi-Tech C compiler), but nowhere in the code I see the clock frequency mentioned....are you sure that's the entire code?
 
The diagram is hideous! I have used 2 x 2n7000 to do level shifting without a MAX 232, eliminates the need for the caps, just a few limiting resistors, and yes the Max generally does use 1uF, I used to use the cheaper(about 1/3 of the price!) EXAR / SIPEX variant which worked on 0.1uF caps at 5v, and is pin compatible, but Proteus and other sim apps do a lot of work for you, so when you put it into the real world it doesn't work as expected, I worked with hardware before I used such applications so I know that ceratain components are needed and add them to the sim even though it will work perfectly well without it, it is generally good practice!
 
Talking of the diagram, you have the RTS line going directly into the pic, that can get up to +15V!
Nominally around 8V, still too high for it's +5V tolerance!
Transmit line for the PC is going into pin 1, so is the PIC supposed to be receiving the transmission? Pin 3 transmits out of the PC into the PIC.
This is MCLR, which I know you are using for programming, but piin 39 surely shouldn't be connected to RTS?! Nor would I imagine TX be connected to the MCLR pin.

Your circuit diagram doesn't show any level shift so we cant tell if you have wired it up correctly.
 
Last edited:
The diagram is hideous! I have used 2 x 2n7000 to do level shifting without a MAX 232, eliminates the need for the caps, just a few limiting resistors, and yes the Max generally does use 1uF, I used to use the cheaper(about 1/3 of the price!) EXAR / SIPEX variant which worked on 0.1uF caps at 5v, and is pin compatible, but Proteus and other sim apps do a lot of work for you, so when you put it into the real world it doesn't work as expected, I worked with hardware before I used such applications so I know that ceratain components are needed and add them to the sim even though it will work perfectly well without it, it is generally good practice!

I wasn't aware that you can pull off serial connection using transistors, although I do know there's nothing special about MAX232 except it only does level conversion and inversion. Besides, the OP said that he used MAX so I'm wondering why he's posting a different circuit that forgoes MAX.

For 16F877A, you only need to connect TX, RX and GND to the RS-232. That translates to PIN 24,25 and either one of the GND pins.
 
or 2,3 and 5 on a 9 way.
Yes you can use 2 2n7000 transistors to do level shifting, and a few resistors, done it a few times in the past, works good!

I think the diagram the OP posted is for his programming circuit.

Still bizarre!
 
I wasn't aware that you can pull off serial connection using transistors, although I do know there's nothing special about MAX232 except it only does level conversion and inversion. Besides, the OP said that he used MAX so I'm wondering why he's posting a different circuit that forgoes MAX.

For 16F877A, you only need to connect TX, RX and GND to the RS-232. That translates to PIN 24,25 and either one of the GND pins.
Did you mean that I can do without MAX232 with PIC16F877A ??????????
 
or 2,3 and 5 on a 9 way.
Yes you can use 2 2n7000 transistors to do level shifting, and a few resistors, done it a few times in the past, works good!

I think the diagram the OP posted is for his programming circuit.

Still bizarre!
Can you attach a diagram please
 
Did you mean that I can do without MAX232 with PIC16F877A ??????????

I've never, as yet personally, done USART without MAX232...but if the rest of the experts(read:Nigel and Wilksey) vouch for it, then I guess it's doable. So far I've used MAX and it works like a charm.

Speaking of diagrams, here's a simple one showing the connections between the PIC, MAX and RS. Someone look over this too; I might get something wrong.
 

Attachments

  • schematic.jpg
    schematic.jpg
    55.4 KB · Views: 588
Status
Not open for further replies.

Latest threads

Back
Top