PIC USART Problems

Discussion in 'Embedded Systems and Microcontrollers' started by crazyengineer, Sep 27, 2012.

  1. crazyengineer

    Thread Starter Member

    Dec 29, 2010
    156
    2
    Hello everyone. I'm trying to write hello world to a serial program. However, when I ran the following code

    Code ( (Unknown Language)):
    1.  
    2. #include <p18F2420.h>
    3. #include <delays.h>
    4. #include <usart.h>
    5. #pragma config OSC = INTIO67
    6. #pragma config WDT = OFF
    7. #pragma config PBADEN = OFF
    8. #pragma config LVP = OFF
    9.  
    10.  
    11.  
    12.  
    13. void main()
    14. {
    15.     TRISC=0x00;
    16.     OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE &USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 51);
    17.     while(1)
    18.     {
    19.         while(BusyUSART());
    20.         putrsUSART("Hello");
    21.     }
    22.  
    23. }
    24.  
    [​IMG]

    Keep in mid I'm using the internal osc of the PIC18F2420.
    I see nothing displayed in the serial program, but the cursor moves
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,436
    3,360
    Have you made certain that the two baud rates are the same?
    Try using an external xtal instead of the internal oscillator.
     
    crazyengineer likes this.
  3. crazyengineer

    Thread Starter Member

    Dec 29, 2010
    156
    2
    Works perfectly now. Just the confusion of the internal clock was messing me up. I switched to an external 20MHZ clock the whole thing works marvelously!
     
    Last edited: Sep 27, 2012
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    If you use Hi-Tech C you must define the clock frequency in your code.
     
  5. lawncegary

    New Member

    Sep 27, 2012
    6
    1
    I switched to an external 20MHZ clock the whole thing works marvelously![​IMG]
     
Loading...