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.

c code for 2x8 lcd using pic16f877a

Status
Not open for further replies.

ditch08

Newbie level 6
Newbie level 6
Joined
Jul 9, 2013
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
114
Good day to all.

i'm having a difficult time trying to find out if my 2x8 lcd is functioning well. See, i'm currently testing it with a code which is intended for 2x16 lcd.
I'm using an mplab with hi-tech c compiler and PIC16F877A. I made some modifications at the code, followed the schematic diagrams and its connections but my display has always been blocks. I know testing the lcd with the code not intended for it is wrong but atleast it should have displayed any character right? I also tried sampled codes from hi-tech's sample folder but the result is always the same. So now, i don't know if the code is my problem or the lcd, or maybe both. If i can only test a decent code for this lcd using mplab with hi-tech compiler and still not display a thing, then i can assure to myself to throw away this lcd.. :D

thanks :)
 

Post your code and schematic, Someone will find out the fault

my display has always been blocks

There are 2 things may cause this.

improper contrast & improper initialization. Check these...
 

About the contrast, i connect a potentiometer to adjust it. But for the initialization, i am not sure since i am using a code for 16x2 lcd display. Maybe i'm doin something with that too. that's why i need a simple code to test it. Even the LCDemo sample from hi-tech c compiler was not working.

this is the datasheet i've search in the net, https://www.datasheets360.com/pdf/8012340707842815009?comp=3509
 

Try simulate on PROTEUS and this way you can determine if the problem is at the Hardware or at the Firmware.


+++
 

Try simulate on PROTEUS and this way you can determine if the problem is at the Hardware or at the Firmware.


+++

well, i'm kind of limited to using mplab with hi-tech c compiler right now. But i'll try to download that. Can you give me a link? thanks
 

is it your lcd ?

Yes, that's the one

- - - Updated - - -

i was trying this code from sample folder of the hitech compiler for this LCD:


Code:
#include <htc.h>
#include "lcd.h"

void
main(void)
{
	lcd_init();
	lcd_goto(0);	// select first line
	lcd_puts("1234");
	lcd_goto(0x40);	// Select second line
	lcd_puts("Hello");

	for(;;);
}

Code:
/*
 *	LCD interface example
 *	Uses routines from delay.c
 *	This code will interface to a standard LCD controller
 *	like the Hitachi HD44780. It uses it in 4 bit mode, with
 *	the hardware connected as follows (the standard 14 pin 
 *	LCD connector is used):
 *	
 *	PORTD bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
 *	PORTA bit 3 is connected to the LCD RS input (register select)
 *	PORTA bit 1 is connected to the LCD EN bit (enable)
 *	
 *	To use these routines, set up the port I/O (TRISA, TRISD) then
 *	call lcd_init(), then other routines as required.
 *	
 */

#ifndef _XTAL_FREQ
 // Unless specified elsewhere, 4MHz system frequency is assumed
 #define _XTAL_FREQ 4000000
#endif


#include	<htc.h>
#include	"lcd.h"

#define	LCD_RS RA3
#define	LCD_RW RA2
#define LCD_EN RA1

#define LCD_DATA	PORTD

#define	LCD_STROBE()	((LCD_EN = 1),(LCD_EN=0))

/* write a byte to the LCD in 4 bit mode */

void
lcd_write(unsigned char c)
{
	__delay_us(40);
	LCD_DATA = ( ( c >> 4 ) & 0x0F );
	LCD_STROBE();
	LCD_DATA = ( c & 0x0F );
	LCD_STROBE();
}

/*
 * 	Clear and home the LCD
 */

void
lcd_clear(void)
{
	LCD_RS = 0;
	lcd_write(0x1);
	__delay_ms(2);
}

/* write a string of chars to the LCD */

void
lcd_puts(const char * s)
{
	LCD_RS = 1;	// write characters
	while(*s)
		lcd_write(*s++);
}

/* write one character to the LCD */

void
lcd_putch(char c)
{
	LCD_RS = 1;	// write characters
	lcd_write( c );
}


/*
 * Go to the specified position
 */

void
lcd_goto(unsigned char pos)
{
	LCD_RS = 0;
	lcd_write(0x80+pos);
}
	
/* initialise the LCD - put into 4 bit mode */
void
lcd_init()
{
	char init_value;

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

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

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

i followed the instructions on the pin connections but the result was always block. Do you think it's the controller? :/
 

Try switching on LED back light first so that you can understand if the display is working or not(if connections are tightly connected).
 

Code:
1, add delay in lcd strobe 
    #define	LCD_STROBE	LCD_EN = 1;__delay_ms(1); LCD_EN=0;
2, add delay after each lcd write operation 

  lcd_write(unsigned char c)
  {
	LCD_DATA = ( ( c >> 4 ) & 0x0F );
	LCD_STROBE();
	LCD_DATA = ( c & 0x0F );
	LCD_STROBE;
        __delay_us(100);
}

3, lcd_init()
{

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

	LCD_RS = 0;
	LCD_EN = 0;
	LCD_RW = 0;
	
__delay_ms(15);	// wait 15mSec after power applied,
LCD_DATA	 = 0x3;
LCD_STROBE();
__delay_ms(5);

	LCD_DATA = 2;	// Four bit mode
	LCD_STROBE();
__delay_ms(5);

	lcd_write(0x28); // Set interface length
__delay_ms(5);
	lcd_write(0xF); // Display On, Cursor On, Cursor Blink
__delay_ms(5);
	lcd_write(0x6); // Set entry Mode
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top