UART program for PIC18F65K40

General discussion on mikroBasic.
Post Reply
Author
Message
Gayathri
Posts: 2
Joined: 19 Jun 2018 12:25

UART program for PIC18F65K40

#1 Post by Gayathri » 20 Jun 2018 06:30

Hi,
I'm new to this mikroc software and programming. Could you please provide me a sample code to transmit a character using UART in PIC18F65K40.

Is there any difference between pic18f65k40 and pic18f65k22 in terms of initiating uart transmission? Whether there is any need to initiate or disable any special registers in pic18f65k40? In mikroc software there present a library for uart so i just copied the code from your website and add my transmitter and receiver pins in program but my circuit doesnot working.

Code: Select all

char i ;
 void main()
 {
   TRISC  = 0x00;    // making port as output
   RX4PPS = 0x11;
   TX4PPS = 0x10;
   UART4_Init(9600);            // Initialize USART module
                                  // (8 bit, 9600 baud rate, no parity bit...)
   delay_ms(2000);
   UART4_Write_Text("Hello world!");
   UART4_Write(13);      // Start a new line
   UART4_Write(10);
   UART4_Write_Text("PIC18F65K40 UART example");
   UART4_Write(13);     // Start a new line
   UART4_Write(10);
   while (1) {
     if (UART4_Data_Ready()) { // If data has been received
      i = UART4_Read();     // read it
      UART4_Write(i);       // and send it back
     }
   }
 }     
Anybody, please guide me.

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: UART program for PIC18F65K40

#2 Post by filip.grujcic » 22 Jun 2018 15:10

Hello,

Try

Code: Select all

Unlock_IOLOCK();
   PPS_Mapping( _RC6, _INPUT, _RX4 );
   PPS_Mapping( _RC7, _OUTPUT, _TX4);
   Lock_IOLOCK();
You can replace _RC6 and _RC7 with pins you want RX and TX lines on.
Also check if you properly set the configuration and oscillator registers.

Regards,
Filip Grujcic

Post Reply

Return to “mikroBasic General”