Toll-Free Customer Support 24/7

PIC Development Board

/*
* Project name:
PIC Development Board
* Copyright
(c) Researchdesignlab.com
* Test configuration:
MCU: PIC16F877A
Dev.Board: PIC
Oscillator: 20.0 MHz
Software: MPLAB IDE v8.92(HI-TECH_C)
*/

#include<htc.h>


#define _XTAL_FREQ 20000000 //crystal frequency of 20MHZ
#include "uart.h" //header file
#include "string.h" //header file

char val;

 


void main()
{
__delay_ms(100); //delay
UART_Init(9600); //calling initialization function
__delay_ms(100); //delay

while(1)
{

UART_Write_Text("RDL"); //Display on to the serial window
UART_Write(10); //carriage return
UART_Write(13); //enter
__delay_ms(1000); //delay

}
}

char UART_Init(const long int baudrate)
{
unsigned int x;
x = (_XTAL_FREQ - baudrate*64)/(baudrate*64);
if(x>255)
{
x = (_XTAL_FREQ - baudrate*16)/(baudrate*16);
BRGH = 1; //High Baud Rate Select bit
}
if(x<256)
{
SPBRG = x;
SYNC = 0;
SPEN = 1;
TRISC7 = 1;
TRISC6 = 1;
CREN = 1;
TXEN = 1;
return 1;
}
return 0;
}

char UART_TX_Empty()
{
return TRMT; //Transmit Shift Register Status bit
}

char UART_Data_Ready()
{
return RCIF; //Flag bit
}

char UART_Read()
{

while(!RCIF);
return RCREG; //Buffer register
}

void UART_Read_Text(char *Output, unsigned int length)
{
int i;
for(int i=0;i<length;i++)
Output[i] = UART_Read();
}

void UART_Write(char data)
{
while(!TRMT);
TXREG = data; //transmit register
}

void UART_Write_Text(char *text)
{
int i;
for(i=0;text[i]!='\0';i++)
UART_Write(text[i]);
}

Back to top