Help in USART Terminal, MikroC and Proteus

General discussion on mikroC PRO for PIC.
Author
Message
Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Help in USART Terminal, MikroC and Proteus

#1 Post by Eng_Bandar » 28 Aug 2010 05:56

Hello for all,

I want send data (letters or numbers) by USART Terminal tool in MikroC Pro

This is my code ( example from help file in MikroC Pro )

Code: Select all

char uart_rd;

void main() {
  ANSEL  = 0;                     // Configure AN pins as digital
  ANSELH = 0;

  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize

  UART1_Write_Text("Start");
  UART1_Write(10);
  UART1_Write(13);

  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {     // If data is received,
      uart_rd = UART1_Read();     // read the received data,
      UART1_Write(uart_rd);       // and send data via UART
    }
  }
}
and this is circuit

Image

I have two problems

1- If I send 'a' I should recieve 'a' but I recieve other letter (I sent 'a' I recieved 'y' :| ) Why ?

this is picture illustrate that


Image

2- In Proutes I do'nt see any thing in Virtual Terminal just black screen Why ?

Image

help please

zan
Posts: 434
Joined: 15 May 2007 19:35

Re: Help in USART Terminal, MikroC and Proteus

#2 Post by zan » 28 Aug 2010 07:14

You should work with Vurtual Terminal or Compim component. You can not use both of them like you did. Also, TX pin from PIC, need to be connected with RXD pin, and RX pin to TXD pin.

Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Re: Help in USART Terminal, MikroC and Proteus

#3 Post by Eng_Bandar » 28 Aug 2010 07:45

zan wrote:You should work with Vurtual Terminal or Compim component. You can not use both of them like you did. Also, TX pin from PIC, need to be connected with RXD pin, and RX pin to TXD pin.
Thank you zan for your reply

