Problem receive data RS232

General discussion on mikroC.
Post Reply
Author
Message
Fabiano
Posts: 29
Joined: 28 Apr 2010 21:07

Problem receive data RS232

#1 Post by Fabiano » 28 Apr 2010 21:28

Hi,

This program receives data through the serial port and the display shows.

receive data when the computer comes correct.

when I receive data from another microcontroller data are not correct.

I am using a PIC18F452

program that receives:

/*
cada caractere recebido pela serial,
sera enviado para o display LCD no formato ASCII.
velocidade de 2400 Bps
LCD trabalhando no modo 8 bits.
Usado o hyperterminal para transferência dos dados via RS232.
cristal: 8mhz
Compilador: mikroC
*/

void main(){
unsigned short rx; //espaço
char a = 0;
//conf serial
USART_init(2400); //inicializa serial com baudrate 2400 bps
delay_ms(100);
//conf LCD
trisd = 0; // conf portD como saída
portD= 0x00;
trise = 0; // conf portE como saída
adcon1 = 0x06; // conf todos pinos de A/D como I/O de uso geral
lcd8_config ( &porte, &portd,2,1,0,7,6,5,4,3,2,1,0); // conf e inicializa LCD
lcd8_cmd(lcd_clear); // apaga LCD

do {
if (Usart_Data_Ready()) { //chegou algum byte no buffer serial
rx= Usart_read(); // le caracter
Usart_Write(rx); //ecoa no hiperterminal
a++;
Lcd8_Chr(1,a,rx); //mostra caracter no LCD
}

} while(1);
}

Deepak
Posts: 55
Joined: 08 Jan 2009 06:00
Location: India

Re: Problem receive data RS232

#2 Post by Deepak » 29 Apr 2010 07:17

Hi Fabiano,

Check the Baud Rate settings on both the controllers. I observe you are running at 2400 but it is usually 9600.

Regards.

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: Problem receive data RS232

#3 Post by tihomir.losic » 29 Apr 2010 08:51

Hello,

first of all, I want to suggest you to download our PRO version of mikroC.
mikroC PRO for PIC: http://www.mikroe.com/download/c_pic_pro.php

mikroC PRO for PIC 2009 includes a set of libraries and examples intended to facilitate application development.
Routines are documented in detail and allow quick start in programming microcontrollers; browse through the supplied
examples and learn how to utilize PIC with minimum of code and effort.

Also, you can look for detailed explanation about UART and LCD library on following links:
- UART library
- LCD library

For any further assistance, feel free to contact us.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

Fabiano
Posts: 29
Joined: 28 Apr 2010 21:07

Re: Problem receive data RS232

#4 Post by Fabiano » 29 Apr 2010 19:40

Thanks for the help of all!

Referring to the baud rate is correct.

I downloaded the version suggested and tried to do some tests with LCD

The following problems occurred in the build.
Attachments
tela1.JPG
tela1.JPG (108.78 KiB) Viewed 2064 times

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: Problem receive data RS232

#5 Post by tihomir.losic » 30 Apr 2010 11:12

Hello,

you need to replace following lines:

Code: Select all

ANSEL = 0;
ANSELH = 0;
with this line of code:

Code: Select all

ADCON1 = 0x07;
Best regards,

Losic Tihomir
mikroElektronika [Support team]

Post Reply

Return to “mikroC General”