Remove Text Formatting

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    gwntd541's Avatar
    gwntd541 Guest

    Default pic18f27j13 Serial Communitcation Help

    Hi, I'm new to programming with the pic, so I've been having some trouble setting up a serial communication, EUSART1, from my pic to my computer. I am using the pic18f27j13 with a max232 to try and send signals at a baudrate of 115200 to the computer. I'm using realterm to read the signals. But, non-correct Hex values are being read. My attempt is to set the Fosc to be 48Mhz from the internal clock and a baudrate of 115200. Can anyone kindly help me by looking at my code and pointing out any mistakes that I may have made. Thank you.

    Some funky things that I have noticed with realterm. Is that if I send 0x88 it comes out as 0xFA // 1000 1000 -> and get 1111 1010.
    0x00 -> gets 0xF0
    0xFF -> gets 0xFF
    0x1F -> gets 0xF3

    I really don't see any pattern.

    #include <p18f27j13.h>
    #include <stdio.h>
    #pragma config WDTEN = OFF   // Sets watchdog OFF
    #pragma config PLLDIV = 2      // Sets divider to 2. Provides output 4Mhz for 96Mhz PLL
    #pragma config OSC = INTOSCPLL // Sets OSC as INTOSC(8Mhz) Postscalled with a PLL
    #pragma config CFGPLLEN = ON //enables PLL on startup
    #pragma config PLLSEL = PLL96 // selects 96Mhz
    #pragma config XINST = OFF
    // setup functions
    void delay();
    void Wait_Buffer1();
    void setupUSART();
    void delay ()
        unsigned long int count = 0;
        for (count = 0; count < 0x0003FFFF; count ++)
    void Wait_Buffer1(void) 
        while (!TXSTA1bits.TRMT) 
    void setupUSART()
        OSCCONbits.SCS = 0x00; // Selects Primary clock(FOSC) as the clock source
        stdout = _H_USART;
        TXSTA =   0b00100000; //Enable transmit and low baud rate
        RCSTA =   0b10010000; //Enable serial port
        BAUDCON = 0b00001000; //Enable 16 bit baud generator
        SPBRGH = 0;
        SPBRG = 25;
        //target baudrate 115200, 
    void main ()
        unsigned int loop_count = 0;
        TRISCbits.TRISC7 = 1;
        TRISCbits.TRISC6 = 0;
        while (1)
        TXREG1 = 0x1F;

  2. #2
    Join Date
    Nov 2003
    Wellton, U.S.A.

    Default Re: pic18f27j13 Serial Communitcation Help

    Not many of us here do "C" as this is a Pic Basic forum.
    You will do better on a "C" forum.
    Always wear safety glasses while programming.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts