NEED HELP LCD Problem

General discussion on mikroC.
Post Reply
Author
Message
M.Farag
Posts: 44
Joined: 22 Feb 2008 18:05

NEED HELP LCD Problem

#1 Post by M.Farag » 12 Apr 2008 16:37

I have PIC 18F452 connected with LCD 20*4
LCD TYPE:
http://www.topwaydisplay.com/Pub/Manual ... Rev0.1.pdf
Problem :
LCD write only on the first row and third row i don't know why ??
Code :

Code: Select all

void main ()
{
      TRISA = 0x00;                  // PORTA is output
      TRISE = 0x00;
      TRISC = 0x00;
      TRISD = 0x00;                  // PORTD is output
      PORTA = 0x00;
      PORTE = 0x00;
      PORTC = 0x00;
      PORTD = 0x00;
      ADCON1 = 0b10000111;             // Enable digital I/O

      PORTC=0X00;
      PORTA=0XFF;
      Lcd8_Config(&PORTE,&PORTD,2,1,0,7,6,5,4,3,2,1,0);
      /*
         e2 ==> RS
         e1 ==> EN
         e0 ==> WR
         D7 ==> D7
         D6 ==> D6
         D5 ==> D5
         D4 ==> D4
         D3 ==> D3
         D2 ==> D2
         D1 ==> D1
         D0 ==> D0
      */
      PORTC=0XFF;
      PORTA=0X00;
      Lcd8_Cmd(LCD_CURSOR_OFF);
      PORTC=0XFF;
      PORTA=0X00;
      Lcd8_Cmd(LCD_CLEAR);
      PORTC=0XFF;
      PORTA=0X00;
      Lcd8_Out(1,1,"Mikro");
      PORTC=0X00;
      PORTA=0XFF;
      Lcd8_Out(2,1,"Electronika");
      PORTC=0XFF;
      PORTA=0X00;
      Lcd8_Out(3,1,"Mikro C");
      PORTC=0X00;
      PORTA=0XFF;
      Lcd8_Out(4,1,"I need Help");
      PORTC=0XFF;
      PORTA=0X00;
      PORTC=0X00;
      PORTA=0Xff;
      while(1)
      {
      
      }
}
 
sorry but really i am in bad need for help

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#2 Post by xor » 12 Apr 2008 16:55

Look under mikroC FAQ about 4 line LCD's. Also try the following method (if your LCD is HD44780 or KS0066 compatible) to set the cursor screen address before writing strings/characters:

Code: Select all

      LCD8_CMD(128);
      Lcd8_Out_CP("Mikro");
      PORTC=0X00;
      PORTA=0XFF;

      LCD8_CMD(192);
      Lcd8_Out_CP("Electronika");
      PORTC=0XFF;
      PORTA=0X00;

      LCD8_CMD(148);
      Lcd8_Out_CP("Mikro C");
      PORTC=0X00;
      PORTA=0XFF;

      LCD8_CMD(212);
      Lcd8_Out_CP("I need Help"); 
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

M.Farag
Posts: 44
Joined: 22 Feb 2008 18:05

#3 Post by M.Farag » 12 Apr 2008 20:01

still writing on first and third line only !!

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#4 Post by xor » 12 Apr 2008 20:19

Those are he same addresses as your shown in your datasheet. Adjust your contrast to be sure.

The LCD8() library's Config routine is causing the problem. There will have to be a comparison to see if there is a compatibility problem between HD44780 (the library's target controller) and the ST7066U (your controller) initiation routines in 8-bit mode to be sure.

EDIT:
At a glance and no tests, the HD44780, KS0066, and ST7066, each have slightly different initiation routines. Right now, LCD8() initiation is written for the HD44780 and for the time being creates the problem you are observing.
Last edited by xor on 12 Apr 2008 21:21, edited 1 time in total.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

M.Farag
Posts: 44
Joined: 22 Feb 2008 18:05

#5 Post by M.Farag » 12 Apr 2008 21:13

i am really thankfull Xor
could you plz help me by telling me what should i do now ??

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#6 Post by xor » 12 Apr 2008 21:27

