Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] 16x2 LCD-PIC Display- only black squares showing

Status
Not open for further replies.

vijaynallasivam

Junior Member level 1
Joined
Nov 16, 2015
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
150
my code was working fine .but suddenly all character are black square box .i am change new lcd 16x2 display & pic16f877a controller ,development board also changing but same problem coming. why this problem coming

mp lab/hitech c compiler i am using

my code:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
header f
void CheckBusy()
{
 
    TRISD = 0xff;
 
    do
    {
    RE0 = 0;
    RE1 = 1;
    RE2 = 1;
    DelayUs(20);
    RE2 = 0;
    }while(RD7);
 
    TRISD = 0x00;
    PORTD = 0x00;
}
 
void LCD_SendCmd1(unsigned char cmd)
{
 
    PORTD = cmd;
    RE0 = 0;
    RE1 = 0;
    RE2 = 1;
    DelayUs(20);
    RE2 = 0;
}
 
void LCD_SendCmd(unsigned char cmd)
{
 
    CheckBusy();
    
    PORTD = cmd;
    RE0 = 0;
    RE1 = 0;
    RE2 = 1;
    DelayUs(20);
    RE2 = 0;
}
 
 
void LCD_SendData(unsigned char dat)
{
 
    CheckBusy();
 
    PORTD = dat;
    RE0 = 1;
    RE1 = 0;
    RE2 = 1;
    DelayUs(20);
    RE2 = 0;
 
}
 
void ClearLine(short int st)
{
 
    short int l;
    for(l=0;l<=15;l++)
    {
        LCD_SendCmd(st+l);
        LCD_SendData(' ');
    }
 
 
}
 
void LCD_init()
{
    LCD_SendCmd1(0x38);
    DelayMs(100);
    LCD_SendCmd1(0x38);
    DelayMs(100);
    LCD_SendCmd1(0x38);
    DelayMs(100);
    LCD_SendCmd(0x06);
    DelayUs(100);
    LCD_SendCmd(0x0c);
    DelayUs(100);
    LCD_SendCmd(0x01);
    DelayUs(100);
    LCD_SendCmd(0x02);
    asm("CLRWDT");
}
 
 
void LCD_puts(const char * s)
{
    
    while(*s)
    {
        LCD_SendData(*s++);
    }
 
}
 
program code:
 
 
#include<pic.h> 
#include<string.h>
#include<stdio.h>  
#include<lcd.h>    
#include<uart.h>  
 
#define _XTAL_FREQ 20e6
__CONFIG(0x3F3A);
 
void main()
{
  
    unsigned char i,temp,database;              
    unsigned char data[12]; 
 
    TRISA = 0xff;
    TRISC = 0x92;
    TRISD = 0x00;
    TRISB = 0x00;
    TRISE = 0x00;
 
        PORTB = 0x00;
    PORTD = 0x00;
    PORTE = 0x00;
        PORTC = 0x02;
      
    ADCON1 =0x86;
    
    SPBRG = 25;                       
    BRGH = 1;                         
    TXEN = 1;                          
    CREN = 1;                         
    SPEN = 1;   
    
    send_config(0b00000001);            
    send_config(0b00000010);           
    send_config(0b00000110);            
    send_config(0b00001100);           
    send_config(0b00111000); 
 
    lcd_clr();                         
    lcd_goto(0);                        
    send_string("WELCOME");    
    lcd_goto(20);                       
    send_string("STARTING UP.....");   
    delay(300000);
                                
    
 while(1)    
    {
        delay(5000);
        CREN = 1; 
        database=0;
        lcd_clr();                              
        lcd_goto(0);                           
        send_string("Place your ID");           
        lcd_goto(20);                          
        send_string("on the reader.");        
        temp=0; 
        for(i=0;i<=12;i++)data[i]=uart_rec(); 
        if(temp==0)
        {
        lcd_clr();  
        lcd_goto(0);                        
        send_string("ID:");                         
        for(i=1;i<=10;i++)send_char(data[i]);       
         }                                          
        CREN = 0; 
        delay(300000);                               
                   
      }              
}

 
Last edited by a moderator:

