Monday, 19 October 2015

PIC16F877A 4BIT LCD INTERFACE

#include<pic.h>
#include<htc.h>
#define __PIC16F877A_H
#define led PORTDbits.RD0
__CONFIG(WDTE_OFF & FOSC_HS);
//unsigned int x;
void delay(unsigned int i)
{
while(i--);
}

void cmd(unsigned char c)
{
unsigned int l,h;
l=c &0X0F;
h=c>>4;


PORTD=h|0X40;
delay(20);
PORTD=h|0X00;

PORTD=l|0X40;
delay(20);
PORTD=l|0X00;
}


void dat (unsigned char c)
{
unsigned int l,h;
l=c &0X0F;
h=c>>4;

PORTD=h|0X50;
delay(20);
PORTD=h|0X10;

PORTD=l|0X50;
delay(20);
PORTD=l|0X10;
}


void lcd_init()
{
cmd(0x02);
delay(100);
cmd(0x28);
delay(100);
cmd(0x01);
delay(100);
cmd(0x80);
delay(100);
cmd(0x0e);
delay(100);
}


void string(unsigned char *p)
{
while(*p!='\0')
{
dat(*p);
p++;
}
}

int main()
{
TRISD=0x00;

lcd_init();

string ("EMBEDDED LAB");
//num(12345);
while(1);

}

No comments:

Post a Comment