Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Interfacing of PIC18F4550 with RS232 (UART)

Status
Not open for further replies.

SAMO6

Newbie level 5
Joined
Nov 14, 2016
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
139
I am new to serial communication.I am trying to send a string(characters) on RS232 to hyperterminal software. I have tried simulation in proteus but, it is not working at all.
Can you tell me what corrections should I do in my code? What are the wrong things in my code?
Plz, Help.
I am using PIC18F4550 microcontroller, MPLAB X IDE, XC8 compiler, 20MHz Crystal Frequency.
Below is my code and screenshot of proteus simulation:

Code:
#include<p18F4550.h>

void delay()
{
    unsigned int i;
    for(i=0;i<=30000;i++);
}
void main(void)
{
  unsigned char data,i;
  unsigned char s[]={"Hello"};
  TRISCbits.RC6 = 0;                        //Configure TX pin set as output (RC6)
 
  SPBRG = 0X20;	           // Set Baud Rate (X value)
  TXSTA = 0b00100000;       //Asynchronous 8-bit; Transmit enabled; Low speed baud rate select
  RCSTA = 0b10010000;	// Enable Serial Port and continuous receive enable pin
            for(i=0;i<15;i++)
        {
         data=s[i];
         TXREG =data ;		// Data to be transmitted is loaded in TXREG register
          while(PIR1bits.TXIF == 0);             //Wait while transmit register is empty
          delay();
        }

}

RS232.JPG
 

I want to see Virtual Terminal window get opened when I start simulation in proteus. So, that I will be able to see data that I want to send to COM port in virtual terminal (In this case, I want to see "Hello" which I have assigned in my program.)
sorry, I got one correction that is, in 'for loop' I should use i<5 for "Hello" word.
I think I have assigned all register values well.

And, What is happening now is that virtual terminal window in proteus is not opening, So I am not being able to verify whether program/simulation is running correctly or not.

If you find any errors, Please tell me about solutions.
Please Help.
 

Hi,

it is not working at all
What does this mean?

* What do you expect? (describe as exact as you can)
* And what happens instead? (describe as exact as you can)

Klaus


Btw: C6 usually is connected to GND. You connected it to VCC. But this shouldn´t cause a problem.

- - - Updated - - -

Hi,

I´m not familiar with proteus...
I just had a view on other proteus schematics using the terminal ...
They connect the terminal to the TTL signals instead of RS232 signals.
And they leave RTS and CTS unconnected.

Klaus
 

It should work as far as I can see. C6 is OK connected to VCC but make sure you have the polarity correct, the positive side goes to the V+ pin.

The speed appears to be set to 9600 Bauds, is that what your virtual terminal is expecting. Also check the terminal program does not have hardware handshake enabled as you are not providing signals to control it.

Brian.
 
  • Like
Reactions: SAMO6

    SAMO6

    Points: 2
    Helpful Answer Positive Rating
Regardless of anything else, you don't have a main loop. When it is actually working, your code will run once and then the 'main' function will exit. What happens after that is (strictly speaking) "undefined" but is actually determined by the compiler you are using. Some will simply sit in an infinite loop doing nothing, and others will cause a device reset which will result in your code being executed again. Neither of these things is probably what you want.
Also please read Section 20.2.1 of the devices data sheet where it shows the exact sequence of instructions you need to enable the Tx side of the UART. Some Microchip UARTs can be funny beasts that must be initialised in the way that is documented, and this includes setting individual bits in the status registers in the correct order and not just writing to the various registers as a whole.
Also setting the BAUD rate is critical. While Brian has confirmed the BAUD rate register setting, can you please show us the config settings so that we can confirm that the oscillator is set up correctly.
Susan
 
  • Like
Reactions: SAMO6

    SAMO6

    Points: 2
    Helpful Answer Positive Rating
I want to see Virtual Terminal window get opened when I start simulation in proteus. So, that I will be able to see data that I want to send to COM port in virtual terminal (In this case, I want to see "Hello" which I have assigned in my program.)
sorry, I got one correction that is, in 'for loop' I should use i<5 for "Hello" word.
I think I have assigned all register values well.

And, What is happening now is that virtual terminal window in proteus is not opening, So I am not being able to verify whether program/simulation is running correctly or not.

If you find any errors, Please tell me about solutions.
Please Help.

Not seeing the terminal window opening in Proteus is a typical beginner problem, to see the open terminal window start the simulation click on debug on the menu and select virtual terminal at the bottom of the menu.
 
  • Like
Reactions: SAMO6

    SAMO6

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top