Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4K views

Programming LCD Display (16x2) With PIC16F877A

This document contains code for programming a 16x2 character LCD display using a PIC microcontroller. The code includes functions for initializing the LCD, writing characters to it, clearing it, and positioning the cursor. The main function demonstrates displaying two lines of text on the LCD and blinking the backlight.

Uploaded by

Hisyam Sani
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views

Programming LCD Display (16x2) With PIC16F877A

This document contains code for programming a 16x2 character LCD display using a PIC microcontroller. The code includes functions for initializing the LCD, writing characters to it, clearing it, and positioning the cursor. The main function demonstrates displaying two lines of text on the LCD and blinking the backlight.

Uploaded by

Hisyam Sani
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

E:\PIC_aku\LCD_16\project_LCD\programming_LCD.

//Project: 16X2 Character LCD Lesson


//Programmer: hisyamsani bin idris
//PIC: PIC16F877A
//Crystal Frequency: 20MHz
//Compiler: HI-TECH ANSI C
//Last Modified: 1 Dis 2010
//Website: http://robot-geek.blogspot.com

#include <pic.h>
#include <htc.h>
__CONFIG(0x3F3A);
#define LCD_RS RD0
#define LCD_RW RD1
#define LCD_EN RD2
#define LCD_LIGHT RD3
#define LCD_DATA PORTD //D7-D4
#define LCD_PULSE() ((LCD_EN=1),(LCD_EN=0))
#define LCD_shift RB0

#define _XTAL_FREQ 20000000

void pic_init(void);
void lcd_init(void);
void lcd_write(unsigned char c);
void lcd_clear(void);
void lcd_goto(unsigned char pos);
void lcd_string(const char *s);

main()
{int a;
pic_init(); //initialize PIC
lcd_init(); //initialize LCD
lcd_goto(0x00); //select first line
lcd_string("robot-geek.blogspot"); //display string
lcd_goto(0x40); //select second line
lcd_string(" hisyamsani "); //display string
for(;;){
LCD_LIGHT=1;
for(a=1;a<=20;a++)
__delay_ms(20);
LCD_LIGHT=0;
for(a=1;a<=20;a++)
__delay_ms(20);
}}

void pic_init(void)
{
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;
ADCON1=0b00000110;
PORTA=0b00000000;
PORTB=0b00000000;
PORTC=0b00000000;
PORTD=0b00000000;
PORTE=0b00000000;
}

/* initialise the LCD - put into 4 bit mode */


void lcd_init(void)
{
__delay_ms(15); //delay for LCD Power Up
lcd_write(0x28); //function set
lcd_write(0x0C); //display on/off control
lcd_clear(); //clear screen
lcd_write(0x06); //entry mode set
LCD_shift=1;
}

/* write a byte to the LCD in 4 bit mode */


1
E:\PIC_aku\LCD_16\project_LCD\programming_LCD.c

void lcd_write(unsigned char c)


{
LCD_DATA=(LCD_DATA&0x0F)|(c&0xF0);
LCD_PULSE();
LCD_DATA=(LCD_DATA&0x0F)|((c<<4)&0xF0);
LCD_PULSE();
__delay_us(40);
}

/* clear LCD and goto home */


void lcd_clear(void)
{
LCD_RS=0;
lcd_write(0x1);
__delay_ms(2);
}

/* write a string of chars to the LCD */


void lcd_string(const char *s)
{

LCD_RS=1; // write characters


while(*s)
lcd_write(*s++);
LCD_shift=1;
}

/* go to the specified position */


void lcd_goto(unsigned char pos)
{
LCD_shift=1;
LCD_RS=0;
lcd_write(0x80+pos);
}

You might also like