LCD wont display

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

LCD wont display

Postby shinigami.alv » Tue May 15, 2012 12:36 am

im using SK40C to display my LCD but all i got is only black screen on the first line. im using (16x2) LCD. below is my code, am i missing something?

CODE: SELECT_ALL_CODE
#include <pic.h>   
__CONFIG ( 0x3F3A ); 
#define   lcd_data      PORTD
#define rs            RB4
#define e            RB5

//==========================================================================
void Init(void);
void delay(unsigned long data);
void send_config(unsigned char data);
void send_char(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void send_string(const char *s);
void e_pulse(void);


//==========================================================================
void main(void)
{
   

   Init();
   lcd_clr();   
   lcd_goto(0);                           // clear the LCD screen
   send_string("helo");                 
   lcd_goto(20);                           // move to 2nd line
   send_string ("helo");
   
}


void Init(void)
{
 
   TRISD = 0b00000000; //output           
   TRISB = 0b11111111;  //input
   PORTB = 0;
//==============================================================================
  //configure lcd
   send_config(0b00000001);         //clear display at lcd
   send_config(0b00000010);         //lcd return to home
   send_config(0b00000110);         //entry mode-cursor increase 1
   send_config(0b00001100);         //display on, cursor off and cursor blink off
   send_config(0b00111000);         //function set

//==============================================================================
}

void delay(unsigned long data)         //short delay     
{                              //delay lenght according to the given value
   for( ;data>0;data-=1);
}



void send_config(unsigned char data)
{
   rs=0;                        //clear rs into config mode
   lcd_data=data;
   delay(50);
   e_pulse();
}

void send_char(unsigned char data)
{
   rs=1;                        //set rs into write mode
   lcd_data=data;                   
   delay(50);
   e_pulse();
}

void e_pulse(void)
{
   e=1;
   delay(50);
   e=0;
   delay(50);
}

void lcd_goto(unsigned char data)
{
    if(data<16)
   {
       send_config(0x80+data);
   }
   else
   {
       data=data-20;
      send_config(0xc0+data);
   }
}

void lcd_clr(void)
{
    send_config(0x01);
   delay(50);   
}

void send_string(const char *s)
{         
   //unsigned char i=0;
     while (s && *s)send_char (*s++);

}

shinigami.alv
Newbie
 
Posts: 12
Joined: Sat Mar 31, 2012 1:34 am

Re: LCD wont display

Postby ABSF » Tue May 15, 2012 6:33 am

shinigami.alv WROTE:im using SK40C to display my LCD but all i got is only black screen on the first line. im using (16x2) LCD. below is my code, am i missing something?


Are you running at 20MHz? I'd say the delay(50) is too short...,,, Try delay(2000) and see if it works.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: LCD wont display

Postby shinigami.alv » Tue May 15, 2012 12:05 pm

Hi Allan, i tried that but still not working. nothing appears on the screen. could it be the code problem?
shinigami.alv
Newbie
 
Posts: 12
Joined: Sat Mar 31, 2012 1:34 am

Re: LCD wont display

Postby ober » Tue May 15, 2012 3:58 pm

Is the code problem... you connect the LCD RS and LCD E at port B, but your TRISB show all pins at PORTB is input. Try to change that particular pin to become output.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: LCD wont display

Postby shinigami.alv » Tue May 15, 2012 9:14 pm

ya, the delay and RS & E are the problems. i tried and found out that delay(700) is the shortest that 20M can support. thanks guys for the help. :)
shinigami.alv
Newbie
 
Posts: 12
Joined: Sat Mar 31, 2012 1:34 am

Re: LCD wont display

Postby ABSF » Tue May 15, 2012 9:42 pm

Glad to hear that you've solved your problem.... :)

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

My code also facing same problem...can help?

Postby choohao » Sat Nov 03, 2012 7:46 pm

CODE: SELECT_ALL_CODE
//==========================================================================
//        Author                                        : CYTRON       
//        Project                                        : SK40C Led Blinking
//        Project description                : Blink RB6 and RB7 LED
//                                                          This sample source code is valid for 20MHz crystal.
//                                                 
//==========================================================================

//        include
//==========================================================================
#include <pic.h>

//configuration
//==========================================================================
__CONFIG ( 0x3F32 );                //configuration for the  microcontroller

//        define
//==========================================================================
#define        rs                        RB4                        //RS pin of the LCD display
#define        e                        RB5                        //E pin of the LCD display

#define        lcd_data        PORTD                //LCD 8-bit data PORT

#define        SW1                        RB0                       
#define        SW2                        RB1                       

