View previous topic :: View next topic |
Author |
Message |
kbruin79
Joined: 02 Aug 2010 Posts: 30
|
Flex_Lcd 16x2 lcd problems |
Posted: Mon Mar 28, 2011 1:13 pm |
|
|
Hello,
I have used the flex lcd driver provided here:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661
I am using pic16f727 and HDM16216L-S-L30S LCD. It's got the HD44780 controller. compiler version 4.106
And all i get is square blocks on the first line of the LCD.Can you tell me what's wrong?
I modified the pin definition to the following:
Code: | #define LCD_DB4 PIN_A0
#define LCD_DB5 PIN_A1
#define LCD_DB6 PIN_A2
#define LCD_DB7 PIN_A3
#define LCD_E PIN_E1
#define LCD_RS PIN_E3
#define LCD_RW PIN_E2
|
Here is the main code:
Code: |
#include <16F727.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOMCLR
#use delay(clock = 4000000)
#include <flex_lcd.c>
//---------------------------------------------------
// Main
//---------------------------------------------------
void main()
{
SETUP_ADC_PORTS(NO_ANALOGS);
lcd_init(); // Always call this first.
while(1)
{
lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");
delay_ms(500);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 28, 2011 1:46 pm |
|
|
Quote: | #define LCD_DB4 PIN_A0
#define LCD_DB5 PIN_A1
#define LCD_DB6 PIN_A2
#define LCD_DB7 PIN_A3
#define LCD_E PIN_E1
#define LCD_RS PIN_E3
#define LCD_RW PIN_E2 |
Pin E3 is an "input only" pin. You can't use it for the LCD.
Choose a different pin.
To see the pin capabilities, download the 16F727 data sheet:
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en533510
Look in the "Device Overview" section near the front of the data sheet.
Look at this table:
Quote: | TABLE 1-1: PIC16F72X/PIC16LF72X PINOUT DESCRIPTION |
It tells you if a pin can be "General purpose i/o" or if it's a "General
purpose input" (i.e., input only). |
|
|
kbruin79
Joined: 02 Aug 2010 Posts: 30
|
|
Posted: Mon Mar 28, 2011 4:47 pm |
|
|
PCM programmer wrote: | Quote: | #define LCD_DB4 PIN_A0
#define LCD_DB5 PIN_A1
#define LCD_DB6 PIN_A2
#define LCD_DB7 PIN_A3
#define LCD_E PIN_E1
#define LCD_RS PIN_E3
#define LCD_RW PIN_E2 |
Pin E3 is an "input only" pin. You can't use it for the LCD.
Choose a different pin.
To see the pin capabilities, download the 16F727 data sheet:
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en533510
Look in the "Device Overview" section near the front of the data sheet.
Look at this table:
Quote: | TABLE 1-1: PIC16F72X/PIC16LF72X PINOUT DESCRIPTION |
It tells you if a pin can be "General purpose i/o" or if it's a "General
purpose input" (i.e., input only). |
Thank you for your reply. I actually have pin E0, E1, E2 wired to E, R/W, RS
So I modified the code to reflect that:
Code: |
#define LCD_E PIN_E0
#define LCD_RS PIN_E2
#define LCD_RW PIN_E1
|
Now I get two lines on the LCD showing all black squares.
Is there anything else code wise that is preventing the LCD to work? I checked all the connections and everything looks fine. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 28, 2011 5:20 pm |
|
|
According to the LCD data sheet, the contrast voltage on pin 3 of the LCD
should be 0.6 volts. What voltage do you currently have on that pin ?
http://www.hantronix.com/down/16216ls.pdf |
|
|
kbruin79
Joined: 02 Aug 2010 Posts: 30
|
|
Posted: Mon Mar 28, 2011 6:04 pm |
|
|
PCM programmer wrote: | According to the LCD data sheet, the contrast voltage on pin 3 of the LCD
should be 0.6 volts. What voltage do you currently have on that pin ?
http://www.hantronix.com/down/16216ls.pdf |
I had it at 0.57v and the display was barely visible so I lowered it to 0.25v and the contrast looks much better. But I still get all solid blocks on both lines. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 28, 2011 9:01 pm |
|
|
Your version has a bug in the start-up code and in setup_analog_ports().
It doesn't make all i/o ports into digital i/o pins. Some of them are left
in the power-on-reset state, which is "all analog" pins. You can fix it by
adding the following function above main(), and then call it at the start
of main(). Example:
Code: |
void make_all_pins_digital(void)
{
#byte ANSELA = getenv("SFR:ANSELA")
#byte ANSELB = getenv("SFR:ANSELB")
#byte ANSELD = getenv("SFR:ANSELD")
#byte ANSELE = getenv("SFR:ANSELE")
ANSELA = 0;
ANSELB = 0;
ANSELD = 0;
ANSELE = 0;
}
//================================
void main()
{
make_all_pins_digital();
// SETUP_ADC_PORTS(NO_ANALOGS); |
|
|
|
kbruin79
Joined: 02 Aug 2010 Posts: 30
|
|
Posted: Mon Mar 28, 2011 9:26 pm |
|
|
PCM programmer wrote: | Your version has a bug in the start-up code and in setup_analog_ports().
It doesn't make all i/o ports into digital i/o pins. Some of them are left
in the power-on-reset state, which is "all analog" pins. You can fix it by
adding the following function above main(), and then call it at the start
of main(). Example:
Code: |
void make_all_pins_digital(void)
{
#byte ANSELA = getenv("SFR:ANSELA")
#byte ANSELB = getenv("SFR:ANSELB")
#byte ANSELD = getenv("SFR:ANSELD")
#byte ANSELE = getenv("SFR:ANSELE")
ANSELA = 0;
ANSELB = 0;
ANSELD = 0;
ANSELE = 0;
}
//================================
void main()
{
make_all_pins_digital();
// SETUP_ADC_PORTS(NO_ANALOGS); |
|
Awesome! you're the best PCM ! now it's working Thank you ! |
|
|
kbruin79
Joined: 02 Aug 2010 Posts: 30
|
lcd_putc( ) |
Posted: Tue Mar 29, 2011 5:24 pm |
|
|
How do I output an integer variable to the LCD. lcd_putc() only outputs a char and printf() requires a serial connection.
ex:
Code: |
int x;
lcd_putc(x);
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
kbruin79
Joined: 02 Aug 2010 Posts: 30
|
|
Posted: Wed Mar 30, 2011 11:42 am |
|
|
Great, Thank you. |
|
|
|