LCD initialization for 16F88

General discussion on mikroPascal.
Post Reply
Author
Message
terabit
Posts: 16
Joined: 29 Jan 2008 11:31

LCD initialization for 16F88

#1 Post by terabit » 29 Jan 2008 11:42

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

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: LCD initialization for 16F88

#2 Post by zristic » 29 Jan 2008 12:53

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.

terabit
Posts: 16
Joined: 29 Jan 2008 11:31

Re: LCD initialization for 16F88

#3 Post by terabit » 29 Jan 2008 13:19

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.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: LCD initialization for 16F88

#4 Post by zristic » 29 Jan 2008 13:29

You have to set ANSEL to 0, before calling LCD_Config.

terabit
Posts: 16
Joined: 29 Jan 2008 11:31

Re: LCD initialization for 16F88

#5 Post by terabit » 29 Jan 2008 13:51

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.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: LCD initialization for 16F88

#6 Post by zristic » 29 Jan 2008 14:07

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.

terabit
Posts: 16
Joined: 29 Jan 2008 11:31

#7 Post by terabit » 29 Jan 2008 14:22

Super, it work :)
thanks

Doctor Aziz
Posts: 58
Joined: 16 Nov 2007 16:57

#8 Post by Doctor Aziz » 02 Feb 2008 15:29

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:

Charlie
Posts: 2744
Joined: 01 Dec 2004 22:29

#9 Post by Charlie » 02 Feb 2008 16:27

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.
Regards Charlie M.

Doctor Aziz
Posts: 58
Joined: 16 Nov 2007 16:57

#10 Post by Doctor Aziz » 02 Feb 2008 23:35

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"
:?

Doctor Aziz
Posts: 58
Joined: 16 Nov 2007 16:57

#11 Post by Doctor Aziz » 02 Feb 2008 23:55

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

Charlie
Posts: 2744
Joined: 01 Dec 2004 22:29

#12 Post by Charlie » 03 Feb 2008 21:08

Glad you got it to work.
Regards Charlie M.

Joe_M
Posts: 12
Joined: 07 Jul 2012 02:01

Re: LCD initialization for 16F88

#13 Post by Joe_M » 28 Jul 2012 18:48

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.

Post Reply

Return to “mikroPascal General”