#define        LED1                RB6                       
#define        LED2                RB7                               

//        function prototype                (every function must have a function prototype)
//==========================================================================
void delay(unsigned long data);                       
void send_config(unsigned char data);
void send_char(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void send_string(const char *s);
void uart_send(unsigned char data);



//        global variable
//==========================================================================

//        main function                                        (main fucntion of the program)
//==========================================================================
void main()
{
        unsigned long delay_time=5000;

        //set I/O input output
        TRISB = 0b00000000;                                //configure PORTB I/O direction
        TRISD = 0b00000000;                                //configure PORTD I/O direction
        TRISA = 0b00000111;                                //configure PORTA I/O direction
       
        //setup ADC
        ADCON1 = 0b00000110;                                //set ADx pin digital I/O
       
        //configure lcd
        send_config(0b00000001);                        //clear display at lcd
        send_config(0b00000010);                        //lcd return to home
        send_config(0b00000110);                        //entry mode-cursor increase 1
        send_config(0b00001100);                        //display on, cursor off and cursor blink off
        send_config(0b00111000);                        //function set

        //display startup message       
        lcd_clr();                                                        //clear lcd
        lcd_goto(2);                                                //set the lcd cursor to location 0
        send_string("Cytron Tech.");                //display "Cytron Tech."
        lcd_goto(26);                                                //set the lcd cursor to location 20
        send_string("SK40C");                                //display "SK40C"

        LED1=0;                                                                //OFF LED1
        LED2=0;                                                                //OFF LED2

        while(1)                                                        //Infinite loop
        {
                if(!SW1)                                                //check if SW1 is pressed
                {
                        while (!SW1);                                //wait SW1 pressed
                        {
                                delay_time+=1000;                //delay
                        }
                }
                else if(!SW2)                                        //check if SW2 is pressed
                {
                        while (!SW2);                                //wait SW2 pressed
                        {
                                delay_time-=1000;                //delay
                        }
                }
               
                LED1^ = 1;                                        //toggle LED1
                delay(delay_time);                               
                LED2^ = 1;                                        //toggle LED2                       
                delay(delay_time);                       
        }
}

//        functions
//==========================================================================
void delay(unsigned long data)                        //delay function, the delay time
{                                                                                //depend on the given value
        for( ;data>0;data--);
}

void send_config(unsigned char data)        //send lcd configuration
{
        rs=0;                                                                //set lcd to configuration mode
        lcd_data=data;                                                //lcd data port = data
        e=1;                                                                //pulse e to confirm the data
        delay(50);
        e=0;
        delay(50);
}

void send_char(unsigned char data)                //send lcd character
{
         rs=1;                                                                //set lcd to display mode
        lcd_data=data;                                                //lcd data port = data
        e=1;                                                                //pulse e to confirm the data
        delay(10);
        e=0;
        delay(10);
}

void lcd_goto(unsigned char data)                //set the location of the lcd cursor
{                                                                                //if the given value is (0-15) the
         if(data<16)                                                        //cursor will be at the upper line
        {                                                                        //if the given value is (20-35) the
                 send_config(0x80+data);                        //cursor will be at the lower line
        }                                                                        //location of the lcd cursor(2X16):
        else                                                                // -----------------------------------------------------
        {                                                                        // | |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| |
                 data=data-20;                                        // | |20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| |
                send_config(0xc0+data);                        // -----------------------------------------------------       
        }
}

void lcd_clr(void)                                                //clear the lcd
{
         send_config(0x01);
        delay(600);       
}

void send_string(const char *s)                        //send a string to display in the lcd
{         
          while (s && *s)send_char (*s++);
}

void uart_send(unsigned char data)
{       
        while(TXIF==0);                                                //only send the new data after
        TXREG=data;                                                        //the previous data finish sent
}
choohao
Freshie
 
Posts: 5
Joined: Sat Nov 03, 2012 7:18 pm

Re: LCD wont display

Postby zhenning » Sat Nov 03, 2012 8:08 pm

choohao WROTE:
CODE: SELECT_ALL_CODE
//==========================================================================
//        Author                                        : CYTRON       
//        Project                                        : SK40C Led Blinking
//        Project description                : Blink RB6 and RB7 LED
//                                                          This sample source code is valid for 20MHz crystal.
//                                                 
//==========================================================================

//        include
//==========================================================================
#include <pic.h>

//configuration
//==========================================================================
__CONFIG ( 0x3F32 );                //configuration for the  microcontroller

//        define
//==========================================================================
#define        rs                        RB4                        //RS pin of the LCD display
#define        e                        RB5                        //E pin of the LCD display

#define        lcd_data        PORTD                //LCD 8-bit data PORT

#define        SW1                        RB0                       
#define        SW2                        RB1                       

#define        LED1                RB6                       
#define        LED2                RB7                               

//        function prototype                (every function must have a function prototype)
//==========================================================================
void delay(unsigned long data);                       
void send_config(unsigned char data);
void send_char(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void send_string(const char *s);
void uart_send(unsigned char data);



//        global variable
//==========================================================================

//        main function                                        (main fucntion of the program)
//==========================================================================
void main()
{
        unsigned long delay_time=5000;

        //set I/O input output
        TRISB = 0b00000000;                                //configure PORTB I/O direction
        TRISD = 0b00000000;                                //configure PORTD I/O direction
        TRISA = 0b00000111;                                //configure PORTA I/O direction
       
        //setup ADC
        ADCON1 = 0b00000110;                                //set ADx pin digital I/O
       
        //configure lcd
        send_config(0b00000001);                        //clear display at lcd
        send_config(0b00000010);                        //lcd return to home
        send_config(0b00000110);                        //entry mode-cursor increase 1
        send_config(0b00001100);                        //display on, cursor off and cursor blink off
        send_config(0b00111000);                        //function set

        //display startup message       
        lcd_clr();                                                        //clear lcd
        lcd_goto(2);                                                //set the lcd cursor to location 0
        send_string("Cytron Tech.");                //display "Cytron Tech."
        lcd_goto(26);                                                //set the lcd cursor to location 20
        send_string("SK40C");                                //display "SK40C"

        LED1=0;                                                                //OFF LED1
        LED2=0;                                                                //OFF LED2

        while(1)                                                        //Infinite loop
        {
                if(!SW1)                                                //check if SW1 is pressed
                {
                        while (!SW1);                                //wait SW1 pressed
                        {
                                delay_time+=1000;                //delay
                        }
                }
                else if(!SW2)                                        //check if SW2 is pressed
                {
                        while (!SW2);                                //wait SW2 pressed
                        {
                                delay_time-=1000;                //delay
                        }
                }
               
                LED1^ = 1;                                        //toggle LED1
                delay(delay_time);                               
                LED2^ = 1;                                        //toggle LED2                       
                delay(delay_time);                       
        }
}

//        functions
//==========================================================================
void delay(unsigned long data)                        //delay function, the delay time
{                                                                                //depend on the given value
        for( ;data>0;data--);
}

void send_config(unsigned char data)        //send lcd configuration
{
        rs=0;                                                                //set lcd to configuration mode
        lcd_data=data;                                                //lcd data port = data
        e=1;                                                                //pulse e to confirm the data
        delay(50);
        e=0;
        delay(50);
}

void send_char(unsigned char data)                //send lcd character
{
         rs=1;                                                                //set lcd to display mode
        lcd_data=data;                                                //lcd data port = data
        e=1;                                                                //pulse e to confirm the data
        delay(10);
        e=0;
        delay(10);
}

void lcd_goto(unsigned char data)                //set the location of the lcd cursor
{                                                                                //if the given value is (0-15) the
         if(data<16)                                                        //cursor will be at the upper line
        {                                                                        //if the given value is (20-35) the
                 send_config(0x80+data);                        //cursor will be at the lower line
        }                                                                        //location of the lcd cursor(2X16):
        else                                                                // -----------------------------------------------------
        {                                                                        // | |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| |
                 data=data-20;                                        // | |20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| |
                send_config(0xc0+data);                        // -----------------------------------------------------       
        }
}

void lcd_clr(void)                                                //clear the lcd
{
         send_config(0x01);
        delay(600);       
}

void send_string(const char *s)                        //send a string to display in the lcd
{         
          while (s && *s)send_char (*s++);
}

void uart_send(unsigned char data)
{       
        while(TXIF==0);                                                //only send the new data after
        TXREG=data;                                                        //the previous data finish sent
}



What is the problem? Mind describing a bit instead of just posting the codes? :roll:
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: LCD wont display

Postby robosang » Sat Nov 03, 2012 9:09 pm

Yup.... I would like to know too... it seem like we know what are you asking :)
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: LCD wont display

Postby mohdismiaswaly » Mon Nov 05, 2012 6:04 pm

Hi,

I a newbie here..how to post thread here?

Cannot find any button to click... :roll:

TQ
mohdismiaswaly
Apprentice
 
Posts: 39
Joined: Mon Nov 05, 2012 2:51 pm

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 0 guests