0
votes

I've been working on a project which requires communication with my laptop and the microchip Pic 16f877a and the communication is not working properly, but When i put this example on Proteus 8 works just fine.
I don't have RS232(serial port) on my laptop, but i had bought TTL module. I use external oscillator 8MHz on the board and baud rate of 9600 bps.

When i connect with my laptop and i send to the TTL module the A symbol nothing hapens and when i send a couple of times A fast i recieve strange symbol like '?' or '#' back.

Here's the code for the Pic:

char x;
void main(){
  TRISB = 0x00;
  PORTB = 0x00;
  UART1_Init(9600);
  delay_ms(10);
while(1){
  if(UART1_Data_Ready())
  {
     x = UART1_Read();
     if(x == 'A')
     {
         PORTB = 0xFF;
         UART1_Write(13);
         UART1_Write_Text("A");
         UART1_Write(13);
     }
     else
     {
        PORTB = 0x00;
     }
  }
 x= '\0';
}
}

Can someone help me ? What's the problem ?

2
you could have any number of things going on... like hardware flow control wrong parity bits etc, don't know what UART1_Write(13); is... It is really really hard to just get this stuff to work without a logic analyzer or O-Scope... especially your first time...Grady Player
Agree with Grady, when working with micorcontrollers invest in an oscilloscope. If you have a PC you essentially already have a usable scope to debug serial I/O such as UART - your sound card. Google online for how to use your sound card as a scope. I myself use xoscope on Linux.slebetman
@GradyPlayer UART1_Write(13); is simply sending a carriage return out.DiBosco

2 Answers

0
votes

Two possibilities as far as I can see (assuming UART1_Init(9600); is a correct library function):

  1. You don't have the Rx pin set up as an input; setting TRIS registers to 0 makes all the pins on that port outputs.

  2. You are using incorrect parity.

Have you set a breakpoint at line

x = UART1_Read();

To see what you actually get in when you send from your terminal program?

Have you looked on youe scope to see what is actually coming in on the Rx pin?

delay_ms(10); is completely unnecessary.

0
votes

give

SPBRG = 139

Refer this link to set the respective Baud Rate Generator