This is the first question in stack exchange.Ok, Im trying to initiate UART of pic microcontroller(PIC24F family). I studied uart related registers in the datasheet and wrote the code to transmit a character 'K', after compile the code, hyperterminal doesn't show anything.

Here is my header file code:

void init_uart1()
 //initiate uart1
 RPOR4bits.RP8R = 3;   //pin8
 U1BRG = 25;
 U1STAbits.UTXEN =1;


Here is my main file:

    TRISB=0x0000;  //0000 0000 0000 0000
    PORTBbits.RB8=0; //set outout PORTB 8th pin 

   while (1)
       while(U1STAbits.UTXBF == 1);

whats wrong in my code?


  • 1
    \$\begingroup\$ what is your exact pic part number? \$\endgroup\$
    – vini_i
    Oct 3, 2015 at 22:18
  • \$\begingroup\$ Pic24fj128ga202 \$\endgroup\$ Oct 4, 2015 at 1:46

2 Answers 2


Microchip provides peripheral library functions which you can use directly in your program instead of putting values in registers. Go to c\Program Files\Microchip\(your compiler)\docs you will find many documentation for it or try searching for PIC18/PIC24/PIC32 peripheral library. I have not worked in PIC24 but the functions are same for all the MCU series like PIC18 PIC24 PIC32. For example, for UART:

OpenUART(): to initialize UART channel.
putsUART(): to send string to your UART
getsUART(): to receive string from UART

you can use these functions directly and save your time.!


You have RPOR4bits.RP8R = 3; listed as pin8

In either the DIP packadge or the QFN RP8 is not pin 8.

DIP RP8 -> pin 17

QFN RP8 -> pin 14


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.