PIC16F877A Problem in Display LCD 2x16


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2013
    Posts
    4

    Default PIC16F877A Problem in Display LCD 2x16

    Hi everyone

    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.
    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

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: PIC16F877A Problem in Display LCD 2x16

    C is not understood here.
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  3. #3
    Join Date
    Apr 2013
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: PIC16F877A Problem in Display LCD 2x16

    ah? really?
    picbasic mean pic using basic language?
    oh sorry, fool me.
    I think it's basic level from pic.

  4. #4
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: PIC16F877A Problem in Display LCD 2x16

    Try this link http://www.mikroe.com/products/view/...gramming-in-c/. I think it will answer all your questions and maybe you'll vindicate rmteo at the same time.

  5. #5
    Join Date
    Apr 2013
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: PIC16F877A Problem in Display LCD 2x16

    Okeee thanks ya AvionicsMaster1
    i'll read and search another source of PIC using C

  6. #6
    russellperry's Avatar
    russellperry Guest


    Did you find this post helpful? Yes | No

    Default Re: PIC16F877A Problem in Display LCD 2x16

    Place a while(true) at the end of main.

    Code:

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

    while(true)
    {
    }
    }

Similar Threads

  1. Replies: 3
    Last Post: - 18th September 2012, 09:21
  2. Need advice with LCD 2x16
    By fratello in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th April 2011, 07:58
  3. 2x16 lcd problem
    By k3v1nP in forum mel PIC BASIC
    Replies: 11
    Last Post: - 30th October 2008, 05:46
  4. small 2X16 LCD
    By Ron Marcus in forum Off Topic
    Replies: 2
    Last Post: - 26th October 2007, 21:37
  5. Problem with 2x16 LCD on 16F630
    By Falcon in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th June 2005, 04:25

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts