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] Program is successfully built but LCD not displaying anything

Status
Not open for further replies.

lian_lee_98

Newbie level 1
Joined
Sep 17, 2017
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
45
Program is succesfully build but LCD not displaying anything

I am doing a project that create custom character for LCD1602, and i am using PIC16F877A, i have succesfully build the program, but by stimulating it inProteus 8, the LCD does not display anything, below is the code i wrote, the compiler i used is Hi-Tech Toolsuite C compiler, help me as i am new and i does not know where have gone wrong.


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
#define _XTAL_FREQ 20000000
#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
 
#include <htc.h>
 
__CONFIG(FOSC_EXTRC &WDTE_OFF & PWRTE_ON &LVP_OFF &BOREN_ON &CPD_OFF &WRT_OFF &CP_OFF);
 
/*******START OF LCD FUNCTIONS*********/
void Lcd_SetBit(char data_bit) //Based on the Hex value Set the Bits of the Data Lines
{
    if(data_bit& 1) 
        D4 = 1;
    else
        D4 = 0;
 
    if(data_bit& 2)
        D5 = 1;
    else
        D5 = 0;
 
    if(data_bit& 4)
        D6 = 1;
    else
        D6 = 0;
 
    if(data_bit& 8) 
        D7 = 1;
    else
        D7 = 0;
}
 
void Lcd_Cmd(char a)
{
    RS = 0;           
    Lcd_SetBit(a); //Incoming Hex value
    EN  = 1;         
    __delay_ms(4);
    EN  = 0;         
}
 
Lcd_Clear()
{
    Lcd_Cmd(0); //Clear the LCD
    Lcd_Cmd(1); //Move the curser to first position
}
 
void Lcd_Set_Cursor(char a, char b)
{
    char temp,z,y;
    if(a== 1)
    {
      temp = 0x80 + b - 1; //80H is used to move the curser
        z = temp>>4; //Lower 8-bits
        y = temp & 0x0F; //Upper 8-bits
        Lcd_Cmd(z); //Set Row
        Lcd_Cmd(y); //Set Column
    }
    else if(a== 2)
    {
        temp = 0xC0 + b - 1;
        z = temp>>4; //Lower 8-bits
        y = temp & 0x0F; //Upper 8-bits
        Lcd_Cmd(z); //Set Row
        Lcd_Cmd(y); //Set Column
    }
}
 
void Lcd_Start()
{
  Lcd_SetBit(0x00);
  for(int i=1065244; i<=0; i--)  NOP();  
  Lcd_Cmd(0x03);
    __delay_ms(5);
  Lcd_Cmd(0x03);
    __delay_ms(11);
  Lcd_Cmd(0x03); 
  Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
  Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
  Lcd_Cmd(0x08); //Select Row 1
  Lcd_Cmd(0x00); //Clear Row 1 Display
  Lcd_Cmd(0x0C); //Select Row 2
  Lcd_Cmd(0x00); //Clear Row 2 Display
  Lcd_Cmd(0x06);
}
 
void Lcd_Print_Char(char data)  //Send 8-bits through 4-bit mode
{
   char Lower_Nibble,Upper_Nibble;
   Lower_Nibble = data&0x0F;
   Upper_Nibble = data&0xF0;
   RS = 1;             // => RS = 1
   Lcd_SetBit(Upper_Nibble>>4);             //Send upper half by shifting by 4
   EN = 1;
   for(int i=2130483; i<=0; i--)  NOP(); 
   EN = 0;
   Lcd_SetBit(Lower_Nibble); //Send Lower half
   EN = 1;
   for(int i=2130483; i<=0; i--)  NOP();
   EN = 0;
}
 
void Lcd_Print_String(char *a)
{
    int i;
    for(i=0;a[i]!='\0';i++)
       Lcd_Print_Char(a[i]);  //Split the string using pointers and call the Char function 
}
 
/*******END OF LCD FUNCTIONS*********/
 