It is nothing you or I can change with the existing library without rewriting the entire library or at least the LCD8_Config().
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#7 Post by xor » 13 Apr 2008 01:24

Below is a quickie LCD8 library that can work with your processor... but you have to test it out to be sure it works since I don't have an LCD with your processor.

Code: Select all

//***********************************************
//*****
//*****   LCD8 For ST7066U Character LCD & PIC18
//*****     By Warren Schroeder  April 12, 2008
//*****       Using mikroC 7.03 
//*****
//***********************************************       
//
//   You must define your control pins and also the dataport
//   The data port is <0..7> for LCD's <D0..D7>
//   
//   Prototypes:
//
//   LCD8INI()  
//         must be called first and only once.
//   LCD8CMD(unsigned short cmdata)   
//         same function as LCD8_CMD() in the standard library
//   LCD8CHR(unsigned short cmd, unsigned char chr) 
//         pass screen position address and single character
//   LCD8STR(unsigned short cmd, unsigned int *chrstr)
//         pass screen position address and string
//

#define DPort  LATD
#define _RS_   LATE.F2
#define _EN_   LATE.F1
#define _RW_   LATE.F0

unsigned int FSR_2 absolute 0x0FD9;

void LCD8CMD(unsigned short cmdata) {
                  DPort = cmdata ;
                  _EN_ = 1       ;
                  Delay_us(1)    ;
                  _EN_ = 0       ;
                  if(cmdata > 2)
                     Delay_us(40);
                  else
                     Delay_ms(2) ;
}

void LCD8CHR(unsigned short cmd, unsigned char chr) {
                  LCD8CMD(cmd)  ;
                  _RS_ = 1      ;
                  LCD8CMD(chr)  ;
                  _RS_ = 0      ;
}

void LCD8STR(unsigned short cmd, unsigned int *chrstr) {
                 LCD8CMD(cmd)   ;
                 FSR_2 = chrstr ;
                 _RS_ = 1       ;
                 while (INDF2 !=0) {
                    LCD8CMD(POSTINC2);
                 }
                 _RS_ = 0       ;
}

void LCD8INI() {
                  Delay_ms(40)  ;
                  _RW_ = 0      ;
                  _EN_ = 0      ;
                  _RS_ = 0      ;
                  LCD8CMD(48)   ;
                  LCD8CMD(56)   ;
                  LCD8CMD(15)   ;
                  LCD8CMD(1)    ;
                  LCD8CMD(6)    ;
}


void main () {

      TRISA = 0x00;                  // PORTA is output
      TRISE = 0x00;
      TRISC = 0x00;
      TRISD = 0x00;                  // PORTD is output
      LATA  = 0x00;
      LATE  = 0x00;
      LATC  = 0x00;
      LATD  = 0x00;
      ADCON1 = 6;                    // Enable digital I/O
      
      LCD8INI();
      Lcd8Cmd(LCD_CURSOR_OFF);
      Lcd8Cmd(LCD_CLEAR);
      Lcd8STR(128,"Mikro");
      Lcd8STR(192,"Electronika");
      Lcd8STR(148,"Mikro C");
      Lcd8STR(212,"I need Help");
      while(1)
      {

      }
}
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

M.Farag
Posts: 44
Joined: 22 Feb 2008 18:05

#8 Post by M.Farag » 13 Apr 2008 02:28

I tested it and it's Working
Thanks thanks thanks Xor you helped me alot thanks

M.Farag
Posts: 44
Joined: 22 Feb 2008 18:05

#9 Post by M.Farag » 25 May 2008 11:37

Xor can i modify the code to be 4 bit interface only or i can't ??
and if i can how could i do that ??

potain
Posts: 1
Joined: 18 Nov 2010 18:55

Re: NEED HELP LCD Problem

#10 Post by potain » 18 Nov 2010 19:00

hello,
I'm new to the forum and want to thank the great community of electronica that is developed here. I found the forum because I am a porjecot which includes a PIC18F452 and Powertip 16x2 LCD controller with pc1602 st7066.
the problem and I used the code over but this does not work. someone could show me the wiring diagram? may be the pic I'm using?

thanks in advance

Post Reply

Return to “mikroC General”