Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC+LCD problem with displaying

Status
Not open for further replies.

scorrpeio

Full Member level 5
Joined
Dec 26, 2006
Messages
286
Helped
10
Reputation
20
Reaction score
9
Trophy points
1,298
Activity points
3,496
PIC+LCD problem

Hello,
I wrote a codeto display some data on LCD display.
But, I am not getting anything on the display :( :( :(

Code:
#include<p18f4520.h>

#pragma config WDT = OFF

void Delay( void );
void GetLCDCommand(void);
void GetLCDData(void);

void main(void)
{
	int index;
	char A[10];
	TRISA = 0x0;  //PORT A configured in O/P mode
	TRISD = 0x00;
	GetLCDCommand();	

	//Configure Display as 2-line, 8-bit, 5x7-dots
	PORTD = 0x38;
	GetLCDCommand();	
	
	//to get a blinking curser display
	PORTD=0X0F; 
	GetLCDCommand();

	//to clear display
	PORTD=0X01; 
	GetLCDCommand();
	
	while(1)
	{
		PORTD = 0xff;
		GetLCDData();	
	}

}

void Delay( void )
{
	float index;
	for( index = 0; index < 10000; index++ )
	{
		//do nothing
	}

}

void GetLCDCommand(void)
{
	int index;

	PORTA = 0b0010;
	PORTA = 0b0000;
	for (index = 0; index < 1000; index++)
	{
	}
}

void GetLCDData(void)
{
	int index;
	
	PORTA = 0b1010;
	PORTA = 0b1000;
	for (index = 0; index < 1000; index++)
	{
	}

}

The PORT D is for DATA and PORT A is for E(RA1), RS(RA3), R/W(RA2) LCD control bits.

The command logic works fine. But, Data is nowhere displayed on to the screen.

Please suggest me where I am going wrong. What to do to display some data onto the screen.

thank you in advance
 

PIC+LCD problem

Have you tried adjusting the contrast voltage on the LCD?
 

Re: PIC+LCD problem

Make sure PortD is not in PSP Mode. Configured in TRISE

Usually TRISE Bit4 = 0, should be 0 by default. But I like to be sure and cleared it.

The other major problems is timing. You are probably going to fast during the CFG staged. I have to paste a xxxuS delays between the LCD CFG instructions.

You need to check out the LCD data sheet. the timings are given in there.

I do not think this is very slick code, but give you an idea of the delays, it was OK for my application.

You can always slow it down, get it working, them turn the speed up.

Ian
Code:
#define	LCD_STROBE()((LCD_EN = 1), (LCD_EN = 1) , (LCD_EN = 1), (LCD_EN=0))

/* initialise the LCD - put into 4 bit mode */
void lcd_init()
{
	char init_value;

	ADCON1 = 0x06;	// Disable analog pins on PORTA

	init_value = 0x3;
	TRISD=0;
	LCD_RS = 0;
	LCD_EN = 0;
	LCD_RW = 0;
	
	__delay_ms(15);	// wait 15mSec after power applied,
	LCD_DATA	 = init_value;
	__delay_ms(20);
	LCD_STROBE();
	__delay_ms(5);
	LCD_STROBE();
	__delay_ms(5);
	LCD_STROBE();
	__delay_us(200);
	LCD_DATA = ((LCD_DATA & 0xF0) | 2 );	// Four bit mode
	LCD_STROBE();

	lcd_write(0x28); // Set interface length (Function Set)
	lcd_write(0xF); // Display On, Cursor On, Cursor Blink
	lcd_clear();	// Clear screen
	lcd_write(0x6); // Set entry Mode
}

void lcd_write(unsigned char c)
{
	
	__delay_us(80);
	LCD_DATA = ((LCD_DATA & 0xF0) | ( ( c >> 4 ) & 0x0F ));
	LCD_STROBE();
	__delay_us(5);
	LCD_DATA = ((LCD_DATA & 0xF0) | ( c & 0x0F ));
	LCD_STROBE();
}
[/code]
 

Re: PIC+LCD problem

Yes...........
I tried adjustment of contrast

Actually.........during LCD "Command" ...it does something..........first 4 to 5 lines on left hand side of LCD turns on and then automatically fades off

Added after 2 hours 31 minutes:

Hello,

I think I am using 4 bit LCD and programming for 8 bit.
I am bit confused, Kindly let me know...................I am attaching the image of the LCD interfaced with the PIC
 

Have you set the ADCON1 to 0x0F. = All Port A Digital.

ref:https://ww1.microchip.com/downloads/en/DeviceDoc/39631a.pdf
Page 105.

The other PORTA pins are multiplexed with analog
inputs, the analog VREF+ and VREF- inputs and the comparator
voltage reference output. The operation of pins
RA3:RA0 and RA5 as A/D converter inputs is selected
by clearing or setting the control bits in the ADCON1
register (A/D Control Register 1).
Pins RA0 through RA5 may also be used as comparator
inputs or outputs by setting the appropriate bits in the
CMCON register. To use RA3:RA0 as digital inputs, it is
also necessary to turn off the comparators.
The RA4/T0CKI/C1OUT pin is a Schmitt Trigger input.
All other PORTA pins have TTL input levels and full
CMOS output drivers.

I would personally use the display in 4Bit mode and move all the data and control lines on to Port D.

I have attached my last working LCD Code, its for the HiTech Com.
Hope this helps.

Regards
Ian
 

Hi. I can not see inclusion file for LCD in your code like #include lcd.c for example if you are using CCS C. BTW which C compiler are you using? and version. Then I can try helping you with specifics.
 

What about if we change PORTD to (DB7-DB4 LCD to PORTD4-7) and E, RS to Portd2 and protd3 where are the changes in this code you attached M1ANH?

Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top