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.

[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:

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);
 
}
 

Thank you for ur response.But still its not working Sir..Pl help Sir
 

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);
 
}
 

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

  • lcd.jpg
    lcd.jpg
    440.1 KB · Views: 113
  • PIC16F877A LCD.rar
    46.9 KB · Views: 50
Last edited:

Is the same be successful in hardware side??Sir will u be able to get the opt from hardware side..
 

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?
 

The ciruit is posted here

i am using 4 bit mode lcd and mikroC Pro compiler.
 

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

Can you post the screenshot of mikroC Configuration for your project?
 

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?
 

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.
 

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

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

Back
Top