Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

PIC16F887 and Serial Port Issue

2 posters

Go down  Message [Page 1 of 1]

1PIC16F887 and Serial Port Issue Empty PIC16F887 and Serial Port Issue Mon Apr 17, 2023 9:48 am

jaltiti



I cannot get the serial Port to receive from PIC16F887. can you please show how to get it to work. Below is the code. I can see through the PIC serial monitor the message "PCT DBM" and "UAE - DUBAI" are sent sent but the serial port serial monitor receive weired characters. The config for the serial port (9600, 8 bits, 1 stop bit) matches the PIC settings.

#include
#define _XTAL_FREQ 4000000
void Send_String(unsigned char *Str);
void SerTx(unsigned char);

void main(void)
{
  TXSTA = 0x20;
  SPBRG = 25;
  SPBRGH = 0;
  RCSTA = 0x80;
  Send_String("PCT DBM \n\r");
  __delay_ms(30);
  Send_String("UAE - DUBAI \n\r");
  while(1);
}

void SerTx(unsigned char x)
{
  TXREG = x;
  while(PIR1bits.TXIF==0);
}

void Send_String(unsigned char *text)
{
  unsigned char i;
  for (i=0; text[i]!='\0'; i++)
      SerTx(text[i]);
}

2PIC16F887 and Serial Port Issue Empty Re: PIC16F887 and Serial Port Issue Thu Apr 20, 2023 9:41 pm

arcachofo

arcachofo

That is probably an error in baudrate.
Is the MCU frequency set to 4 MHz?

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum