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] LCD-PIC problem- only black squares

Status
Not open for further replies.

Milead

Newbie level 5
Joined
Sep 13, 2011
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
Im trying to connect a HD44780 lcd to a pic16f874a.
I read many posts in different forums, but could not solve my problem.
I have the pic connected to the lcd just as it is in the example of Mikroc.
My code is also very similar.
I dont know if the problem is the hardware or the software.
I appreciate if you help me.
i can see only black squares on the first row.
i took care of the contrast,
LVP and in circuit debugger are off in config bits.

Here is my code:

char *text = "Hello World"; //Constant holding text to be displayed
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;

void main() * * * * //Main program
*{
* TRISB = 0; * * * * * * * *// PORTB is output
* * * Delay_ms(1000);
* Lcd_Init(); * * * * // Initialize LCD connected to PORTB
* * * * * * *Delay_ms(1000);
* Lcd_Cmd(_Lcd_CLEAR); * * * // Clear data on lcd
* Lcd_Cmd(_Lcd_CURSOR_OFF); *// Turn cursor off
* while(1) *//while loop, not necessarily needed
* * {
* * *Lcd_Out(1, 1, text); * // Print text to LCD, 2nd row, 1st column
* * }
}
 

Are you running your code on physical hardware or in simulation, like Proteus? Is your clock speed defined correct in MikroC?

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
Are you running your code on physical hardware or in simulation, like Proteus? Is your clock speed defined correct in MikroC?

BigDog

the code works fine on Proteus but not in real life:D
the clock speed is set to 8 MHz and i have chose the HS oscillator and using an 8 MHz crystal oscillator
 

Did you connect RW pin to GND?
&
Try this code

char *text = "Hello World"; //Constant holding text to be displayed
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;

void main() //Main program
{
TRISB = 0; // PORTB is output
Lcd_Init(); // Initialize LCD connected to PORTB
Lcd_Cmd(_LCD_CLEAR); // Clear data on lcd
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
while(1) //while loop, not necessarily needed
{
Lcd_Out(1, 1, text); // Print text to LCD, 1st row, 1st column
}
}
 

Did you connect RW pin to GND?
&
Try this code

char *text = "Hello World"; //Constant holding text to be displayed
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;

void main() //Main program
{
TRISB = 0; // PORTB is output
Lcd_Init(); // Initialize LCD connected to PORTB
Lcd_Cmd(_LCD_CLEAR); // Clear data on lcd
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
while(1) //while loop, not necessarily needed
{
Lcd_Out(1, 1, text); // Print text to LCD, 1st row, 1st column
}
}

RW is grounded.
code without delays did not do any better:|

---------- Post added at 12:36 ---------- Previous post was at 11:12 ----------

any idea?:(
 

Are all the other data lines grounded. check the contrast pin variation. and use pull up resistor for all port pin.
 

How 'bout Vo (contrast) pin? Do you have a trim-pot or voltage divider on Vo pin? (No. 3 on LCD connector)
yes with a pot

---------- Post added at 17:56 ---------- Previous post was at 17:54 ----------

Are all the other data lines grounded. check the contrast pin variation. and use pull up resistor for all port pin.
other data lines are grounded, but could you be more specific about "pull up resistors for all port pins"?
 

add 10k resistor to all port pins one end to port pin and other end to VCC. for all port pins.
 

simulate it in proteus and see the output once. what is your fuse bit and osc settings in program.
 

PROBLEM SOLVED:D ok, it was obvious that the lcd does not initialize, so i reduced the Oscillator Freq from 8 to 4MHz and boom, it works:D thank you all:)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top