Hi,

Did you do a search on LCD problems?

I doubt this, because the black boxes is the most common problem with LCDs.
Usually this is caused by no initialisation or wrong initialisation of the LCD(controller).

Klaus
 

lcd init in header file separate file

Not according to your code. A program in 'C' starts with the main() function, you DO have LCD initialization in your program but it is not called when the program starts running.
Try adding "LCD_Init();" somewhere around line 137.

Note that it is normal to put the #includes at the beginning of the program, not half way through it!

Brian.
 

i am adding in LCD_Init(); but still in same problem


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void LCD_init()
{
    LCD_SendCmd1(0x38);
    DelayMs(100);
    LCD_SendCmd1(0x38);
    DelayMs(100);
    LCD_SendCmd1(0x38);
    DelayMs(100);
    LCD_SendCmd(0x06);
    DelayUs(100);
    LCD_SendCmd(0x0c);
    DelayUs(100);
    LCD_SendCmd(0x01);
    DelayUs(100);
    LCD_SendCmd(0x02);
    asm("CLRWDT");
}

 
Last edited by a moderator:

That was there before but it was never executed.

A program in 'C' is not executed from top to bottom, it always starts with the function 'main()' so you have to call LCD_Init() AFTER the main() code section has started.

Brian.
 

Black squares can be caused by the contrast setting on the LCD being too high - assuming that your LCD has separate contrast pins.
Many circuits have a variable resistor connected to the contrast pin (often called VEE in the data sheets) so that this can be set to suit the viewing conditions. If the voltage is too low then you will not see the characters at all. If it is too high then you get the black squares. Turn the voltage up until the black squares just appear and then back off a little. When the device is initialised and characters are displayed, they will then be seen against the background.
Susan
 

I think, you want to go fast without proper understanding. First read all of the related points from LCD datasheet and Check hardware circuit.

Code:
void LCD_Init()
{
    RS_PIN = 0;              //LCD instructions (RS) pin no. 4
    Chr_LCD(0x38);        //LCD 8 Bit Data
    Chr_LCD(0x01);        //LCD clear
    Chr_LCD(0x0C);        //LCD diplay on cursor not blinking
    Chr_LCD(0x80);        //LCD cursor Pos. begain
    RS_PIN = 1;              //LCD DATA (RS) pin no. 4
}

Code:
void Chr_LCD(char data)
{
    DATA_PORT = data;
    E_PIN = 1;
    Time_10ms();
    E_PIN = 0;
    Time_10ms();
}

These codes work always for me.
 

Hi,

The OP already has the LCD_init routine...
but the problem is that he never calls this routine....

Klaus
 

The exact sequence of codes needed to initialize the LCD varies according to the LCD geometry and controller IC. The codes in post #10 may not work in the original design. Follow Susan's check first to be sure you are not seeing an electrical problem then follow my advice and ensure the LCD_Init function is actually being executed.

A fresh copy of your current code would be helpful.

Another thing to check is the delay between powering up and starting to configure the LCD. The LCD controller IC is quite slow to prepare itself to accept commands, you may find it helps to add a delay BEFORE writng anything, including the init sequence to it. The datasheet shoud tell you the exact delay needed but it is typically 40mS starting from the time the supply has risen to 90% of nominal level.

Brian.
 

this is the header file:

Code:
#define rs          RE0             
#define rw          RE1            
#define e           RE2             
#define lcd_data    PORTD  

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 delay(unsigned long data)          
{                                     
    for( ;data>0;data-=1);
}
void send_config(unsigned char data)    
{
    rw=0;                               
    rs=0;                            
    lcd_data=data;                   
    e=1;                                
    delay(50);
    e=0;
    delay(50);
}
 
void send_char(unsigned char data)      
{
    rw=0;                               
    rs=1;                               
    lcd_data=data;                    
    e=1;                                
    delay(10);
    e=0;
    delay(10);
}
 
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(600); 
}
 
