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 randomly ignore characters

Status
Not open for further replies.

lakis

New Member
Hi guys.
I am trying to connect a lcd 16x2 with a pic18f97j60 although it works , every time i give power to the pic the lcd seems to randomly ignore some of the characters it should display.
For example if i program it to display HELLOGEO , it displays me something
like HEL O EO .
 
Post your software code and hardware schematic.

The two most likely culprits I can think of are a clock rate mismatch, or an interrupt that is occurring the MCU which is pissing off the display routine.
 
1) I think you should first try to debug the program to give a more accurate error of what's happening.

2) Does it display randomly characters even with the same input? If that's the case it's likely to be some false connections that are causing that, though it could be more things, if with the same input you get the same, it's likely a code error. But as I say first it would be needed t debug it.
 
Last edited:
this is my code

Code:
#include<p18f97J60.h>// Include files and definitions for the Processor

#include<xlcd.h>// Include function definitions for the External LCD Library library
#include<delays.h>// Include function definitions for built in Delay routines

/*oi pio kato bibliothikes mporei na sou fanoun xrisimes pio meta ston kodika sou*/
//#include <stdio.h>
//#include <timers.h>
//#include <adc.h>
//#include <math.h>

//#include <stdlib.h> /**********tin aferesa epeidi ekane problima sto itoa. Kanonika auti einai bibliothiki poy exei to idoa mesa tin ebala otan ebla ton ADC kodika Den ipirxe prin. Douleue sosta xvris ayti*/


/*Dilosi Configuration Bits*/
#pragma config WDT=OFF// 
#pragma config DEBUG = ON 
#pragma config XINST= OFF
 #pragma config  FOSC=HS


#define DATALCD PORTE
#define dirDATA TRISE


void LCDdata (unsigned char);
void LCDDelay( void );
void lcdcmd(unsigned char);
void stringtoLCD(unsigned char *m);
unsigned char *itoa (unsigned int value) ;  //itoa (unsigned int value, unsigned char * string)
//unsigned char dataString[10];

void DelaySTRING(void);
void main(void)
{

unsigned char *biginin;


	int i,z,t;
    
   overlay   char data[]="HEllOGEO ";
	static const char data1[]="18F";
 overlay	 char start[]=" PIC";
	unsigned char start1[]="LCD";
	unsigned char start2[]="GEO";
 
	unsigned char newlineadd=0x40; // Line 2 addresses are 40h to 4Fh

    //OSCCON=0x60;//Internal 4MHZ Oscillator
//	ADCON1=0X7F;//Make all ports Digital	

	OpenXLCD( EIGHT_BIT & LINES_5X7 );// Use 8 bit Data, 5x7 pixel Matrix per character
	while( BusyXLCD());// Wait till LCD finishes executing command
	WriteCmdXLCD( CURSOR_ON);// Turn cursor ON
    WriteCmdXLCD(0x80); // Force curson to the begining of 1st line
	while( BusyXLCD() );// Wait till LCD finishes executing command
   WriteCmdXLCD( SHIFT_DISP_LEFT );//Shift Cursor Display Left
	while( BusyXLCD());// Wait till LCD finishes executing command
     
	putsXLCD(data);// Write the String data to the LCD
	WriteCmdXLCD(0b0000110); // 0b0011111
	while( BusyXLCD() );
   WriteCmdXLCD( 0xC0);// Force curson to the begining of 2nd line
  //SetDDRamAddr( newlineadd );
	while( BusyXLCD() );

    putsXLCD(data1);// Write the String data to the LCD
   
  
  	DelaySTRING();

/*********************Apofasi gia address RAM*****************************/
	while( BusyXLCD());// Wait till LCD finishes executing command
	WriteCmdXLCD(0b00000001);// Clear Display
 	while( BusyXLCD() );// Wait till LCD finishes executing command
    WriteCmdXLCD( SHIFT_DISP_LEFT );//Shift Cursor Display Left
	while( BusyXLCD());// Wait till LCD finishes executing command
 	putsXLCD(start);// Write the String data to the LCD
	
	while( BusyXLCD() );
    //SetDDRamAddr( newlineadd );
	while( BusyXLCD() );
    putsXLCD(start1);// Write the String data to the LCD
    DelaySTRING();
    while( BusyXLCD());// Wait till LCD finishes executing command
	WriteCmdXLCD(0b00000001);// Clear Display
 	while( BusyXLCD() );// Wait till LCD finishes executing command
    WriteCmdXLCD( SHIFT_DISP_LEFT );//Shift Cursor Display Left
	while( BusyXLCD());// Wait till LCD finishes executing command
 	putsXLCD(start2);// Write the String data to the LCD
	DelaySTRING();
	while( BusyXLCD() );

/*********************************************/
   // SetDDRamAddr( newlineadd );


	while( BusyXLCD() );
     	


    while(1);// Wait here
}


// As indicated in the C18 libraries manual
// These delays are required for LCD operation

/****************************************************************/
//  DelayFor18TCY  =18 cycles.
/****************************************************************/
void LCDdata (unsigned char value)
{
BusyXLCD();//busylcd();
TRISE = 0;
DATALCD = value;
RS_PIN=1;
RW_PIN=0;
E_PIN=1;
LCDDelay();
E_PIN=0;

}

void LCDDelay(void)
{
int i=0;
for (i=0;i<250;i++);

}
void stringtoLCD(unsigned char *m)
{
unsigned char i;
i = 0;
while(m[i] != 0)
{
LCDdata(m[i]);
i++;
}


}


void DelayFor18TCY(void)
{
Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();
	Nop();

}


/****************************************************************/
//  DelayPORXLCD  =15 ms.
/****************************************************************/

void DelayPORXLCD(void)
{
Delay1KTCYx(15);
}

/****************************************************************/
//  DelayXLCD  =5 ms.
/****************************************************************/

void DelayXLCD(void)
{
Delay1KTCYx(5);
}

/****************************************************************/
//  DelayString  =250 ms.
/****************************************************************/

void DelaySTRING(void)
{
Delay1KTCYx(450);
}
 
I have the problem of random glitches or skips of characters when my enable or strobe is too fast... Put a bigger delay in there around half a second for testing purposes if it works slow it down little by little until you find the fastest safe point!
 
I've had similar things happen when I've changed clock or interrupt frequencies and the 1ms delay between the characters has been too short, it seems to affect some characters more than others, must be something to do with the number of pixels the lcd controller has to change.
 
dr pepper,

The LCD does have instruction times, Clearing the display takes a certain amount of time avg. 36uS's, while writing a character to the screen can take 5uS's...

So You are correct.
:p
 
Correct in princicple, but I think I need to get a more recent datasheet mine says character update takes 1000uS!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top