mayasunny
Member level 3
Hi members,
i'm trying to interface 4 bit LCD with pic16f877a micro controller,
and my lcd c file and h.file are below
lcd is not displaying anything, im unable to find the out the problem. i need some hepl
i'm trying to interface 4 bit LCD with pic16f877a micro controller,
Code:
#pragma config FOSC = HS // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#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)
#include<xc.h>
#include"lcd.h"
#define _XTAL_FREQ 20000000
int main()
{
TRISB = 0X00; // Configure all the LCD pins as output
PORTB = 0X00;
char i,a[]={"Good morning!"};
lcd_init();
lcd_write('H');
lcd_write('e');
lcd_write('l');
lcd_write('l');
lcd_write('o');
lcd_write(' ');
lcd_write('w');
lcd_write('o');
lcd_write('r');
lcd_write('l');
lcd_write('d');
lcd_goto(0xc0); //Go to Next line and display Good Morning
lcd_data(a);
while(1);
}
Code:
#include<xc.h>
#include"lcd.h"
#define _XTAL_FREQ 20000000
//*********************************************************//
#define LCD_RS PORTBbits.RB5 // Register select
#define LCD_EN PORTBbits.RB4 // Enable
//*********************************************************//
// write a byte to the LCD in 4 bit mode
//*********************************************************//
void lcd_write(unsigned char c)
{
PORTB = (PORTB & 0xF0) | (c >> 4); // Send higher nibble
LCD_EN = 1;
LCD_EN = 0;
PORTB = (PORTB & 0xF0) | (c & 0x0F); // Send lower nibble
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(40);
}
//*********************************************************//
// Clear and home the LCD
//*********************************************************//
void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(2);
}
//*********************************************************//
// write a string of chars to the LCD
//*********************************************************//
void lcd_data(const char *s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}
//*********************************************************//
// Go to the specified position
//*********************************************************//
void lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}
//*********************************************************//
// initialise the LCD - Put into 4 bit mode
//*********************************************************//
void lcd_init(void)
{
LCD_RS = 0; // write control bytes
__delay_ms(15); // power on delay
PORTB = 0x3; // attention!
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(5);
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(100);
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(5);
PORTB = 0x2; // to set 4 bit mode
LCD_EN = 1;
LCD_EN = 0;
__delay_ms(40);
lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font
lcd_write(0x08); // display off
// lcd_write(0x0F); // display on, blink curson on
lcd_write(0x0C); // display on, cursor off, blink off
lcd_write(0x06); // entry mode
// lcd_write(0x80); // Move the cursor to beginning of first line
}
Code:
/* write a byte to the LCD in 4 bit mode */
extern void lcd_write(unsigned char);
/* Clear and home the LCD */
extern void lcd_clear(void);
/* write a string of characters to the LCD */
extern void lcd_data(const char *s);
/* Go to the specified position */
extern void lcd_goto(unsigned char pos);
/* intialize the LCD - call before anything else */
extern void lcd_init(void);
extern void lcd_putch(char);
/* Set the cursor position */
#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)
lcd is not displaying anything, im unable to find the out the problem. i need some hepl