Random Characters in Terminal Emulator

600 views Asked by At

I am currently working on a project to select different outputs based on a text input from a laptop via USB.

What I am currently trying to do is send a character out from my PIC18F1320 to HyperTerminal, I have tried using variables but was recieveing rnadom characters such as smiley faces etc. I simplified my code to simply print a 1 however I am still recieving smily face symbols. I have checked that I am using the correct baud rate and there is definite communication between my laptop and the PIC, however at this point I am completely stuck as I have no idea why random characters are being output.

I have extremely little knowledge of C and any help would be appreciated

    #include <p18f1320.h>
    #include <usart.h>
    #include <stdio.h>
    #include <stdlib.h>

    void main()
    { 
        OSCCON = 0x70;  // 8MHz internal clock

        // Configure USART
        OpenUSART(  USART_TX_INT_OFF    &
                    USART_RX_INT_OFF    &
                    USART_ASYNCH_MODE   &
                    USART_EIGHT_BIT     &
                    USART_CONT_RX       &
                    USART_BRGH_LOW,
                    12);

        while (1)
        {
            putrsUSART("1");
        }
        CloseUSART();
    }
2

There are 2 answers

1
AudioBubble On

The internal RC oscillator on the PIC is not precise enough to run the USART at the desired speed - it can vary by ±2% from the expected frequency, which is probably far out enough to be causing the errors you're seeing. You will need to attach and configure an external crystal for correct results.

2
chux - Reinstate Monica On

Put your data in RAM and send. See Harvard Architecture

char buf[10];
strcpy(buf, "Hello\n");  // This should cal special ROM to RAM strcpy();
putrsUSART(buf);

Note: "I have checked that I am using the correct baud rate" may not be right. Until you received valid data, I would not be too confident about this.