Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD Display only showing first character per line

Status
Not open for further replies.

kyru27

New Member
I've the following code based on a Microchip code example:

Code:
#include <p18cxxx.h>
#include "xlcd.h"


#pragma config OSC=INTIO67, FCMEN=ON, WDT=OFF, IESO=ON, XINST=OFF, LVP=OFF

char XLCD_Disp1[] = "1234567890";
char XLCD_Disp2[] = " PIC_UC       ";


void main(void)
{
unsigned char config=0xFF,i=0,addr=0,data=0;
ADCON1 = 0xFF;

TRISD = 0;
PORTD = 0;	
TRISB = 0;				// Port,pin direction configuration
PORTB = 0;
TRISC = 0;
PORTC = 0;
TRISCbits.TRISC7 = 1;  // make sure this pin is input
TRISE=0;

	config = FOUR_BIT  & LINES_5X7;
//********  Configure LCD for four line communication and 5X7 line display *********************************
	OpenXLCD(config);		
		busylcd();		//wait untill LCD controller is busy

//*********** Set the starting address in the LCD RAM for display. This determines the location of display ********	
	SetDDRamAddr(0x80);
		busylcd();		//wait untill LCD controller is busy
	putsXLCD(XLCD_Disp1);			//Display string of text
		busylcd();		//wait untill LCD controller is busy

//********** Set the address in second line for display ****************************************************		
	SetDDRamAddr(0xC1);
		busylcd();		//wait untill LCD controller is busy
	putsXLCD(XLCD_Disp2);					//Display string of text
		busylcd();		//wait untill LCD controller is busy
	putcXLCD(0x5F);					//dsiplay some chrecter
	 	busylcd();		//wait untill LCD controller is busy
		 
	SetDDRamAddr(0x20);
		busylcd();		//wait untill LCD controller is busy

	while(1);					//end of program		
		
}

There's to notice that I've replaced the BusyXLCD usual function for the ones I'm showing below this paragraph, as the schematic circuit has the R/W pin of the LCD pin grounded and, in any case the original BusyXLCD function doesn't seem to work right for me.

Code:
void busylcd(void)
{
	LCDDelay();
	LCDDelay();
	LCDDelay();
}

void LCDDelay(void)
{


int i=0;
for (i=0;i<250;i++);

}


In fact, the original example just modified to have the microcontroller pins that control the display the same as mine , doesn't show anything if not with that portion of code:

Code:
TRISD = 0;
PORTD = 0;	
TRISB = 0;				// Port,pin direction configuration
PORTB = 0;
TRISC = 0;
PORTC = 0;
TRISCbits.TRISC7 = 1;  // make sure this pin is input
TRISE=0;




I understand that the modifications I've introduced could make the strings to display right or wrong but... I don't see any reason how they can make the LCD display the first character ("1" and "P") at the beginning of each line and not more of them, moreover putsXLCD seemingly is working right (I've entered debug mode and I have seen that it looks like it reads the full strings but just displays the first character).

Any idea of what can be happening? I don't really know what to check.

Thanks.
 
Last edited:
Fix the delay first, replace your simple for() loop counter delay with a Delay_uS(200) or something, or even a large delay like Delay_mS(1) etc between each character.

I'm pretty sure the problem is your delay between characters.

Once it is working you can start decreasing the delay (if you need more speed).
 
Thanks for your help.

Fix the delay first, replace your simple for() loop counter delay with a Delay_uS(200) or something, or even a large delay like Delay_mS(1) etc between each character.

I'm pretty sure the problem is your delay between characters.

Once it is working you can start decreasing the delay (if you need more speed).

Tried with both delays but it still keeps the same, anyway you have helped me to realize that it might have to do something with that after writing the first one the display is left in a situation where it cannot display more characters so I'll check WriteDataXLCD function.

I think you'll find that the putsXLCD() routine calls busyXLCD() from within the function..... You may need to edit this source file...

I had taken that already in consideration and I had edited the source file replacing the BusyXLCD first place with my original delay function and in second place with Mr RB's suggestion but doesn't work...


PD: I checked WriteDataXLCD function and, despite it looks to execute exactly in the same way for each character of the string, it writes "1" but not the rest... This is seriously beyond odd...
 
Last edited:
I refuse to use Microchips routines.... I find none work as would like... I have my own LCD routines... 4bit and 8 bit... The are hard coded to the ports I use but if they help I will be glad to post them for you..
 
I refuse to use Microchips routines.... I find none work as would like... I have my own LCD routines... 4bit and 8 bit... The are hard coded to the ports I use but if they help I will be glad to post them for you..

If you could do that I'd be really grateful to you, because I'm seriously going nuts with this thing, I've lost the count of how much time I've spent with this problem. I guess it would be also enough just to post your equivalent to the putsXLCD Microchip function, as, ironically, commands seem to work perfectly with Microchip functions.
 
Thanks a lot for your functions Ian, but... your code also doesn't seem to work in my case.

Anyway I managed to find a solution, though I cannot understand at all how can it be working, it makes absolute no sense for me but, in fact, it works.

I mean, for example to display on first line:T.ACTUAL=-24C, I need the following code.

Code:
#pragma config OSC=INTIO67, FCMEN=ON, WDT=OFF, IESO=ON, XINST=OFF, LVP=OFF

char XLCD_Disp1[] = "C42-:LAUTCA.T";
char XLCD_Disp2[] = " PIC_UC       ";


void main(void)
{
unsigned char config=0xFF,i=0,addr=0,data=0;
ADCON1 = 0xFF;

TRISD = 0;
PORTD = 0;	
TRISB = 0;				// Port,pin direction configuration
PORTB = 0;
TRISC = 0;
PORTC = 0;
TRISCbits.TRISC7 = 1;  // make sure this pin is input
TRISE=0;
ADCON1=255;

	config = FOUR_BIT  & LINES_5X7;
//********  Configure LCD for four line communication and 5X7 line display *********************************
	OpenXLCD(config);		
		busylcd();		//wait untill LCD controller is busy

//*********** Set the starting address in the LCD RAM for display. This determines the location of display ********	
	SetDDRamAddr(0x8C);
		busylcd();		//wait untill LCD controller is busy

	putsXLCD(XLCD_Disp1);			//Display string of text
}

It looks like the putXLCD function displays the next character in a memory position that's before the last it was displayed on, instead of one after it, so to save this I've to invert the string to be shown, and this happens even when in the code of putsXLCD memory positions are being incremented...

I guess there has to be something failing I can't understand as this behaviour isn't normal at all, but whatever, after having wasted a lot of time with this I don't care about making a right code, if I can display what I want I don't mind it makes no logical sense.
 
Last edited:
One thing I haven't checked... The array is a "char" array ( It should reside in data memory ).... You need to check that the compiler isn't making it constant... There is another function putrXLCD(); for rom strings...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top