void send_string(const char *s)         
{          
    unsigned char i=0;
    while (s && *s)send_char (*s++);
 
}
 
[U]my program:[/U]


#include<pic.h> 
#include<string.h>
#include<stdio.h>  
#include<lcd.h>    
#include<uart.h>  
 
#define _XTAL_FREQ 20e6
__CONFIG(0x3F3A);
 
void main()
{
  
    unsigned char i,temp,database;              
    unsigned char data[12]; 
 
    TRISA = 0xff;
    TRISC = 0x92;
    TRISD = 0x00;
    TRISB = 0x00;
    TRISE = 0x00;
 
        PORTB = 0x00;
    PORTD = 0x00;
    PORTE = 0x00;
        PORTC = 0x02;
      
    ADCON1 =0x86;
    
    SPBRG = 25;                       
    BRGH = 1;                         
    TXEN = 1;                          
    CREN = 1;                         
    SPEN = 1;   
    
    send_config(0b00000001);            
    send_config(0b00000010);           
    send_config(0b00000110);            
    send_config(0b00001100);           
    send_config(0b00111000); 
 
    lcd_clr();                         
    lcd_goto(0);                        
    send_string("WELCOME");    
    lcd_goto(20);                       
    send_string("STARTING UP.....");   
    delay(300000);
                                
    
 while(1)    
    {
        delay(5000);
        CREN = 1; 
        database=0;
        lcd_clr();                              
        lcd_goto(0);                           
        send_string("Place your ID");           
        lcd_goto(20);                          
        send_string("on the reader.");        
        temp=0; 
        for(i=0;i<=12;i++)data[i]=uart_rec(); 
        if(temp==0)
        {
        lcd_clr();  
        lcd_goto(0);                        
        send_string("ID:");                         
        for(i=1;i<=10;i++)send_char(data[i]);       
         }                                          
        CREN = 0; 
        delay(300000);                               
                   
      }              
}

my program was working fine .show the character also .....my problem is LCD display unfortunate hit to ground,again i connect to power supply only black box showing problem starting here . i replace another lcd display .but same (2 row black box)problem going .....(this is the problem)
 
Last edited by a moderator:

hello,


you can increase all your delai used in this program .. multiply by 10 or 100 or more !
most problem with LCD turn around delay !
especially for the init ...

Code:
[COLOR=#333333][FONT=Verdana] Delay(100000);  //delai for  power stabilisation[/FONT][/COLOR]
[COLOR=#333333][FONT=Verdana]send_config(0b00000001);  Delay(10000);[/FONT][/COLOR]
[COLOR=#333333][FONT=Verdana]send_config(0b00000010); [/FONT][/COLOR][COLOR=#333333][FONT=Verdana] Delay(10000);[/FONT][/COLOR]
[COLOR=#333333][FONT=Verdana]send_config(0b00000110); [/FONT][/COLOR][COLOR=#333333][FONT=Verdana] Delay(10000);[/FONT][/COLOR]
[COLOR=#333333][FONT=Verdana]send_config(0b00001100); [/FONT][/COLOR][COLOR=#333333][FONT=Verdana] Delay(10000);[/FONT][/COLOR]
[COLOR=#333333][FONT=Verdana]send_config(0b00111000); [/FONT][/COLOR][COLOR=#333333][FONT=Verdana] Delay(10000);[/FONT][/COLOR]
 

Now you have REMOVED the LCD_Init() altogether!

The LCD will not initialise unless you send it specific bytes in a specific order. Previously you had the code to do that but never executed it, now you have deleted it.

Please do as I advised in post #6. Put the LCD_Init() routine back in again but call it somewhere at the beginning of main() just before your first send_config() is called.
I assume the header file you posted is one of the ones named at the start of "my program".

Brian.
 

Check you contrast Pin and try adjusting it. if only black boxes are visible to your LCD it means contrast is quite high.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top