Lcd_Init doesn't work but Lcd_Custom_Config does...

General discussion on mikroC.
Post Reply
Author
Message
amrbekhit
Posts: 95
Joined: 05 Jul 2007 12:55
Contact:

Lcd_Init doesn't work but Lcd_Custom_Config does...

#1 Post by amrbekhit » 25 Nov 2007 13:47

Hello all,

I've been having a bit of a problem with a PIC18F4550 and the LCD. I've tried to get some text out using the Lcd_Init command, but it hasn;t worked at all. Then, I tried to use the Lcd_Custom_Config, using the same pins as Lcd_init does, and it works fine! Any ideas?

Here's the code:

Code: Select all

void main(void)
{
	CMCON=0x07;
	ADCON1=0x0F;

//	Lcd_Init(&PORTD);
//	Lcd_Cmd(LCD_CLEAR);
//	Lcd_Cmd(LCD_CURSOR_OFF);
//	Lcd_Out(1,1,"Stepper test");

	Lcd_Custom_Config(&PORTD,7,6,5,4,&PORTD,2,0,3);
	Lcd_Custom_Cmd(Lcd_CLEAR);           
	Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
  	Lcd_Custom_Out(1, 1, "This is nice");

	
	while(1)
	{

	}
}
Thanks

--Amr

pwdixon
Posts: 1431
Joined: 13 Apr 2005 11:14
Location: UK

#2 Post by pwdixon » 25 Nov 2007 18:07

I had a problem with this in version 5 and moved over to the custom lcd library for that very reason, haven't tried it again in V6 or V7.

amrbekhit
Posts: 95
Joined: 05 Jul 2007 12:55
Contact:

#3 Post by amrbekhit » 25 Nov 2007 19:07

I'm using v7.0.0.3, so it looks like this problem has been around for a while.

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

#4 Post by xor » 25 Nov 2007 20:29

The standard LCD library works fine with the 18F4550. Since you are using the '4550 you must be sure your configurations settings are correct. Also LCD_INIT() requires a specific pinout:
  • PORTD.F2 = RS
    PORTD.F3 = E
    PORTD.F4 = D4
    PORTD.F5 = D5
    PORTD.F6 = D6
    PORTD.F7 = D7

    RW, and D0..D3 are connected to GND.
This code from the example works perfectly with my '4550 @ 10MHz:

Code: Select all

char *text = "mikroC_123";

void main() {
  
  
  Lcd_Init(&PORTD);         // Initialize LCD connected to PORTD
  Lcd_Cmd(LCD_CLEAR);       // Clear display
  Lcd_Cmd(LCD_CURSOR_OFF);  // Turn cursor off
  Lcd_Out(1,1, text);       // Print text to LCD, 2nd row, 1st column
  Lcd_Chr_CP('@');
  Lcd_Chr(1,14, '#');
  Lcd_Cmd(LCD_SECOND_ROW);
  Lcd_Out_CP(text);

  while (1);                // endless loop
}//~!
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

amrbekhit
Posts: 95
Joined: 05 Jul 2007 12:55
Contact:

#5 Post by amrbekhit » 27 Nov 2007 00:55

Thanks for your reply, xor.

I haven't had much luck with these routines. I just gave it another go now. I uncommented the Lcd_Custom_Config routines and brought back the LCd_init routines. The text did indeed display on the screen after I programmed the chip, but as soon as I removed power and reapplied it again, the screen just wouldn't initialize no matter what I did. Reprogramming it had no effect.

Since the PIC is doing other things as well (USB comms, driving motors) I'm pretty sure the config bits and hardware are in working order, which is what leads me to think that the Lcd_Init routines must not have a completely fool proof initialization routines, cos Lcd_Custom_Config works just fine.

--Amr

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

#6 Post by Charlie » 27 Nov 2007 01:32

Hi amrbekhit,

Have you tried a small delay after LCD_Init?
Regards Charlie M.

amrbekhit
Posts: 95
Joined: 05 Jul 2007 12:55
Contact:

#7 Post by amrbekhit » 27 Nov 2007 20:49

Hi Charlie,

Thanks for your reply. I added a 1s delay before and after the initialization, but unfortunately this did not improve the situation. I'm going to submit this as a support request, perhaps one of the mikro guys can have a look at it, although I still appreciate suggestions on the forum too.

--Amr

pwdixon
Posts: 1431
Joined: 13 Apr 2005 11:14
Location: UK

#8 Post by pwdixon » 18 Dec 2007 16:39

Why not use the custom functions but set it up just like the standard LCD functions ie. using the same ports/bits?

NANO PRO
Posts: 24
Joined: 02 Sep 2007 18:01
Location: Viet Nam
Contact:

#9 Post by NANO PRO » 20 Dec 2007 05:11

I worked like with P16F877A:

Code: Select all

{
PORTB=0; // Output to LCD
Lcd_Init(&PORTB);
Lcd_Cmd(LCD_CLEAR);
Lcd_Cmd(LCD_CURSOR_OFF);

Lcd_Out(2,2,"NANO PRO");
}
Okie
Dear.
NANO PRO

rodentje
Posts: 48
Joined: 10 Jun 2007 21:45

#10 Post by rodentje » 20 Dec 2007 07:44