const unsigned short Custom_Char5x8[] = {
0b01110,0b11011,0b10001,0b10001,0b10001,0b10001,0b10001,0b11111,//code for CGRAM memory space 1
0b01110,0b11011,0b10001,0b10001,0b10001,0b10001,0b11111,0b11111,//code for CGRAM memory space 2
0b01110,0b11011,0b10001,0b10001,0b10001,0b11111,0b11111,0b11111,//code for CGRAM memory space 3
0b01110,0b11011,0b10001,0b10001,0b11111,0b11111,0b11111,0b11111,//code for CGRAM memory space 4
0b01110,0b11011,0b10001,0b11111,0b11111,0b11111,0b11111,0b11111,//code for CGRAM memory space 5
0b01110,0b11011,0b11111,0b11111,0b11111,0b11111,0b11111,0b11111,//code for CGRAM memory space 6
0b01110,0b11111,0b11111,0b11111,0b11111,0b11111,0b11111,0b11111 //code for CGRAM memory space 7
};
 
int main()
{
    unsigned int a;char i;
    TRISD = 0x00;
    Lcd_Start();
 
    //***Load custom char inyo CGROM***//
    Lcd_Cmd(0x04);//set CGRAM address
    Lcd_Cmd(0x00);//...set CGRAM Address
    for (i = 0; i <= 63 ; i++)
    Lcd_Print_Char(Custom_Char5x8[i]);
    Lcd_Cmd(0);      // Return to Home
    Lcd_Cmd(2);      // .. return to Home
  //*** Loading custom char complete***//
 
    while(1)
    {
        Lcd_Clear();
        Lcd_Set_Cursor(1,1);
        Lcd_Print_String("Custom Font");
        
 
        Lcd_Set_Cursor(2,1);
        Lcd_Print_Char(0); // Display Custom Character 0
        Lcd_Print_Char(1); // Display Custom Character 1
        Lcd_Print_Char(2); // Display Custom Character 2
        Lcd_Print_Char(3); // Display Custom Character 3
        Lcd_Print_Char(4); // Display Custom Character 4
        Lcd_Print_Char(5); // Display Custom Character 5
        Lcd_Print_Char(6); // Display Custom Character 6
        Lcd_Print_Char(7); // Display Custom Character 7
        Lcd_Print_String("BATTERY");
        __delay_ms(1000);
    }
    return 0;
}

 
Last edited by a moderator:

Re: Program is succesfully build but LCD not displaying anything

void Lcd_Start()
{
for(int i=1065244; i<=0; i--) NOP();
}

void Lcd_Print_Char(char data) //Send 8-bits through 4-bit mode
{
for(int i=2130483; i<=0; i--) NOP();
for(int i=2130483; i<=0; i--) NOP();
}
}[/syntax]

Any reason why you are using such huge value for i? Because if int is 16 bit signed value maximum it can take is 32767.
 

Re: Program is succesfully build but LCD not displaying anything

In code

Code:
for(int i=2130483; i<=0; i--)  NOP(); 
   EN = 0;
   Lcd_SetBit(Lower_Nibble); //Send Lower half
   EN = 1;
   for(int i=2130483; i<=0; i--)  NOP();
   EN = 0;

correct is

Code:
i >= 0;
 

Re: Program is succesfully build but LCD not displaying anything

use the appropiate variable format ...

int i=2130483 will give => -32205 => for(int i=2130483; i<=0; i++) NOP(); but only 32205 loops
unsigned int i=2130483 will give => 33331
long i =2130483 =>correct format , give 2130483 ==> for(long i=2130483; i>=0; i--) NOP();
 

Re: Program is succesfully build but LCD not displaying anything

Also be careful writing delay loops like this - it is all do easy for the compiler to see that (in effect) nothing is happening and it can optimise away the whole thing. This will result in no delay at all. You are already using the provided delay functions in other places so use them everywhere you need a delay.
Timing is VERY important when initialising these displays and the delays given in the data sheet should not be reduced.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top