LCD 2x16 Problem

Status
Not open for further replies.

purelife

New Member
Hello,
I have LCD problem (2x16 and PIC 16f877a)
I'm using mikroc programming

My code :

void main()
{
TRISB = 0;
Lcd_init(&portb);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
Lcd_Out(1, 1, "Pure Life");
delay_ms (1000);
}

Connections :

1 ---> GRD
2 ---> 5V
3 ---> 1k pot
4 ---> RB2 "Register Select" (RS)
5 ---> RB0 "Read / Write" (RW)
6 ---> RB3 "Enable" (E)
11 ~ 14 ---> RB4 ~ RB7 "Data 4 bit"
15 ---> 5V
16 ---> GRD

Any solutions ?

View attachment 60634
 
Last edited:
you need a delay between each stage of the initialisation. 100ms should do it. Do you have a datasheet you could post? I had one that detailed all the delays, but cannot find it. Can you see nothing at all or just a row of black squares? Normally if the LCD has not been initialised, you will just see a row of black squares. If it is initialised, but you have a contrast problem, your display will not show anything
 
sorry - i've just seen the photo (doh!). This is an initialisation problem, probably caused by no delays between each line. put a delay of 100ms and see what happens
 
I added delay 100ms after lcd init. and it works
but it writes something i cant understand it
D4 = RB4
D5 = RB5
D6 = RB6
D7 = RB7
 
The LCD controller you are using can accept 4 bit or 8 bit data - it comes from the old days when micros used to have 4 bit ports on them. You are probably expecting to operate in one mode, yet are actually using it in another. Attached is a datasheet I find quite readable. Pay attention to the intialisation flow charts at the end - they will tell you if you are using the part in 4 bit or 8 bit mode
 
to work with the PORTB and an LCD you must disable the pull-up resistor

MOVLW 0x80 ;DISABLE WEAK PULLUP RESISTORS
MOVWF OPTION_REG
 
Haven't used MicroC but some of the LCD examples I'm looking at wants you to define the port, bits and tris registers.

Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

char txt1[] = "mikroElektronika"; 
char txt2[] = "example";

void main(){
  ANSEL  = 0;                        // Configure AN pins as digital I/O
  ANSELH = 0;
  C1ON_bit = 0;                      // Disable comparators
  C2ON_bit = 0;

  Lcd_Init();                        // Initialize LCD

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,txt1);                 // Write text in first row
  Delay_ms(2000);
  Lcd_Out(2,6,txt2);                 // Write text in second row
  Delay_ms(2000);

}
 
for disable pull up resistor of PORTB

void main()
{
OPTION_REG.F7 = 1; //portB Pullup resistor disabled
TRISB = 0;
Lcd_init(&portb);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
Lcd_Out(1, 1, "Pure Life");
delay_ms (1000);
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…