Home Code PIC16F873 and LCD example

PIC16F873 and LCD example

by shedboy71

In this example we connect an LCD to our PIC16F873 microcontroller

Schematic

pic16f873 and lcd

pic16f873 and lcd

Code

Mplab X using the XC8 compiler requires lcd.h

lcd header file

 

#define _XTAL_FREQ 4000000
 
#define RS RC0
#define EN RC1
#define D4 RC2
#define D5 RC3
#define D6 RC4
#define D7 RC5
// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//END CONFIG
 
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include "lcd.h";
/*
* 
*/
int main()
{
unsigned int a;
TRISC = 0x00;
Lcd_Init();
while(1)
{
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Write_String("Line 1");
Lcd_Set_Cursor(2,1);
Lcd_Write_String("Line 2");
 
}
return 0;
 
}

 

Links

10PCS lcd 1602 blue screen Character LCD Display

PIC16F873 DIP28 IC 20PCS

Share

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More