PDA

View Full Version : PIC16F877A Problem in Display LCD 2x16



chichara
- 1st May 2013, 03:00
Hi everyone :smile:

I'm beginner in PIC and I have problem to display LCD. Here is the code :


#include<pic.h> //Define PIC Registers

#include<stdio.h> //Define I/O Functions



__CONFIG(0x3f72); //Select HS oscillator, Enable (PWRTE,BOREN),

//Disable (CPD,CP,WDTEN,In-circuit Debugger)


#define RS RE0 //LCD Register Select

#define RW RE1 //LCD Read/Write Pin

#define EN RE2 //LCD Enable Pin

#define DATA PORTD //LCD Data Port

#define DATADIR TRISD //LCD Data Port Direction Register

#define CNTRLDIR TRISE //RS,RW,EN Direction Register


void lcdinit(void); //LCD initialization Function

void lcdclr(void); //LCD Clear Function

void lcdcomd(unsigned char); //LCD Command Declaring Fucntion

void lcddata(unsigned char); //LCD Data Display Fucntion

void DelayMs(unsigned int);


void main()

{

int i;

unsigned char First[]={" PIC DEV. BOARD "};

unsigned char Secnd[]={"LCD DEMO PROGRAM"};

DelayMs(500);

lcdinit();

DelayMs(500);



while(1)

{

lcdclr();

lcdcomd(0x80);


for(i=0;i<16;i++) //Display the Message

{

lcddata(First[i]);

DelayMs(50);

}


lcdcomd(0xc0);

for(i=0;i<16;i++) //Display the Message

{

lcddata(Secnd[i]);

DelayMs(50);

}


DelayMs(500);

}

}


void lcdinit(void)

{

int i;

unsigned char command[]={0x38,0x0c,0x06,0x01};

//LCD Command set for 8 bit Interface, 2 Lines, 5x7 Dots

ADCON1 = 0x07; //Make PORTE Pin as Digital

CNTRLDIR = 0x00; //Make LCD control port (PORTE) as output

DATADIR = 0x00;

DelayMs(50); //Make LCD Data Port (PORTD) as output port

for(i=0;i<4;i++)

{

lcdcomd(command[i]); //Send the Initialisation Commands

DelayMs(5);

}

DelayMs(500);

}


void lcdclr(void) //Send LCD clear command

{

lcdcomd(0x01);

DelayMs(2);

}


void lcdcomd(unsigned char cmd)

{

RS=0; RW=0; //Select Command Register, R/W--write enabled

EN=1; //Enable LCD to accept commands

DATA=cmd;

EN=0;

DelayMs(5); //Give a Pulse via Enable pin

}

void lcddata(unsigned char byte)

{

RS=1; RW=0; //Select Data register, R/W--write enabled

EN=1;

DATA=byte; //Give a Pulse via Enable pin

EN=0;

DelayMs(5);

}

void DelayMs(unsigned int Ms)

{

int delay_cnst;

while(Ms>0)

{

Ms--;

for(delay_cnst = 0;delay_cnst <220;delay_cnst++);

}

}

The code is successfully compile in MPLAB, and also success to display in simulator (proteus). But, I try in real PIC, it can't show anything. :frown:
I really confused about that. I have checked the wiring and I'm sure that it is true. Somebody please.. I need your help.

Thank you

rmteo
- 1st May 2013, 03:36
C is not understood here.

chichara
- 1st May 2013, 09:34
ah? really?
picbasic mean pic using basic language?
oh sorry, fool me. :frown:
I think it's basic level from pic.

AvionicsMaster1
- 2nd May 2013, 14:47
Try this link http://www.mikroe.com/products/view/285/book-pic-microcontrollers-programming-in-c/. I think it will answer all your questions and maybe you'll vindicate rmteo at the same time.

chichara
- 6th May 2013, 03:52
Okeee thanks ya AvionicsMaster1
i'll read and search another source of PIC using C :smile:

russellperry
- 2nd February 2014, 08:46
Place a while(true) at the end of main.

Code:

void main()
{
lcd_init();
lcd_putc("\fTesting");

while(true)
{
}
}