This is a piece of code for the BoostC compiler which I wrote recently. It drives the LCD on a EasyPIC4 board:

Code: Select all

#ifndef   LCDDRIVER_H
#define   LCDDRIVER_H

/** I N C L U D E S **********************************************************/
#include	<system.h>

/** D E F I N I T I O N S ****************************************************/
volatile unsigned char LCD@LATD;

volatile bit RS@LATD.2;
volatile bit E@LATD.3;

#define  LCDTris trisd

/** P R O T O T Y P E S ******************************************************/
//-- public prototypes -------------------------------------------------------/
void clearLCD ( void );
void sendLCDChar ( char c , char row , char position );
void sendLCDString ( char* str , char row , char position );
void initLCD ( void );

//-- private prototypes ------------------------------------------------------/
void sendLCD ( char data , char rs );

#endif

Code: Select all

/** I N C L U D E S **********************************************************/
#include  	"lcdDriver.h"

/** D E C L A R A T I O N S **************************************************/
/******************************************************************************
 * Function:        void clearLCD (void)
 *
 * Input:           None
 *
 * Output:          None
 *
 * Overview:        Calls the function sendLCD to send the right command to 
 *					clear the LCD.
 *
 *****************************************************************************/
void clearLCD (){
     sendLCD ( 0x01 , 0 );
     delay_ms(2);
}

/******************************************************************************
 * Function:        void sendLCD ( char data , char rs )
 *
 * Input:           char data: the data to be send to the display
 *					char rs  : '1' means character, '0' means command
 *
 * Output:          None
 *
 * Overview:        Sends a character or command to the display.
 *
 *****************************************************************************/
void sendLCD ( char data , char rs ){
     LCD = data & 0xF0;
     RS = rs;
     E = 1;
     E = 0;
     delay_10us(4);
     LCD = data << 4;
     RS = rs;
     E = 1;
     E = 0;
     delay_10us(4);
}

/******************************************************************************
 * Function:        void sendLCDChar ( char c , char row , char position )
 *
 * Input:           char c		  :	The character to be displayed
 *					char row	  : The row on which the character should be 
 *								   	displayed.
 *					char position : The position where the character should be
 *								   	displayed.
 *
 * Output:          None
 *
 * Overview:        Puts a character on the display on a specified position 
 *					using the function sendLCD
 *
 *****************************************************************************/
void sendLCDChar ( char c , char row , char position ){
     // Check if given position is valid
     if( row<0 || row>1 || position<0 || position>15 )
		 return;
     if( row == 0 ){
         position = 0x80 + position;
     } else if( row == 1 ){
         position = 0xC0 + position;
     }
     sendLCD ( position , 0 );
     sendLCD ( c , 1 );
}

/******************************************************************************
 * Function:        void sendLCDString ( char* str , char row , char position )
 *
 * Input:           char* str: Pointer to an array of characters which must be
 *							   displayed. Last character should be 0 or '\n'.
 *					char row : Row on which the string of characters must be
 *							   displayed.
 *					char position : Position where the string of characters 
 *									must be displayed.
 *
 * Output:          None
 *
 * Overview:        Puts a string on the display on a specified position 
 *					using the function sendLCD
 *
 *****************************************************************************/
void sendLCDString ( char* str , char row , char position ){
     // Check if given position is valid
     if( row<0 || row>1 || position<0 || position>15 )
		 return;
     if( row == 0 ){
         position = 0x80 + position;
     } else if( row == 1 ){
         position = 0xC0 + position;
     }
     int ptr = 0;
     sendLCD ( position , 0 );
     while (str[ptr] != 0 && str[ptr] != '\n')
           sendLCD ( str[ptr++] , 1 );
}

/******************************************************************************
 * Function:        void initLCD (void)
 *
 * Input:           None
 *
 * Output:          None
 *
 * Overview:        Initiates the LCD display by sending the necessary commands
 * 					using the function sendLCD
 *
 *****************************************************************************/
void initLCD (){
	LCDTris = 0;
    char a;
	delay_ms(20);
    for ( a = 0 ; a < 3 ; a++ )
    {
        sendLCD ( 0x20 , 0 );
        delay_ms(6);
    }
    sendLCD ( 0x28 , 0 );
    sendLCD ( 0x01 , 0 );
    delay_ms(2);
    sendLCD ( 0x0C , 0 );
    sendLCD ( 0x06 , 0 );
}
This should be very easy to translate to the MikroC compiler, so good luck with it !

Best regards,
RoDeNtJe
It's nice to be important, but it's more important to be nice !

RobOnk12
Posts: 25
Joined: 09 Dec 2010 03:31

Re: Lcd_Init doesn't work but Lcd_Custom_Config does...

#11 Post by RobOnk12 » 20 Jan 2011 10:47

Looking for assistance.

I just bought a dspicbig6 board with a dspic30F6014a micro. I'm trying to get familiar with the board and so far all is going well. However, I cannot get the 2x16 lcd to display anything yet. When looking at the various examples, I see there are several methods of writing to the lcd. My questions are,

What is the simplest way to write something to the lcd?
What is the purpose of having more than one method of writing to the lcd?

A simple file that outputs something to the lcd display would be great.

Post Reply

Return to “mikroC General”