Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[SOLVED] mikroc code for lcd not working

Status
Not open for further replies.

aswathymohan

Member level 4
Joined
Nov 11, 2012
Messages
68
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,727
i have used mikroc code for lcd interfacing with pic16f877a

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
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
char *text;
 
char *text1;
void main()
{ 
 
 
TRISB=0X00;
PORTB=0X00;
 
 delay_ms(500);
Lcd_Init(); // LCD display initialization
delay_ms(500);
 
//UART1_Init(9600);
//delay_ms(100);
 
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
 
text = "WELCOME...... "; // Define the first message
Lcd_Cmd(_LCD_CLEAR);
 
Lcd_Out(1,2,text); // Write the first message in the first line
text1 ="ENTER A";
Lcd_Out(2,1,text1);
delay_ms(1000);
delay_ms(1000);
 
}


code is compiled successfully...but the hardware is not working..lcd displays nothing..pl help ...its urgent
 
Last edited by a moderator:

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
Try this

Code:
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
char *text = "                ";
 
char *text1 = "               ";
void main()
{ 
 
 
TRISB=0X00;
PORTB=0X00;
 
 delay_ms(500);
Lcd_Init(); // LCD display initialization
delay_ms(500);
 
//UART1_Init(9600);
//delay_ms(100);
 
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
 
text = "WELCOME...... "; // Define the first message
Lcd_Cmd(_LCD_CLEAR);
 
Lcd_Out(1,2,text); // Write the first message in the first line
text1 ="ENTER A";
Lcd_Out(2,1,text1);
delay_ms(1000);
delay_ms(1000);
 
}
 

aswathymohan

Member level 4
Joined
Nov 11, 2012
Messages
68
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,727
Thank you for ur response.But still its not working Sir..Pl help Sir
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
Try this code

Code:
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
char text[17];
 
char text1[17];


void main()
{ 
 
 
TRISB=0X00;
PORTB=0X00;
 
Lcd_Init(); // LCD display initialization
delay_ms(500);
 

Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
 
text = "WELCOME...... "; // Define the first message
Lcd_Out(1,2,text); // Write the first message in the first line
text1 ="ENTER A";
Lcd_Out(2,1,text1);
 
}
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
Maybe you have selected a wrong clock frequency in mikroC. Is your hardware and connections ok? post your circuit diagram. zip and post your mikroc project files.

Code:
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;

char text[17] = "Welcome...";
char text1[17] = "Enter A";

void main()
{


     TRISB=0X00;
     PORTB=0X00;

     Lcd_Init();                    // LCD display initialization
     Lcd_Cmd(_LCD_CURSOR_OFF);      // LCD command (cursor off)
     Lcd_Cmd(_LCD_CLEAR);           // LCD command (clear LCD)
     Lcd_Out(1,2,text);             // Write the first message in the first line
     Lcd_Out(2,1,text1);

}
 

Attachments

Last edited:

aswathymohan

Member level 4
Joined
Nov 11, 2012
Messages
68
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,727
Is the same be successful in hardware side??Sir will u be able to get the opt from hardware side..
 

aswathymohan

Member level 4
Joined
Nov 11, 2012
Messages
68
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,727
I have some doubts regarding the hardware side.Will u post the details of lcd connections??Other than the pot (for contrast),any other resistor is required in connection?
 

aswathymohan

Member level 4
Joined
Nov 11, 2012
Messages
68
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,727
Still no response from the lcd..I tested the lcd with a program done in mplab ide..Its working.I suppose there is some pblm is with the mikroc code,regarding delay..
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
Can you post the screenshot of mikroC Configuration for your project?
 

T3STY

Full Member level 4
Joined
Apr 17, 2012
Messages
239
Helped
24
Reputation
48
Reaction score
24
Trophy points
1,308
Activity points
3,715
If possible, check out the timing for the LCD clock. 50us high clock should be enough when using 4MHz PIC clock.
Also, I'm not aware of mikroc programming and the available functions, but I see no configuration in your code for the Lcd_Init() function. How do you set 4-bit or 8-bit data transfer mode? From your code I understand you're trying to use 4-bit mode, but are you sure the Lcd_Init() function does not initialize the display for 8-bit mode? Isn't there any other function you have to use for setting the data transfer mode?
Another thing: not all the displays work the same. You're sure your HW display is a HD44780 controlled display?
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
This code
Code:
 sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
with Lcd_Init(); sets Lcd mode to 4 bit.
 

aswathymohan

Member level 4
Joined
Nov 11, 2012
Messages
68
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,727
Finally got it..I just gave a delay of 1 s after Lcd_init() and 100 ms after clear command and cursor off command..Thanks a lot..
 

mustafa alkhani

Newbie level 3
Joined
Jan 14, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
20
i have similar problem but when i am connect short cable its work fine, when i am connect a long cable the LCD shown wrong data, i am using 8MHz and mikroC Pro compiler can you help me
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top