electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Interfacing Hitachi HD44780 2x16 LCD with PIC 16F877


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Interfacing Hitachi HD44780 2x16 LCD with PIC 16F877
Author Message
bjerkely



Joined: 26 May 2004
Posts: 92
Helped: 1
Location: Turkiye


Post17 Dec 2005 19:52   

hd44780 pic


I'm using Hi-tech PicC-lite compiler,it comes with some sample C codes.The routines in LCD.c work quite fine for 16F84 but when I change to 16F877 with the same pin connections nothing promts on LCD. The code is below....

Thanx in advance...
/*
* LCD interface header file
* See lcd.c for more info
*/

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

extern void lcd_write(unsigned char);

/* Clear and home the LCD */

extern void lcd_clear(void);

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

extern void lcd_puts(const char * s);

/* Go to the specified position */

extern void lcd_goto(unsigned char pos);

/* intialize the LCD - call before anything else */

extern void lcd_init(void);

extern void lcd_putch(char);

/* Set the cursor position */

#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)


LCD.C
/*
* 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):
*
* PORTB bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
* PORTA bit 2 is connected to the LCD RS input (register select)
* PORTA bit 3 is connected to the LCD EN bit (enable)
*
* To use these routines, set up the port I/O (TRISA, TRISB) then
* call lcd_init(), then other routines as required.
*
*/

#include <pic.h>
#include "lcd.h"
#include "delay.h"

static bit LCD_RS @ ((unsigned)&PORTA*8+2); // Register select
static bit LCD_EN @ ((unsigned)&PORTA*8+3); // Enable

#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)
{
PORTB = (PORTB & 0xF0) | (c >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) | (c & 0x0F);
LCD_STROBE;
DelayUs(40);
}

/*
* Clear and home the LCD
*/

void
lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
DelayMs(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
PORTB = (PORTB & 0xF0) | (c >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) | (c & 0x0F);
LCD_STROBE;
DelayUs(40);
}


/*
* 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(void)
{
LCD_RS = 0; // write control bytes
DelayMs(15); // power on delay
PORTB = 0x3; // attention!
LCD_STROBE;
DelayMs(5);
LCD_STROBE;
DelayUs(100);
LCD_STROBE;
DelayMs(5);
PORTB = 0x2; // set 4 bit mode
LCD_STROBE;
DelayUs(40);
lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font
lcd_write(0x08); // display off
lcd_write(0x0F); // display on, blink curson on
lcd_write(0x06); // entry mode
}
Back to top
C-Man



Joined: 19 Jul 2001
Posts: 1235
Helped: 73


Post18 Dec 2005 9:58   

hitachi hd44780


On the 16F877 PORTA is switched to analog input on reset.

If you want to use it as digital I/O you must put this into your init routine:
ADCON1=6;

Check the datasheet ...

hope this helps and best regards
Back to top
Google
AdSense
Google Adsense




Post18 Dec 2005 9:58   

Ads




Back to top
Jack// ani



Joined: 02 Dec 2004
Posts: 488
Helped: 25


Post18 Dec 2005 17:59   

hd44780 2x16


Hi,

I need C routine in 8bit mode....for 16f84!! Any help...

Thanks
Back to top
arash_micro



Joined: 25 Jan 2005
Posts: 92


Post18 Dec 2005 20:33   

16f877 lcd


Hi all.
I try to make volt meter with ht-picc on lcd.I solve my problem with lcd but i cant use adc in 10 bit. can you help me.
Here is my project with some change.



Sorry, but you need login in to view this attachment

Back to top
bjerkely



Joined: 26 May 2004
Posts: 92
Helped: 1
Location: Turkiye


Post19 Dec 2005 9:59   

pic hd44780


C-Man wrote:
Quote:
If you want to use it as digital I/O you must put this into your init routine:
ADCON1=6;


I set the ADCON1 register to 6 but it's no good,nothing promts again...
May anyone give me a link to assembly LCD routines...
Regards
Back to top
C-Man



Joined: 19 Jul 2001
Posts: 1235
Helped: 73


Post19 Dec 2005 10:51   

lcd 2x16 hitachi


Are you sure the mico is working correctly?

What are your fuse settings?

Which type of oscillator are you using?

Have you tried to get a simle flashing led programm going?

best regards
Back to top
arash_micro



Joined: 25 Jan 2005
Posts: 92


Post19 Dec 2005 21:23   

hitachi hd44780 lcd


Hi all.
I make 8-ch voltmeter with ht-picc.it works good in proteuse But have some error in real.it works with 4meg xtal and when i change it to 24 meg even lcd doesn't work.
can you help me to change the xtal.
Thanks



Sorry, but you need login in to view this attachment

Back to top
bjerkely



Joined: 26 May 2004
Posts: 92
Helped: 1
Location: Turkiye


Post20 Dec 2005 0:54   

hitachi hd44780 lcd controller


I had the same problem,try to change the crystal type in your configuration register
like that __config _HS_OSC & _WDT_OFF & _PWRTE_ON

This helped me...
Back to top
arash_micro



Joined: 25 Jan 2005
Posts: 92


Post20 Dec 2005 9:00   

16f877 lcd interface


I have another problem now.when i turn my pic on, the lcd doesn't turn on (in 90% of times),is there another setting t oset this.
Back to top
gidimiz



Joined: 03 Feb 2005
Posts: 428
Helped: 77


Post20 Dec 2005 15:01   

4 bit lcd c code for 16f877a


Hi,

There are few ways to see how to solve your problems with the LCD.
1. Go to Microchip web site and look under the App Note for LCD. There you will see few notes on how to do this. http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1490&filterID=416

2. Again in the Microchip web site, go to the PICDEM2+ EV Board directory, and download the source code. It is used with the F877 and it demonstrates the LCD. In the User manual you will also find the Electronic circuit that you will have to compare to your design so the output pines will match.
Direct link: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010072&part=DM163022

3. Last but not list, is a very useful web site ( Its not Microchip web site ): www.microchipc.com

If you found my answer useful, click on the button that says Helped me. ( NO points will be taken from you! )


Good luck.
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Interfacing Hitachi HD44780 2x16 LCD with PIC 16F877
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Interfacing HD44780 LCD with PIC 16F877 (7)
AT89C51 + 2x16 Lines LCD (HD44780) module (4)
Need Help for Hitachi 2x16 LCD Display (3)
c code for character display in 2X16 lcd using "16F877 (1)
jpeg camera interfacing with pic 16F877 (2)
Visual basic 6 interfacing with PIC 16f877 microcontroller (2)
problem with controlling LCD 16x2 with PIC 16f877 (6)
help me how to use graphical lcd with pic 16f877 (2)
Interfacing msp430135 whith a 5V 2x16 character lcd screen (5)
PIC LCD HD44780 help (1)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS