Page 1 of 1

LCD initialization for 16F88

Posted: 29 Jan 2008 11:42
by terabit
I use LCD with the 16F88 and the conection is following:
DB7-RB7,
DB6-RB6
DB5-RB5
DB4-RB4
ES-RB1
E-RB0

I use Lcd_Config(PORTB,7,6,5,4,PORTB,1,3,0); Is this correct ? The LCD dont work...

_miroslav

Re: LCD initialization for 16F88

Posted: 29 Jan 2008 12:53
by zristic
terabit wrote:I use LCD with the 16F88 and the conection is following:
DB7-RB7,
DB6-RB6
DB5-RB5
DB4-RB4
ES-RB1
E-RB0

I use Lcd_Config(PORTB,7,6,5,4,PORTB,1,3,0); Is this correct ? The LCD dont work...

_miroslav
What exactly does not work?
Make sure you connect the RW pin of LCD to ground.

Re: LCD initialization for 16F88

Posted: 29 Jan 2008 13:19
by terabit
zristic wrote:
terabit wrote:I use LCD with the 16F88 and the conection is following:
DB7-RB7,
DB6-RB6
DB5-RB5
DB4-RB4
ES-RB1
E-RB0

I use Lcd_Config(PORTB,7,6,5,4,PORTB,1,3,0); Is this correct ? The LCD dont work...

_miroslav
What exactly does not work?
Make sure you connect the RW pin of LCD to ground.

Yes the RW is on ground. (I use the connection with assambler and it work OK, the connections are OK) .It make only black boxes in first row.(there are not full black, it is like the LCD is not initialized)

I have begin with the Mikropascal and i am not sure if this is OK Lcd_Config(PORTB,7,6,5,4,PORTB,1,3,0); for me connection.

here is full code

Code: Select all

var ch: byte;
    t : word;
    Text : array[17] of char;
    tlong: longint;

begin
  PORTB  := 0;                      // clear PORTB
  TRISB  := 0;                      // designate PORTB  as output (LCD is connected to PORTB)
  INTCON := 0;                      // disable all interrupts

                                       //Lcd_Init(PORTB);                  // initialize  (4-bit interface connection)
Lcd_Config(PORTB,7,6,5,4,PORTB,1,3,0);

                                       

  Lcd_Cmd( LCD_CURSOR_OFF);         // send command to LCD (cursor off)
  Lcd_Cmd(LCD_CLEAR);



  Text := 'Inicializacia';       // assign text to string a
  Lcd_Out(1,1, Text);               // print string a on LCD, 1st row, 1st column
  OPTION_REG := $80;
  ADCON1     := $82;                // configure VDD as Vref, and analog channels
  TRISA      := $FF;                // designate porta as input
  Delay_ms(2000);
  Text  := 'voltage:';              // assign text to string a
  Lcd_Out(2, 1, Text);              // print string a on LCD, 2nd row, 1st column
  Lcd_Chr(2, 14, 'V');
  while true do
    begin
      t     := ADC_read(0);         // get ADC value from 2nd channel
      tlong := t*5000;
      t     := tlong shr 10;
      ch    := t div 1000;          // prepare value for diplay

      Lcd_Chr(2, 9, 48+ch);         // write ASCII at 2nd row, 9th column
      Lcd_Chr(2, 10, '.');

      ch    := (t div 100) mod 10;
      Lcd_Chr(2, 11, 48+ch);

      ch    := (t div 10) mod 10;
      Lcd_Chr(2, 12, 48+ch);

      ch    := t mod 10;
      Lcd_Chr(2, 13, 48+ch);

      delay_ms(1);
    end;
end.

Re: LCD initialization for 16F88

Posted: 29 Jan 2008 13:29
by zristic
You have to set ANSEL to 0, before calling LCD_Config.

Re: LCD initialization for 16F88

Posted: 29 Jan 2008 13:51
by terabit
zristic wrote:You have to set ANSEL to 0, before calling LCD_Config.
Why ANSEL? I use the LCD on RB . Now i have delete the ADC code I need only check the LCD.
Is this lcd config OK? Lcd_Config(PORTB,7,6,5,4,PORTB,1,3,0); for this pins?
DB7-RB7,
DB6-RB6
DB5-RB5
DB4-RB4
ES-RB1
E-RB0

Or not?

Code: Select all

var ch: byte;
    t : word;
    Text : array[17] of char;
    tlong: longint;

begin
  PORTB  := 0;                      // clear PORTB
  TRISB  := 0;                      // designate PORTB  as output (LCD is connected to PORTB)
  INTCON := 0;                      // disable all interrupts

                                       //Lcd_Init(PORTB);                  // initialize  (4-bit interface connection)
 Lcd_Config(PORTB,7,6,5,4,PORTB,1,3,0);
                                      
  Lcd_Cmd( LCD_CURSOR_OFF);         // send command to LCD (cursor off)
  Lcd_Cmd(LCD_CLEAR);
  Text := 'Inicializacia';       // assign text to string a
  Lcd_Out(1,1, Text);               // print string a on LCD, 1st row, 1st column
  OPTION_REG := $80;
  ADCON1     := $82;                // configure VDD as Vref, and analog channels
  TRISA      := $FF;                // designate porta as input
  Delay_ms(2000);
  Text  := 'voltage:';              // assign text to string a
  Lcd_Out(2, 1, Text);              // print string a on LCD, 2nd row, 1st column
  Lcd_Chr(2, 14, 'V');

end.

Re: LCD initialization for 16F88

Posted: 29 Jan 2008 14:07
by zristic
Why ANSEL? I use the LCD on RB .
:shock:

I expect that you listen to the advice if you are already asking for it.

PORTB can be analog too, in order to use LCD, you have to make it digital. Datasheet is your friend.

Image

It really costs you nothing to try it out. Just put ANSEL := 0; then compile+program.

Btw, you can still use ADC, but on other pins, not on those which are reserved for LCD.

Posted: 29 Jan 2008 14:22
by terabit
Super, it work :)
thanks

Posted: 02 Feb 2008 15:29
by Doctor Aziz
What's the equivalent of "ANSEL := 0" in C for PIC18F458? I've been reading the manual sheets for like an hour now, and I still couldn't find the answer for that! :oops:

Posted: 02 Feb 2008 16:27
by Charlie
Take a look at page 244. To set I/O to digital: ADCON1 = %00000111

You may have to add CMCON = 7 to turn off comparitors.

Posted: 02 Feb 2008 23:35
by Doctor Aziz
hey, Charlie... thanks a lot for your reply :)
I tried to put ADCON1 = 6, but nothing changed..
And about CMCON, I tired that, but I always get an error message saying:
"Undeclared Identifier [CMCON] in expression"
:?

Posted: 02 Feb 2008 23:55
by Doctor Aziz
Oh, baaaaaack again :D:D
Finally, the LCD works!!
All what I needed to add was: CMCON = 7;
The message I got before was because an error in the Project Setup... I didn't choose the right device; I forgot to choose PIC18F458.
Thanks a lot :)

Posted: 03 Feb 2008 21:08
by Charlie
Glad you got it to work.

Re: LCD initialization for 16F88

Posted: 28 Jul 2012 18:48
by Joe_M
This might be old news for you, but I took your advice, and it pulled me through the last step to get my scrolling data to come across my 2x16 display. I didn't do this on the development board I have, I find that it is all is too much to wrap my head around for a beginner, so it was put together on a breadboard with the 16F88, and the same display that the Picpro7 board has, only I paid $2.xx each to get then shipped from China via Ebay. I didn't want to risk ruining the parts on the development board dues to inexperience.

The other advice to read the application notes is exactly how I like to go, but this one step got past me, so I am happy to find it here in your reply. Thanks Joe


zristic wrote:
Why ANSEL? I use the LCD on RB .
:shock:

I expect that you listen to the advice if you are already asking for it.

PORTB can be analog too, in order to use LCD, you have to make it digital. Datasheet is your friend.

Image

It really costs you nothing to try it out. Just put ANSEL := 0; then compile+program.

Btw, you can still use ADC, but on other pins, not on those which are reserved for LCD.