if I connnect TX pin from PIC to RXD not work (I don't no why?) I searched in web about this point I found most circuits like this I don't have interpret for this .

What do mean "You should work with Vurtual Terminal or Compim component" I used Virtual Terminal, about Compim component I don't know it and how can I use it ?

thank you zan again

zan
Posts: 434
Joined: 15 May 2007 19:35

Re: Help in USART Terminal, MikroC and Proteus

#4 Post by zan » 28 Aug 2010 09:31

Try this
Attachments
Test.zip
(42.5 KiB) Downloaded 2107 times

Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Re: Help in USART Terminal, MikroC and Proteus

#5 Post by Eng_Bandar » 28 Aug 2010 12:47

zan wrote:Try this

I tried it but nothing happened. Also How you want PIC send data without COM ? in your connection no sender and no reciever. This code says if you send 'a' or any data from PC to PIC, PIC will send same data from PIC to PC.

zan
Posts: 434
Joined: 15 May 2007 19:35

Re: Help in USART Terminal, MikroC and Proteus

#6 Post by zan » 28 Aug 2010 15:57

Eng_Bandar wrote:This code says if you send 'a' or any data from PC to PIC, PIC will send same data from PIC to PC.
Please, don't forget that you are working in Proteus, so if you send 'a' from virtual terminal to PIC, the PIC will return 'a' to virtual terminal.

Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Re: Help in USART Terminal, MikroC and Proteus

#7 Post by Eng_Bandar » 28 Aug 2010 17:45

zan wrote:
Eng_Bandar wrote:This code says if you send 'a' or any data from PC to PIC, PIC will send same data from PIC to PC.
Please, don't forget that you are working in Proteus, so if you send 'a' from virtual terminal to PIC, the PIC will return 'a' to virtual terminal.
I send data from USART Terminal in MikroC Pro to PIC (in Proteus through RS232) not from virtual terminal as you said. I use virtual terminal to see find sending operation or no in RS232. Can you tell me if I wrong or no ?

Thank you again.

MARIO
Posts: 978
Joined: 18 Aug 2008 22:13
Location: Brasil

Re: Help in USART Terminal, MikroC and Proteus

#8 Post by MARIO » 28 Aug 2010 18:17

Hi Eng_Bandar,

Except by these 2 lines (these registers do not exist in 16F877)

Code: Select all

ANSEL  = 0;                     // Configure AN pins as digital
ANSELH = 0;
your code is running Ok.
Use the Proteus circuit sent by zan, configure the PIC in Proteus to your .cof or .hex file, set the frequency and configuration bits.
When you run it you'll see the word "Start" in the virtual terminal.
When you type anything you'll see the answer, not what you are typing. Maybe this can cause confusion because response is immediate.
If you doubt that, delete the line from TX of the PIC to the RX of the terminal.
Another way to see that PIC is OK, put an oscilloscope and connect one channel to RX and the other channel to TX.
Besides that you can put a large time between reading your typing and PIC response. It will take that time to appear in terminal screen.

Code: Select all

    if (UART1_Data_Ready()) {     // If data is received,
      uart_rd = UART1_Read();     // read the received data,
      Delay_ms(300);   //add this line to delay, so you can see that what appears on terminal screen is the response of the PIC
      UART1_Write(uart_rd);       // and send data via UART
    }
I hope I could help you.

BR.

MARIO
Posts: 978
Joined: 18 Aug 2008 22:13
Location: Brasil

Re: Help in USART Terminal, MikroC and Proteus

#9 Post by MARIO » 28 Aug 2010 18:34

Eng_BandaR wrote:I send data from USART Terminal in MikroC Pro to PIC (in Proteus through RS232) not from virtual terminal as you said.
I think this is not possible unless you have another PC running the terminal connected to the COM port of the PC where your Proteus is running. With only one PC it will not work.
Maybe if you have 2 serial ports, one running Terminal and other Proteus and an appropriate physical cable connecting them. I'm not sure of this.

BR

zan
Posts: 434
Joined: 15 May 2007 19:35

Re: Help in USART Terminal, MikroC and Proteus

#10 Post by zan » 29 Aug 2010 08:25

MARIO wrote:Maybe if you have 2 serial ports, one running Terminal and other Proteus and an appropriate physical cable connecting them. I'm not sure of this.
This can also work if you have two virtual serial ports installed, one of them connected to PIC in Proteus and another connected to ME Usart Terminal.

I'm using this software for virtual serial ports.

MARIO
Posts: 978
Joined: 18 Aug 2008 22:13
Location: Brasil

Re: Help in USART Terminal, MikroC and Proteus

#11 Post by MARIO » 29 Aug 2010 23:12

@zan,

Thanks for your hint. It worked nice!

BR.

Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Re: Help in USART Terminal, MikroC and Proteus

#12 Post by Eng_Bandar » 30 Aug 2010 07:53

Thank you guys so much for your helping

@zan

I tried your circuit agian, it is work with me perfectly. My problem was that sending data from USART Terminal but now I tried to send data from Virtual Terminal from Proteus as you siad.

I forgot to tell you that I use Virtual Serial Port Driver as you said in last post. realy I am so sorry for this.

Now I want send data from USART Terminal Tool and its port is COM1 and other port is COM2 for RS232 in Proteus. I connected these ports by Virtual Serial Port Driver.
Also Virtual Serial Port Driver illustrate me find sending and recieving operations through these ports (COM1 & COM2).

following picture illustrates Virtual Serial Port Driver

Image

I hope my problem now clear for you.

Special thanks for zan and MARIO for your helping.

zan
Posts: 434
Joined: 15 May 2007 19:35

Re: Help in USART Terminal, MikroC and Proteus

#13 Post by zan » 30 Aug 2010 20:33

Well, that is different story :)

In Proteus, RX pin from PIC need to be connected to RXD pin on COMPIM component and TX pin from PIC to TXD pin on COMPIM. Next, doubleclick on COMPIM and set:

Physical Port = COM1 (your virtual port 1)
Physical Baud Rate = 9600
Virtual Baud Rate = 9600

There is no need to edit other settings, just click OK.
Now open Usart Terminal and select Com Port = COM2 (your virtual port 2), click Connect button.
Go to Proteus and click 'Play' button.

That's it

Image

Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Re: Help in USART Terminal, MikroC and Proteus

#14 Post by Eng_Bandar » 30 Aug 2010 21:34

@zan

Thank you so much. I can't describe my feeling for you.
Thank you zan again and agian and agian.

I don't put Virtual Baud Rate for RS232 9600 it was 4800, O my god for this mistake.

You gave me hope to complete my project.

Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Re: Help in USART Terminal, MikroC and Proteus

#15 Post by Eng_Bandar » 14 Sep 2010 11:19

Hi zan,

Did you write your code by MikroC or MikroC Pro?
I wrote it by MikroC Pro find problem.

your code work. But in MikroC Pro not work .

Post Reply

Return to “mikroC PRO for PIC General”