Sign in

username:

password:



Not a member?

Search lpc2000



Search tips

Subscribe to lpc2000



lpc2000 by Keywords

2106 | ADC | ARM7 | Atmel | Bootloader | CAN | CrossStudio | CrossWorks | DDS | ECos | Ethernet | ETM | FIFO | FLASH | FPGA | GCC | GDB | GNU | GNUARM | GPIO | I2C | IAP | IAR | JTAG | Kickstart | LCD | Linux | LPC | LPC-E2294 | LPC2000 | LPC2100 | LPC2104 | Lpc2106 | Lpc210x | LPC2114 | LPC2119 | LPC2124 | LPC2129 | Lpc2138 | LPC213x | LPC21xx | LPC2210 | LPC2212 | LPC2214 | LPC2292 | LPC2294 | LPC2xxx | LPC3128 | MCB2100 | Olimex | Philips | PWM | Rowley | RTC | RTOS | SPI | SSP | UART | UART0 | UART1 | ULINK | USB | Watchdog | Wiggler

Sponsor

controlSUITE™ software
Comprehensive.
Intuitive.
Optimized.

Real-world software for real-time control. Details Here!

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | LPC2000 | HD44780 Initialisation (20x4 display in 4-bit mode)

Discussion group dedicated to the Philips LPC2000 family of ARM MCUs

HD44780 Initialisation (20x4 display in 4-bit mode) - Kevin Townsend - Oct 4 18:36:16 2008

I've spent the last couple day trying to get a 20x4 character HD44780=20
LCD working with my Olimex H2148, and have poured over at least 5=20
different examples (including the one in the files section here)=20
trying to put together a basic class to work with 44870 LCD.

I'm almost certain I have the board wired up properly (including &=20
10K resistor for contrast on pin 3), and I've read through the entire=20
Hitachi datasheet and double-checked my command codes, comparing them=20
with other people's examples, but whatever I feed the board it=20
doesn't seem to do anything. Line 1 and 3 have solid blocks, and=20
line 2 and 4 have nothing.

It must be something with the way the commands are sent, but I don't=20
see it myself. If anyone has any experience, I'd certainly=20
appreciate another set of eyes and someone else's experience. My=20
guess is I screwed something up with either 'hd77480_Send_4Bits'=20
or 'hd77480_SendCommand' with the 4-bit business..

NOTE: The code below uses JCWren's (excellent) lpc210x.h, which isn't=20
included below, and the delay.h file from the lpc2000 group Files=20
section.

Example:
--------
hd44780_Init();
hd44780_SendCommand(HD44780_DISPON_CURSBLINKING);
hd44780_SendCommand(HD44780_CLEAR_DISPLAY);
hd44780_DisplayString("Test Test\n");
hd44780_SendCommand(HD44780_MOVE_CURSOR_DOWN);
hd44780_DisplayString("Test Test\n");

*********** START 44780.h ******************************
typedef enum
{
PIN_RS =3D 0x00080000, // 1.19 Register Select
PIN_RW =3D 0x00100000, // 1.20 Read/Write
PIN_E =3D 0x00200000, // 1.21 Enable
PIN_D4 =3D 0x00400000, // 1.22 Data 4
PIN_D5 =3D 0x00800000, // 1.23 Data 5
PIN_D6 =3D 0x20000000, // 1.18 Data 6 (1.24 is used on the=20
Olimex H2148)
PIN_D7 =3D 0x02000000 // 1.25 Data 7
}=20
hd44780_Pins_t;

typedef enum
{
HD44780_CLEAR_DISPLAY =3D 0x01, // Clear LCD=20
Display 1.52 mS
HD44780_HOME =3D 0x02, // Move the cursor to=20
the home position 1.52 mS
HD44780_DISPON =3D 0x0C, // Turn display on=20
with no cursor and no blink 37 =B5S
HD44780_DISPON_CURSUNDERNEATH =3D 0x0E, // Turn display on,=20
with cursor under 37 =B5S
HD44780_DISPON_CURSBLINKING =3D 0x0F, // Turn display on,=20
with blinking 37 =B5S
HD44780_DISPOFF =3D 0x08, // Turn display=20
off 37 =B5S
HD44780_ENTRYMODE_INCR_NOSHIFT =3D 0x06, // Auto increment=20
cursor position, no shift 37 =B5S (Default entry mode)
HD44780_ENTRYMODE_INCR_SHIFT =3D 0x07, // Auto increment=20
cursor position, shift text 37 =B5S
HD44780_ENTRYMODE_DECR_NOSHIFT =3D 0x04, // Auto decrement=20
cursor position, no shift 37 =B5S
HD44780_ENTRYMODE_DECR_SHIFT =3D 0x05, // Auto decrement=20
cursor position, shift text 37 =B5S
HD44780_MOVE_CURSOR_RIGHT =3D 0x14, // Shift cursor one=20
character to the right 37 =B5S
HD44780_MOVE_CURSOR_LEFT =3D 0x10, // Shift cursor one=20
character to the left 37 =B5S
HD44780_MOVE_CURSOR_UP =3D 0x80, // Shift cursor up=20
one character 37 =B5S
HD44780_MOVE_CURSOR_DOWN =3D 0xC0, // Shift cursor down=20
one character 37 =B5S
HD44780_SHIFT_TEXT_RIGHT =3D 0x1C, // Shift text one=20
space to the right 37 =B5S
HD44780_SHIFT_TEXT_LEFT =3D 0x18, // Shift text one=20
space to the left 37 =B5S
HD44780_SETFUNC_8BIT_2LINE_5x8 =3D 0x38, // 8 bit interface, 2=20
line display, 5x8 pix chars 37 =B5S
HD44780_SETFUNC_8BIT_1LINE_5x8 =3D 0x30, // 8 bit interface, 1=20
line display, 5x8 pix chars 37 =B5S
HD44780_SETFUNC_4BIT_2LINE_5x8 =3D 0x28, // 4 bit interface, 2=20
line display, 5x8 pix chars 37 =B5S
HD44780_SETFUNC_4BIT_1LINE_5x8 =3D 0x20, // 4 bit interface, 1=20
line display, 5x8 pix chars 37 =B5S
HD44780_BUSY =3D 0x80, // Check if the=20
controller is busy (1) or not (0)
HD44780_LINE2 =3D 0x40, // LCD display=20
address offset for line 2 (20x4)
HD44780_LINE3 =3D 0x14, // LCD display=20
address offset for line 3 (20x4)
HD44780_LINE4 =3D 0x54 // LCD display=20
address offset for line 4 (20x4)
}=20
hd44780_Commands_t;

// Method Prototypes
void hd77480_Send_4Bits(unsigned char v);
void hd44780_SendCommand(hd44780_Commands_t command);
void hd44780_Init(void);
void hd44780_DisplayString(char* str);
*********** END 44780.h ********************************
*********** START 44780.c ******************************
#include "lpc210x.h"
#include "44780.h"
#include "delay.h"

void hd77480_Send_4Bits(unsigned char v)=20
{=20
GPIO1_IOCLR |=3D ( PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 );=20
GPIO1_IOSET |=3D (v << 22);=20
}=20

void hd44780_SendCommand(hd44780_Commands_t command)
{
// Make sure that D4, D5, D6, D7, RS, RW, E are set to output ports
GPIO1_IODIR |=3D (1 << PIN_D4)=20
| (1 << PIN_D5)=20
| (1 << PIN_D6)=20
| (1 << PIN_D7)=20
| (1 << PIN_RS)=20
| (1 << PIN_RW)=20
| (1 << PIN_E);=20

// Write higher order bits=20
GPIO1_IOSET |=3D PIN_E;
hd77480_Send_4Bits((command>>4) & 0x0F);=20
GPIO1_IOCLR |=3D PIN_E;
=20=20
DelayMS(2); // 2 ms=20
=20=20
// Write lower order bits=20
GPIO1_IOSET |=3D PIN_E;=20
hd77480_Send_4Bits((command) & 0x0F);=20
GPIO1_IOCLR |=3D PIN_E;=20
=20=20
DelayMS(2); // 2 ms=20
}

void hd44780_Init(void)
{
// Make sure that the pins are set for GPIO
PCB_PINSEL1 |=3D (PCB_PINSEL1_P019_GPIO=20
| PCB_PINSEL1_P020_GPIO=20
| PCB_PINSEL1_P021_GPIO
| PCB_PINSEL1_P022_GPIO
| PCB_PINSEL1_P023_GPIO
| PCB_PINSEL1_P018_GPIO
| PCB_PINSEL1_P025_GPIO);
=20=20
// Set D4, D5, D6, D7, RS, RW, E to output ports
GPIO1_IODIR |=3D (1 << PIN_D4)=20
| (1 << PIN_D5)=20
| (1 << PIN_D6)=20
| (1 << PIN_D7)=20
| (1 << PIN_RS)=20
| (1 << PIN_RW)=20
| (1 << PIN_E);=20

// wait for LCD to reset itself
DelayMS(20);

// Set default states=20
GPIO1_IOCLR |=3D PIN_RS;
GPIO1_IOCLR |=3D PIN_RW;
GPIO1_IOCLR |=3D PIN_E;

// Wait for device to power up
DelayMS(500);

// Start initialisation sequence

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET |=3D PIN_E;=20
hd77480_Send_4Bits(0x3);=20
GPIO1_IOCLR |=3D PIN_E;
DelayMS(10);

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET |=3D PIN_E;=20
hd77480_Send_4Bits(0x3);=20
GPIO1_IOCLR |=3D PIN_E;
DelayMS(120);

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET |=3D PIN_E;=20
hd77480_Send_4Bits(0x3);=20
GPIO1_IOCLR |=3D PIN_E;
DelayMS(2);

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 0
GPIO1_IOSET |=3D PIN_E;=20
hd77480_Send_4Bits(0x2); // Set interface to be 4 bits long
GPIO1_IOCLR |=3D PIN_E;
DelayMS(2);

// Function set (specify the number of lines and character font)
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 0
// 0 0 N F * *
hd44780_SendCommand(HD44780_SETFUNC_4BIT_2LINE_5x8);

// Display OFF
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 1 0 0 0
hd44780_SendCommand(HD44780_DISPOFF);

// Display CLEAR=20
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 0 0 0 1
hd44780_SendCommand(HD44780_CLEAR_DISPLAY);=20

// Set Entry Mode=20
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 0 1 I/D S
hd44780_SendCommand(HD44780_ENTRYMODE_INCR_NOSHIFT);=20
}

void hd44780_WriteChar(char c)=20
{=20
GPIO1_IOSET |=3D PIN_E; // Set E high
GPIO1_IOSET |=3D PIN_RS; // Set RS high

hd44780_SendCommand(c); // Write character to ram
=20=20
DelayUS(50); // Wait 50 microseconds
=20=20
GPIO1_IOCLR |=3D PIN_E; // Set E low
GPIO1_IOCLR |=3D PIN_RS; // Set RS low
=20=20
DelayUS(50); // Wait 50 microseconds
}=20

void hd44780_DisplayString(char* str)=20
{=20
unsigned int i=3D0;=20
=20=20
while (str[i] !=3D '\0')=20
{=20
if (str[i] =3D=3D '\n')=20
hd44780_SendCommand(HD44780_MOVE_CURSOR_DOWN); // New line
else=20
hd44780_WriteChar(str[i]);=20
=20=20=20=20
i++;=20
}=20
}=20
*********** END 44780.c ********************************

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )


Re: HD44780 Initialisation (20x4 display in 4-bit mode) - "J.C. Wren" - Oct 4 19:09:17 2008

I see a couple problems right off the bat.
1) You shouldn't be using |=3D with _IOSET and _IOCLR. These need to be a
straight assignment. So GPIO1_IOCLR =3D PIN_E;

2) This code:

void hd77480_Send_4Bits(unsigned char v)

> {
>
GPIO1_IOCLR |=3D ( PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 );
>
GPIO1_IOSET |=3D (v << 22);
>
}
>

is flawed. You have the pins defined as

PIN_D4 =3D 0x00400000, // 1.22 Data 4

PIN_D5 =3D 0x00800000, // 1.23 Data 5

PIN_D6 =3D 0x20000000, // 1.18 Data 6 (1.24 is used on the Olimex H2148)

PIN_D7 =3D 0x02000000 // 1.25 Data 7
Yet, you're shifting by 22. That would work if your pins were 1.22. 1.23,
1.24 and 1.25. But 1.18 is biting you here. It's ALWAYS zero. You need t=
o
explicitly assign the bits

if (v & 0x01)
GPIO1_IOSET =3D PIN_D4;
if (v & 0x02)
GPIO1_IOSET =3D PIN_D5;
if (v & 0x04)
GPIO1_IOSET =3D PIN_D6;
if (v & 0x08)
GPIO1_IOSET =3D PIN_D7;

A cuter way that uses a few more bytes is to define an array:

unsigned int foo [16] =3D {0, PIN_D4, PIN_D4 | PIN_D5, PIN_D4 | PIN_D6, etc=
};

so that you have all 16 combinations. Then you can say GPIO1_IOSET =3D foo
[v]; This would be a very quick table lookup, but it does use 64 bytes.

There may be other problems, but I'd resolve these first.

--jc

On Sat, Oct 4, 2008 at 6:36 PM, Kevin Townsend wrote:

> I've spent the last couple day trying to get a 20x4 character HD44780
> LCD working with my Olimex H2148, and have poured over at least 5
> different examples (including the one in the files section here)
> trying to put together a basic class to work with 44870 LCD.
>
> I'm almost certain I have the board wired up properly (including &
> 10K resistor for contrast on pin 3), and I've read through the entire
> Hitachi datasheet and double-checked my command codes, comparing them
> with other people's examples, but whatever I feed the board it
> doesn't seem to do anything. Line 1 and 3 have solid blocks, and
> line 2 and 4 have nothing.
>
> It must be something with the way the commands are sent, but I don't
> see it myself. If anyone has any experience, I'd certainly
> appreciate another set of eyes and someone else's experience. My
> guess is I screwed something up with either 'hd77480_Send_4Bits'
> or 'hd77480_SendCommand' with the 4-bit business..
>
> NOTE: The code below uses JCWren's (excellent) lpc210x.h, which isn't
> included below, and the delay.h file from the lpc2000 group Files
> section.
>
> Example:
> --------
> hd44780_Init();
> hd44780_SendCommand(HD44780_DISPON_CURSBLINKING);
> hd44780_SendCommand(HD44780_CLEAR_DISPLAY);
> hd44780_DisplayString("Test Test\n");
> hd44780_SendCommand(HD44780_MOVE_CURSOR_DOWN);
> hd44780_DisplayString("Test Test\n");
>
> *********** START 44780.h ******************************
> typedef enum
> {
> PIN_RS =3D 0x00080000, // 1.19 Register Select
> PIN_RW =3D 0x00100000, // 1.20 Read/Write
> PIN_E =3D 0x00200000, // 1.21 Enable
> PIN_D4 =3D 0x00400000, // 1.22 Data 4
> PIN_D5 =3D 0x00800000, // 1.23 Data 5
> PIN_D6 =3D 0x20000000, // 1.18 Data 6 (1.24 is used on the
> Olimex H2148)
> PIN_D7 =3D 0x02000000 // 1.25 Data 7
> }
> hd44780_Pins_t;
>
> typedef enum
> {
> HD44780_CLEAR_DISPLAY =3D 0x01, // Clear LCD
> Display 1.52 mS
> HD44780_HOME =3D 0x02, // Move the cursor to
> the home position 1.52 mS
> HD44780_DISPON =3D 0x0C, // Turn display on
> with no cursor and no blink 37 =B5S
> HD44780_DISPON_CURSUNDERNEATH =3D 0x0E, // Turn display on,
> with cursor under 37 =B5S
> HD44780_DISPON_CURSBLINKING =3D 0x0F, // Turn display on,
> with blinking 37 =B5S
> HD44780_DISPOFF =3D 0x08, // Turn display
> off 37 =B5S
> HD44780_ENTRYMODE_INCR_NOSHIFT =3D 0x06, // Auto increment
> cursor position, no shift 37 =B5S (Default entry mode)
> HD44780_ENTRYMODE_INCR_SHIFT =3D 0x07, // Auto increment
> cursor position, shift text 37 =B5S
> HD44780_ENTRYMODE_DECR_NOSHIFT =3D 0x04, // Auto decrement
> cursor position, no shift 37 =B5S
> HD44780_ENTRYMODE_DECR_SHIFT =3D 0x05, // Auto decrement
> cursor position, shift text 37 =B5S
> HD44780_MOVE_CURSOR_RIGHT =3D 0x14, // Shift cursor one
> character to the right 37 =B5S
> HD44780_MOVE_CURSOR_LEFT =3D 0x10, // Shift cursor one
> character to the left 37 =B5S
> HD44780_MOVE_CURSOR_UP =3D 0x80, // Shift cursor up
> one character 37 =B5S
> HD44780_MOVE_CURSOR_DOWN =3D 0xC0, // Shift cursor down
> one character 37 =B5S
> HD44780_SHIFT_TEXT_RIGHT =3D 0x1C, // Shift text one
> space to the right 37 =B5S
> HD44780_SHIFT_TEXT_LEFT =3D 0x18, // Shift text one
> space to the left 37 =B5S
> HD44780_SETFUNC_8BIT_2LINE_5x8 =3D 0x38, // 8 bit interface, 2
> line display, 5x8 pix chars 37 =B5S
> HD44780_SETFUNC_8BIT_1LINE_5x8 =3D 0x30, // 8 bit interface, 1
> line display, 5x8 pix chars 37 =B5S
> HD44780_SETFUNC_4BIT_2LINE_5x8 =3D 0x28, // 4 bit interface, 2
> line display, 5x8 pix chars 37 =B5S
> HD44780_SETFUNC_4BIT_1LINE_5x8 =3D 0x20, // 4 bit interface, 1
> line display, 5x8 pix chars 37 =B5S
> HD44780_BUSY =3D 0x80, // Check if the
> controller is busy (1) or not (0)
> HD44780_LINE2 =3D 0x40, // LCD display
> address offset for line 2 (20x4)
> HD44780_LINE3 =3D 0x14, // LCD display
> address offset for line 3 (20x4)
> HD44780_LINE4 =3D 0x54 // LCD display
> address offset for line 4 (20x4)
> }
> hd44780_Commands_t;
>
> // Method Prototypes
> void hd77480_Send_4Bits(unsigned char v);
> void hd44780_SendCommand(hd44780_Commands_t command);
> void hd44780_Init(void);
> void hd44780_DisplayString(char* str);
> *********** END 44780.h ********************************
>
> *********** START 44780.c ******************************
> #include "lpc210x.h"
> #include "44780.h"
> #include "delay.h"
>
> void hd77480_Send_4Bits(unsigned char v)
> {
> GPIO1_IOCLR |=3D ( PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 );
> GPIO1_IOSET |=3D (v << 22);
> }
>
> void hd44780_SendCommand(hd44780_Commands_t command)
> {
> // Make sure that D4, D5, D6, D7, RS, RW, E are set to output ports
> GPIO1_IODIR |=3D (1 << PIN_D4)
> | (1 << PIN_D5)
> | (1 << PIN_D6)
> | (1 << PIN_D7)
> | (1 << PIN_RS)
> | (1 << PIN_RW)
> | (1 << PIN_E);
>
> // Write higher order bits
> GPIO1_IOSET |=3D PIN_E;
> hd77480_Send_4Bits((command>>4) & 0x0F);
> GPIO1_IOCLR |=3D PIN_E;
>
> DelayMS(2); // 2 ms
>
> // Write lower order bits
> GPIO1_IOSET |=3D PIN_E;
> hd77480_Send_4Bits((command) & 0x0F);
> GPIO1_IOCLR |=3D PIN_E;
>
> DelayMS(2); // 2 ms
> }
>
> void hd44780_Init(void)
> {
> // Make sure that the pins are set for GPIO
> PCB_PINSEL1 |=3D (PCB_PINSEL1_P019_GPIO
> | PCB_PINSEL1_P020_GPIO
> | PCB_PINSEL1_P021_GPIO
> | PCB_PINSEL1_P022_GPIO
> | PCB_PINSEL1_P023_GPIO
> | PCB_PINSEL1_P018_GPIO
> | PCB_PINSEL1_P025_GPIO);
>
> // Set D4, D5, D6, D7, RS, RW, E to output ports
> GPIO1_IODIR |=3D (1 << PIN_D4)
> | (1 << PIN_D5)
> | (1 << PIN_D6)
> | (1 << PIN_D7)
> | (1 << PIN_RS)
> | (1 << PIN_RW)
> | (1 << PIN_E);
>
> // wait for LCD to reset itself
> DelayMS(20);
>
> // Set default states
> GPIO1_IOCLR |=3D PIN_RS;
> GPIO1_IOCLR |=3D PIN_RW;
> GPIO1_IOCLR |=3D PIN_E;
>
> // Wait for device to power up
> DelayMS(500);
>
> // Start initialisation sequence
>
> // RS RW DB7 DB6 DB5 DB4
> // 0 0 0 0 1 1
> GPIO1_IOSET |=3D PIN_E;
> hd77480_Send_4Bits(0x3);
> GPIO1_IOCLR |=3D PIN_E;
> DelayMS(10);
>
> // RS RW DB7 DB6 DB5 DB4
> // 0 0 0 0 1 1
> GPIO1_IOSET |=3D PIN_E;
> hd77480_Send_4Bits(0x3);
> GPIO1_IOCLR |=3D PIN_E;
> DelayMS(120);
>
> // RS RW DB7 DB6 DB5 DB4
> // 0 0 0 0 1 1
> GPIO1_IOSET |=3D PIN_E;
> hd77480_Send_4Bits(0x3);
> GPIO1_IOCLR |=3D PIN_E;
> DelayMS(2);
>
> // RS RW DB7 DB6 DB5 DB4
> // 0 0 0 0 1 0
> GPIO1_IOSET |=3D PIN_E;
> hd77480_Send_4Bits(0x2); // Set interface to be 4 bits long
> GPIO1_IOCLR |=3D PIN_E;
> DelayMS(2);
>
> // Function set (specify the number of lines and character font)
> // RS RW DB7 DB6 DB5 DB4
> // 0 0 0 0 1 0
> // 0 0 N F * *
> hd44780_SendCommand(HD44780_SETFUNC_4BIT_2LINE_5x8);
>
> // Display OFF
> // RS RW DB7 DB6 DB5 DB4
> // 0 0 0 0 0 0
> // 0 0 1 0 0 0
> hd44780_SendCommand(HD44780_DISPOFF);
>
> // Display CLEAR
> // RS RW DB7 DB6 DB5 DB4
> // 0 0 0 0 0 0
> // 0 0 0 0 0 1
> hd44780_SendCommand(HD44780_CLEAR_DISPLAY);
>
> // Set Entry Mode
> // RS RW DB7 DB6 DB5 DB4
> // 0 0 0 0 0 0
> // 0 0 0 1 I/D S
> hd44780_SendCommand(HD44780_ENTRYMODE_INCR_NOSHIFT);
> }
>
> void hd44780_WriteChar(char c)
> {
> GPIO1_IOSET |=3D PIN_E; // Set E high
> GPIO1_IOSET |=3D PIN_RS; // Set RS high
>
> hd44780_SendCommand(c); // Write character to ram
>
> DelayUS(50); // Wait 50 microseconds
>
> GPIO1_IOCLR |=3D PIN_E; // Set E low
> GPIO1_IOCLR |=3D PIN_RS; // Set RS low
>
> DelayUS(50); // Wait 50 microseconds
> }
>
> void hd44780_DisplayString(char* str)
> {
> unsigned int i=3D0;
>
> while (str[i] !=3D '\0')
> {
> if (str[i] =3D=3D '\n')
> hd44780_SendCommand(HD44780_MOVE_CURSOR_DOWN); // New line
> else
> hd44780_WriteChar(str[i]);
>
> i++;
> }
> }
> *********** END 44780.c ********************************
>
>=20=20
>
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - "J.C. Wren" - Oct 4 19:15:06 2008

Ooops. And there's more :)

> GPIO1_IODIR |= (1 << PIN_D4)

| (1 << PIN_D5)

| (1 << PIN_D6)

| (1 << PIN_D7)

| (1 << PIN_RS)

| (1 << PIN_RW)

| (1 << PIN_E);
You're shifting 1 by 0x00400000 (PIN_D4), which I'm pretty sure is going to
be more than 32 :) You need to set these as GPIO1_IODIR = (PIN_D4 | PIN_D5,
etc);

Once you get this working, you should be able to remove the timing delays in
your send command code, and poll D7. Then the only fixed delays you need
are in the initialization code.

--jc
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Kevin Townsend - Oct 4 19:27:22 2008

Thanks (A LOT) for the reply ... I appreciate the effort. Alas,
still no luck. I've made the mentionned changes (stupid oversights
on my part, being quite new to ARM development), but still don't seem
to get any visible response back. How would you normally go about
debugging this yourself, of out curiousity?

Kevin

void hd77480_Send_4Bits(unsigned char v)
{
// Clear all bits by default
GPIO1_IOCLR = ( PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 );

// Set individual bits
if (v & 0x01)
GPIO1_IOSET = PIN_D4;
if (v & 0x02)
GPIO1_IOSET = PIN_D5;
if (v & 0x04)
GPIO1_IOSET = PIN_D6;
if (v & 0x08)
GPIO1_IOSET = PIN_D7;
}

void hd44780_SendCommand(hd44780_Commands_t command)
{
// Make sure that D4, D5, D6, D7, RS, RW, E are set to output ports
GPIO1_IODIR |= (PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 | PIN_RS | PIN_RW
| PIN_E);

// Write higher order bits
GPIO1_IOSET = PIN_E;
hd77480_Send_4Bits((command>>4) & 0x0F);
GPIO1_IOCLR = PIN_E;

DelayMS(2); // 2 ms

// Write lower order bits
GPIO1_IOSET = PIN_E;
hd77480_Send_4Bits((command) & 0x0F);
GPIO1_IOCLR |= PIN_E;

DelayMS(2); // 2 ms
}

void hd44780_Init(void)
{
// Make sure that the pins are set for GPIO
PCB_PINSEL1 |= (PCB_PINSEL1_P019_GPIO
| PCB_PINSEL1_P020_GPIO
| PCB_PINSEL1_P021_GPIO
| PCB_PINSEL1_P022_GPIO
| PCB_PINSEL1_P023_GPIO
| PCB_PINSEL1_P018_GPIO
| PCB_PINSEL1_P025_GPIO);

// Set D4, D5, D6, D7, RS, RW, E to output ports
GPIO1_IODIR |= (PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 | PIN_RS | PIN_RW
| PIN_E);

// wait for LCD to reset itself
DelayMS(20);

// Set default states
GPIO1_IOCLR = PIN_RS;
GPIO1_IOCLR = PIN_RW;
GPIO1_IOCLR = PIN_E;

// Wait for device to power up
DelayMS(500);

// Start initialisation sequence

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET = PIN_E;
hd77480_Send_4Bits(0x3);
GPIO1_IOCLR = PIN_E;
DelayMS(10);

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET = PIN_E;
hd77480_Send_4Bits(0x3);
GPIO1_IOCLR = PIN_E;
DelayMS(120);

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET = PIN_E;
hd77480_Send_4Bits(0x3);
GPIO1_IOCLR = PIN_E;
DelayMS(2);

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 0
GPIO1_IOSET = PIN_E;
hd77480_Send_4Bits(0x2); // Set interface to be 4 bits long
GPIO1_IOCLR = PIN_E;
DelayMS(2);

// Function set (specify the number of lines and character font)
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 0
// 0 0 N F * *
hd44780_SendCommand(HD44780_SETFUNC_4BIT_2LINE_5x8);

// Display OFF
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 1 0 0 0
hd44780_SendCommand(HD44780_DISPOFF);

// Display CLEAR
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 0 0 0 1
hd44780_SendCommand(HD44780_CLEAR_DISPLAY);

// Set Entry Mode
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 0 1 I/D S
hd44780_SendCommand(HD44780_ENTRYMODE_INCR_NOSHIFT);
}

------------------------------------

______________________________
controlSUITE™ software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - "J.C. Wren" - Oct 4 19:28:24 2008

I've posted some LCD code that works under FreeRTOS at http://jcwren.com/arm
I'm not sure your settling times after setting the data then strobing E are
within spec. On a 48Mhz LPC-2148 with partial MAM, I found I had to insert
some delays to meet the specs on the LCD. The LCD code is setup for an 8
bit interface, and uses the D7 polling to determine command completion. The
LCD model is a CrystalFontz CFAH1602Z-YYH-ET. There's a nifty little
negative voltage charge pump circuit that uses two diodes and a PWM channel
to control the contrast.

--jc
[Non-text portions of this message have been removed]
------------------------------------

______________________________
controlSUITE™ software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - "J.C. Wren" - Oct 4 19:33:57 2008

You've still got that |= action going on. Change those to ='s. And check
the followup about additional delays for data line and control line settling
times.
Truth be told, in a case like this, experience. I've been using HD44780
LCDs for something like 20 years, on 8051's, PICs, AVRs, ARMs, Z80s, and
1802's. I just kinda know their quirks at this point. But when this sort
of problem does hit, my best friend is a logic analyzer. At work I have
access to expensive test equipment. At home, I have a HP 1630G I picked up
off of eBay for $100 or so. I also have a USBee ZX 8 channel logic
analyzer, left over from a company that folded. The software is sorta
funky, but it's much faster than the 1630G.

A 'scope helps a lot, but you really want to see all the control lines and
examine the relationships between them and the data sheets.

--jc
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Kevin Townsend - Oct 4 19:34:13 2008

--- In l...@yahoogroups.com, "J.C. Wren" wrote:
>
> I've posted some LCD code that works under FreeRTOS at
http://jcwren.com/arm

Thanks ... I'll take a look at it now.

Kevin.
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Natarajan N - Oct 5 0:07:24 2008

The first step perhaps could be - power input and contrast setting.
=A0
(1) Do u see=A0 the dots turning darker with contrast adjustment?=A0=20
=A0
We use O'scope to monitor e-signal. Read, write Chip selects.
=A0
While we were working on LPC 2xxx=A0 for the first time:
=A0
Some times the port pins dp not behave as expected.
=A0
Now: =A0We toggle every bit and monitor to ensure that all the port bits be=
have right. This is after we struggled to make Graphic display interfacing.=
Initially we believed that the port pins would behave=A0 normally.=20
=A0
Some port pins needed pull-up which we failed to take note of.

When we follow these steps our dev process is flowing free and smooth.
=A0
We used to get in the market some 25 / 30 years ago a product called pulser=
/ probe.
=A0
This can apply a pulse where the probe is placed .
=A0
Also a re-triggerable monostable multivibrator can substitute to a small ex=
tent, an oscilloscope. It can be built=A0 in one hour max.=A0 With this, we=
can monitor the pulses.
=A0
You might find the ccts in archives of electronic magazines.
=A0
Natarajan
--- On Sun, 10/5/08, Kevin Townsend wrote:

From: Kevin Townsend
Subject: [lpc2000] Re: HD44780 Initialisation (20x4 display in 4-bit mode)
To: l...@yahoogroups.com
Date: Sunday, October 5, 2008, 4:57 AM

Thanks (A LOT) for the reply ... I appreciate the effort. Alas,=20
still no luck. I've made the mentionned changes (stupid oversights=20
on my part, being quite new to ARM development) , but still don't seem=20
to get any visible response back. How would you normally go about=20
debugging this yourself, of out curiousity?

Kevin

void hd77480_Send_ 4Bits(unsigned char v)=20
{=20
// Clear all bits by default
GPIO1_IOCLR =3D ( PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 );=20

// Set individual bits
if (v & 0x01)
GPIO1_IOSET =3D PIN_D4;
if (v & 0x02)
GPIO1_IOSET =3D PIN_D5;
if (v & 0x04)
GPIO1_IOSET =3D PIN_D6;
if (v & 0x08)
GPIO1_IOSET =3D PIN_D7;
}=20

void hd44780_SendCommand (hd44780_ Commands_ t command)
{
// Make sure that D4, D5, D6, D7, RS, RW, E are set to output ports
GPIO1_IODIR |=3D (PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 | PIN_RS | PIN_RW=20
| PIN_E);

// Write higher order bits=20
GPIO1_IOSET =3D PIN_E;
hd77480_Send_ 4Bits((command> >4) & 0x0F);=20
GPIO1_IOCLR =3D PIN_E;

DelayMS(2); // 2 ms=20

// Write lower order bits=20
GPIO1_IOSET =3D PIN_E;=20
hd77480_Send_ 4Bits((command) & 0x0F);=20
GPIO1_IOCLR |=3D PIN_E;=20

DelayMS(2); // 2 ms=20
}

void hd44780_Init( void)
{
// Make sure that the pins are set for GPIO
PCB_PINSEL1 |=3D (PCB_PINSEL1_ P019_GPIO=20
| PCB_PINSEL1_ P020_GPIO=20
| PCB_PINSEL1_ P021_GPIO
| PCB_PINSEL1_ P022_GPIO
| PCB_PINSEL1_ P023_GPIO
| PCB_PINSEL1_ P018_GPIO
| PCB_PINSEL1_ P025_GPIO) ;

// Set D4, D5, D6, D7, RS, RW, E to output ports
GPIO1_IODIR |=3D (PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 | PIN_RS | PIN_RW=20
| PIN_E);

// wait for LCD to reset itself
DelayMS(20);

// Set default states=20
GPIO1_IOCLR =3D PIN_RS;
GPIO1_IOCLR =3D PIN_RW;
GPIO1_IOCLR =3D PIN_E;

// Wait for device to power up
DelayMS(500) ;

// Start initialisation sequence

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET =3D PIN_E;=20
hd77480_Send_ 4Bits(0x3) ;=20
GPIO1_IOCLR =3D PIN_E;
DelayMS(10);

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET =3D PIN_E;=20
hd77480_Send_ 4Bits(0x3) ;=20
GPIO1_IOCLR =3D PIN_E;
DelayMS(120) ;

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET =3D PIN_E;=20
hd77480_Send_ 4Bits(0x3) ;=20
GPIO1_IOCLR =3D PIN_E;
DelayMS(2);

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 0
GPIO1_IOSET =3D PIN_E;=20
hd77480_Send_ 4Bits(0x2) ; // Set interface to be 4 bits long
GPIO1_IOCLR =3D PIN_E;
DelayMS(2);

// Function set (specify the number of lines and character font)
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 0
// 0 0 N F * *
hd44780_SendCommand (HD44780_ SETFUNC_4BIT_ 2LINE_5x8) ;

// Display OFF
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 1 0 0 0
hd44780_SendCommand (HD44780_ DISPOFF);

// Display CLEAR=20
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 0 0 0 1
hd44780_SendCommand (HD44780_ CLEAR_DISPLAY) ;=20

// Set Entry Mode=20
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 0 1 I/D S
hd44780_SendCommand (HD44780_ ENTRYMODE_ INCR_NOSHIFT) ;=20
}

=20

=20=20=20=20=20=20

[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Kevin Townsend - Oct 5 18:27:26 2008

I was wondering if someone could confirm for me if it was normal that
when I add power to my 20x4 display, and connect the third pin to a
10K resistor on pin 1 and 2 (for contrast), that I have two lines of
solid blocks and two empty lines. I've attached a photo for reference
sake:

http://img503.imageshack.us/my.php?image=hd44780defaultstatevy5.jpg

Also, I hooked up a cheapo ebay oscilloscope that I bought, and
noticed when monitoring the different pins that the 4 data bits seems
to work (I see activity going up and down), but I don't seem to get
any response out of the E pin when it should be bouncing up and down
as I enter the following methods:

static inline void lcdEnableHigh()
{
GPIO1_IOSET = PIN_E;
}

static inline void lcdEnableLow()
{
GPIO1_IOCLR = PIN_E;
}

Admittedly, I'm completely new to all this, but shouldn't the IOSET
and IOCLR cause the pin to go up and down on the 'scope? I'm sure it
it connected to the probe properly, and the connection is fine between
the 2148 and the LCD board ... any ideas what might be explain this?
I've attached another image to show what I mean, with the breakpoint
on the left (after I've entered the method a few times):

http://img117.imageshack.us/my.php?image=escopedda7.jpg

I appreciate any feedback anyone can offer.
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: HD44780 Initialisation (20x4 display in 4-bit mode) - GB - Oct 5 18:31:05 2008

>I was wondering if someone could confirm for me if it was normal that
> when I add power to my 20x4 display, and connect the third pin to a
> 10K resistor on pin 1 and 2 (for contrast), that I have two lines of
> solid blocks and two empty lines. I've attached a photo for reference
> sake:
>
> http://img503.imageshack.us/my.php?image=hd44780defaultstatevy5.jpg

Yes it's normal. Until the LCD is initialized that's what you'll see.

GB
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Kevin Townsend - Oct 5 18:35:16 2008

Here is the latest incarnation of the code if anyone has enough
patience or interest to look through it.

I'm using an Olimex H2148 board, and as far as I can tell the pins I'm
using (P1.16...22) are not used on this board.

http://www.olimex.com/dev/images/lpc-h2148-sch.gif

*********** START hd44780.c *********************
#include "lpc210x.h"
#include "hd44780.h"
#include "delay.h"

//
// Each operation is 83.33ns. Cumlative delays make be longer, but
not shorter.
// This delay assumes a 48Mhz clock and MAM=3Dpartial
//
#define delay166ns() do { __asm__ volatile ("push {r0}\r\npop
{r0}\r\n"); } while (0)

//
// 166ns measured
//
static inline void lcdDelay140ns (void)
{
delay166ns ();
}

//
// 333ns measured
//
static inline void lcdDelay320ns (void)
{
delay166ns ();
delay166ns ();
}

//
// 500ns measured
//
static inline void lcdDelay450ns (void)
{
delay166ns ();
delay166ns ();
delay166ns ();
}

//
// 666ns measured
//
static inline void lcdDelay550ns (void)
{
delay166ns ();
delay166ns ();
delay166ns ();
delay166ns ();
}

static inline void lcdEnableHigh()
{
GPIO1_IOSET =3D PIN_E;
}

static inline void lcdEnableLow()
{
GPIO1_IOCLR =3D PIN_E;
}

static inline void lcdEnableStrobe (void)
{
lcdEnableHigh ();
lcdDelay450ns ();
lcdEnableLow ();
lcdDelay550ns ();
}

void hd77480_Send_4Bits(unsigned char v)=20
{=20
// Clear all bits by default
GPIO1_IOCLR =3D ( PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 );=20
=20=20
// Set individual bits
if (v & 0x01)
GPIO1_IOSET =3D PIN_D4;
if (v & 0x02)
GPIO1_IOSET =3D PIN_D5;
if (v & 0x04)
GPIO1_IOSET =3D PIN_D6;
if (v & 0x08)
GPIO1_IOSET =3D PIN_D7;
}=20

void hd44780_SendCommand(hd44780_Commands_t command)
{
// Make sure that D4, D5, D6, D7, RS, RW, E are set to output ports
GPIO1_IODIR |=3D (PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 | PIN_RS | PIN_RW
| PIN_E);

// Write higher order bits=20
lcdEnableHigh ();
lcdDelay450ns ();
hd77480_Send_4Bits ((command >> 4) & 0x0F);=20
lcdDelay140ns ();
lcdEnableLow ();
lcdDelay550ns ();
=20=20
// Write lower order bits=20
GPIO1_IOSET =3D PIN_E;=20
lcdDelay450ns ();
hd77480_Send_4Bits ((command) & 0x0F);=20
lcdDelay140ns ();
GPIO1_IOCLR =3D PIN_E;=20

// Delay before exiting
lcdDelay550ns ();
lcdDelay550ns ();
}

void hd44780_Init(void)
{
PCB_PINSEL1 =3D PCB_PINSEL1_P016_GPIO;
// Set D4, D5, D6, D7, RS, RW, E to output ports
GPIO1_IODIR |=3D (PIN_D4 | PIN_D5 | PIN_D6 | PIN_D7 | PIN_RS | PIN_RW
| PIN_E);

// wait for LCD to reset itself
DelayMS (20);

// Set default states=20
GPIO1_IOCLR =3D PIN_RS;
GPIO1_IOCLR =3D PIN_RW;
GPIO1_IOCLR =3D PIN_E;

// Wait for device to power up
DelayMS (500);

// Start initialisation sequence
for (int counter =3D 0; counter < 3; counter++) // Repeat 3 times
{
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 1
GPIO1_IOSET =3D PIN_E;=20
lcdDelay450ns ();
hd77480_Send_4Bits (0x03);=20
GPIO1_IOCLR =3D PIN_E;
DelayMS (120);
}

// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 0
GPIO1_IOSET =3D PIN_E;=20
lcdDelay450ns ();
hd77480_Send_4Bits (0x02); // Set interface to be 4 bits long
GPIO1_IOCLR =3D PIN_E;
DelayMS (100);

// Function set (specify the number of lines and character font)
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 1 0
// 0 0 N F * *
hd44780_SendCommand (HD44780_SETFUNC_4BIT_2LINE_5x8);

// Display OFF
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 1 0 0 0
hd44780_SendCommand (HD44780_DISPOFF);

// Display CLEAR=20
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 0 0 0 1
hd44780_SendCommand (HD44780_CLEAR_DISPLAY);=20

// Set Entry Mode=20
// RS RW DB7 DB6 DB5 DB4
// 0 0 0 0 0 0
// 0 0 0 1 I/D S
hd44780_SendCommand (HD44780_ENTRYMODE_INCR_NOSHIFT);=20
}

void hd44780_WriteChar(char c)=20
{=20
GPIO1_IOSET =3D PIN_E; // Set E high
GPIO1_IOSET =3D PIN_RS; // Set RS high

hd44780_SendCommand (c); // Write character to ram
=20=20
DelayUS (50); // Wait 50 microseconds
=20=20
GPIO1_IOCLR =3D PIN_E; // Set E low
GPIO1_IOCLR =3D PIN_RS; // Set RS low
=20=20
DelayUS (50); // Wait 50 microseconds
}=20

void hd44780_DisplayString(char* str)=20
{=20
unsigned int i=3D0;=20
=20=20
while (str[i] !=3D '\0')=20
{=20
if (str[i] =3D=3D '\n')=20
hd44780_SendCommand(HD44780_MOVE_CURSOR_DOWN); // New line
else=20
hd44780_WriteChar(str[i]);=20
=20=20=20=20
i++;=20
}=20
}=20
*************** END hd44780.c ****************************

*************** START hd44780.h **************************

#define LCD_COMMAND_CLEAR 0x01
#define LCD_COMMAND_HOME 0x02
#define LCD_COMMAND_MODE 0x04
#define LCD_COMMAND_DISPLAY 0x08
#define LCD_COMMAND_SHIFT 0x10
#define LCD_COMMAND_FUNCTION 0x20
#define LCD_COMMAND_CGRAM 0x40
#define LCD_COMMAND_DDRAM 0x80

#define LCD_MODE_SHIFT_NO 0x00
#define LCD_MODE_SHIFT_YES 0x01
#define LCD_MODE_DECREMENT 0x00
#define LCD_MODE_INCREMENT 0x02
#define LCD_MODE_MASK 0x03

#define LCD_SHIFT_CURSOR 0x00
#define LCD_SHIFT_DISPLAY 0x04
#define LCD_SHIFT_LEFT 0x00
#define LCD_SHIFT_RIGHT 0x08
#define LCD_SHIFT_MASK 0x0c

#define LCD_FUNCTION_FONT_5X8 0x00
#define LCD_FUNCTION_FONT_5X11 0x04
#define LCD_FUNCTION_LINES_1 0x00
#define LCD_FUNCTION_LINES_2 0x08
#define LCD_FUNCTION_BUS_4 0x00
#define LCD_FUNCTION_BUS_8 0x10
#define LCD_FUNCTION_MASK 0x1c

#define LCD_DISPLAY_BLINK_OFF 0x00
#define LCD_DISPLAY_BLINK_ON 0x01
#define LCD_DISPLAY_CURSOR_OFF 0x00
#define LCD_DISPLAY_CURSOR_ON 0x02
#define LCD_DISPLAY_DISPLAY_OFF 0x00
#define LCD_DISPLAY_DISPLAY_ON 0x04
#define LCD_DISPLAY_MASK 0x07

typedef enum
{
PIN_RS =3D 0x00010000, // 1.16 Register Select
PIN_RW =3D 0x00020000, // 1.17 Read/Write
PIN_E =3D 0x00040000, // 1.18 Enable
PIN_D4 =3D 0x00080000, // 1.19 Data 4
PIN_D5 =3D 0x00100000, // 1.20 Data 5
PIN_D6 =3D 0x00200000, // 1.21 Data 6
PIN_D7 =3D 0x00400000 // 1.22 Data 7
}=20
hd44780_Pins_t;

typedef enum
{
HD44780_CLEAR_DISPLAY =3D 0x01, // Clear LCD Display=20
1.52 mS
HD44780_HOME =3D 0x02, // Move the cursor to
the home position 1.52 mS
HD44780_DISPON =3D 0x0C, // Turn display on
with no cursor and no blink 37 =B5S
HD44780_DISPON_CURSUNDERNEATH =3D 0x0E, // Turn display on,
with cursor under 37 =B5S
HD44780_DISPON_CURSBLINKING =3D 0x0F, // Turn display on,
with blinking 37 =B5S
HD44780_DISPOFF =3D 0x08, // Turn display off=20=20
37 =B5S
HD44780_ENTRYMODE_INCR_NOSHIFT =3D 0x06, // Auto increment
cursor position, no shift 37 =B5S (Default entry mode)
HD44780_ENTRYMODE_INCR_SHIFT =3D 0x07, // Auto increment
cursor position, shift text 37 =B5S
HD44780_ENTRYMODE_DECR_NOSHIFT =3D 0x04, // Auto decrement
cursor position, no shift 37 =B5S
HD44780_ENTRYMODE_DECR_SHIFT =3D 0x05, // Auto decrement
cursor position, shift text 37 =B5S
HD44780_MOVE_CURSOR_RIGHT =3D 0x14, // Shift cursor one
character to the right 37 =B5S
HD44780_MOVE_CURSOR_LEFT =3D 0x10, // Shift cursor one
character to the left 37 =B5S
HD44780_MOVE_CURSOR_UP =3D 0x80, // Shift cursor up one
character 37 =B5S
HD44780_MOVE_CURSOR_DOWN =3D 0xC0, // Shift cursor down
one character 37 =B5S
HD44780_SHIFT_TEXT_RIGHT =3D 0x1C, // Shift text one
space to the right 37 =B5S
HD44780_SHIFT_TEXT_LEFT =3D 0x18, // Shift text one
space to the left 37 =B5S
HD44780_SETFUNC_8BIT_2LINE_5x8 =3D 0x38, // 8 bit interface, 2
line display, 5x8 pix chars 37 =B5S
HD44780_SETFUNC_8BIT_1LINE_5x8 =3D 0x30, // 8 bit interface, 1
line display, 5x8 pix chars 37 =B5S
HD44780_SETFUNC_4BIT_2LINE_5x8 =3D 0x28, // 4 bit interface, 2
line display, 5x8 pix chars 37 =B5S
HD44780_SETFUNC_4BIT_1LINE_5x8 =3D 0x20, // 4 bit interface, 1
line display, 5x8 pix chars 37 =B5S
HD44780_BUSY =3D 0x80, // Check if the
controller is busy (1) or not (0)
HD44780_LINE2 =3D 0x40, // LCD display address
offset for line 2 (20x4)
HD44780_LINE3 =3D 0x14, // LCD display address
offset for line 3 (20x4)
HD44780_LINE4 =3D 0x54 // LCD display address
offset for line 4 (20x4)
}=20
hd44780_Commands_t;

// Method Prototypes
void hd77480_Send_4Bits(unsigned char v);
void hd44780_SendCommand(hd44780_Commands_t command);
void hd44780_Init(void);
void hd44780_DisplayString(char* str);

*************** END hd44780.h **************************

------------------------------------

______________________________
controlSUITE™ software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: HD44780 Initialisation (20x4 display in 4-bit mode) - "J.C. Wren" - Oct 5 19:32:35 2008

I've added LCD functionality to LPC-2148 demo code that I'm getting ready to
release. In the mean time, I've put the lcd_4bit.c file that I got working
today up at http://jcwren.com/arm The actual display I tested with is a
CrystalFontz CFAH1602Z-YYH-ET. This is a standard HD44780-based LCD, so it
should work the same as yours.
Until you get your display working, I'd suggest replacing
the lcdWaitWhileBusy() routine with a hard 30 millisecond delay. It'll make
the display look like a teletype when it's writing (which is sorta cool, if
you don't need to print lots of stuff).

I'm still looking at what you've currently got to see if I can find where it
went wrong.

--jc
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Sumit Bhatnagar - Oct 5 19:42:38 2008

I also plan to use a 16X2 LCD with the LPCH2148.=C2=A0 I am at the same sta=
ge as you are. 1 row blanc and other black.
I=C2=A0ran into the same issue with the PIC16F684 while trying to interface=
that to the LCD. I did not proceed further to resolve that completely.

I am therefore planning on a differnt approach with the LPCH2148. I have go=
t the schematic for the IAR LPC 2148 R2T. I will be connecting the LPCH2148=
with the LCD per the schematic and then run the sample code that comes wit=
h the IAR. I am hoping this will work. Later I will modify the code to suit=
the pinout I decide.

-sumit
----- Original Message ----
From: J.C. Wren
To: l...@yahoogroups.com
Sent: Sunday, 5 October, 2008 7:32:28 PM
Subject: Re: [lpc2000] Re: HD44780 Initialisation (20x4 display in 4-bit mo=
de)
I've added LCD functionality to LPC-2148 demo code that I'm getting ready t=
o
release. In the mean time, I've put the lcd_4bit.c file that I got working
today up at http://jcwren. com/arm The actual display I tested with is a
CrystalFontz CFAH1602Z-YYH- ET. This is a standard HD44780-based LCD, so it
should work the same as yours.
Until you get your display working, I'd suggest replacing
the lcdWaitWhileBusy( ) routine with a hard 30 millisecond delay. It'll mak=
e
the display look like a teletype when it's writing (which is sorta cool, if
you don't need to print lots of stuff).

I'm still looking at what you've currently got to see if I can find where i=
t
went wrong.

--jc

[Non-text portions of this message have been removed]

=20
Add more friends to your messenger and enjoy! Go to http://messenger.=
yahoo.com/invite/

[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Natarajan N - Oct 6 4:08:00 2008

yes, it is normal.
=A0
If u had two line display one of the line will be.
=A0
in four lines alternate lines would be darker.
=A0
Natarajan

--- On Mon, 10/6/08, Kevin Townsend wrote:

From: Kevin Townsend
Subject: [lpc2000] Re: HD44780 Initialisation (20x4 display in 4-bit mode)
To: l...@yahoogroups.com
Date: Monday, October 6, 2008, 3:57 AM

I was wondering if someone could confirm for me if it was normal that
when I add power to my 20x4 display, and connect the third pin to a
10K resistor on pin 1 and 2 (for contrast), that I have two lines of
solid blocks and two empty lines. I've attached a photo for reference
sake:

http://img503. imageshack. us/my.php? image=3Dhd44780def aultstatevy5. jpg

Also, I hooked up a cheapo ebay oscilloscope that I bought, and
noticed when monitoring the different pins that the 4 data bits seems
to work (I see activity going up and down), but I don't seem to get
any response out of the E pin when it should be bouncing up and down
as I enter the following methods:

static inline void lcdEnableHigh( )
{
GPIO1_IOSET =3D PIN_E;
}

static inline void lcdEnableLow( )
{
GPIO1_IOCLR =3D PIN_E;
}

Admittedly, I'm completely new to all this, but shouldn't the IOSET
and IOCLR cause the pin to go up and down on the 'scope? I'm sure it
it connected to the probe properly, and the connection is fine between
the 2148 and the LCD board ... any ideas what might be explain this?=20
I've attached another image to show what I mean, with the breakpoint
on the left (after I've entered the method a few times):

http://img117. imageshack. us/my.php? image=3Descopedda7 .jpg

I appreciate any feedback anyone can offer.

=20

=20=20=20=20=20=20

[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Kevin Townsend - Oct 6 12:02:09 2008

I spent a bit of time individually checking all of the pins on my
H2148 board, and noticed something really odd that I'm sure is the
cause of the problem.

Of the pins between 1.16 and 1.31 on the H2148, 1.26..31 are reserved
for JTAG, but I expected 1.16..25 (except 1.24) to be available for
normal GPIO. When I hooked each pin up to an oscilloscope, though, it
seems that only 1.16 and 1.22-25 are actually working when I set and
clear the pins. Looking at the schematic, I can't see any reason pins
1.17..21 aren't working, and I passed 'PCB_PINSEL1 = 0x00000000;' to
make sure that GPIO is selected.

Does this make sense to anyone? If the board is toasted, wouldn't all
the pins fail?

http://www.olimex.com/dev/images/lpc-h2148-sch.gif

Kevin.
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: HD44780 Initialisation (20x4 display in 4-bit mode) - "J.C. Wren" - Oct 6 12:22:45 2008

You need to set PINSEL2 to 0. The default is for those pins to come up for
the trace port.

--jc

On Mon, Oct 6, 2008 at 12:02 PM, Kevin Townsend wrote:

> I spent a bit of time individually checking all of the pins on my
> H2148 board, and noticed something really odd that I'm sure is the
> cause of the problem.
>
> Of the pins between 1.16 and 1.31 on the H2148, 1.26..31 are reserved
> for JTAG, but I expected 1.16..25 (except 1.24) to be available for
> normal GPIO. When I hooked each pin up to an oscilloscope, though, it
> seems that only 1.16 and 1.22-25 are actually working when I set and
> clear the pins. Looking at the schematic, I can't see any reason pins
> 1.17..21 aren't working, and I passed 'PCB_PINSEL1 = 0x00000000;' to
> make sure that GPIO is selected.
>
> Does this make sense to anyone? If the board is toasted, wouldn't all
> the pins fail?
> http://www.olimex.com/dev/images/lpc-h2148-sch.gif
>
> Kevin.
>
>
>
[Non-text portions of this message have been removed]
------------------------------------

______________________________
controlSUITE™ software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Kevin Townsend - Oct 6 12:39:08 2008

--- In l...@yahoogroups.com, "J.C. Wren" wrote:
>
> You need to set PINSEL2 to 0. The default is for those pins to come
up for
> the trace port.
>
> --jc

Thanks again, and sorry if this is all fairly basic stuff.

Out of curiousity, though, what is the logic behind the numbering on
the following defines (ex. P13626, P12516). I don't remember seeing
PINSEL2 in the previous lpc210x.h file.

#define PCB_PINSEL2_P13626_GPIO ((unsigned int) 0x00000000)
#define PCB_PINSEL2_P13626_DEBUG ((unsigned int) 0x00000004)
#define PCB_PINSEL2_P13626_MASK ((unsigned int) 0x00000004)

#define PCB_PINSEL2_P12516_GPIO ((unsigned int) 0x00000000)
#define PCB_PINSEL2_P12516_TRACE ((unsigned int) 0x00000008)
#define PCB_PINSEL2_P12516_MASK ((unsigned int) 0x00000008)

In any case, thanks again for your help ... I really appreciate you
taking the time to share your expertise, and hope someone else finds
it useful as well down the road.

Kevin
------------------------------------

______________________________
controlSUITE™ software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: HD44780 Initialisation (20x4 display in 4-bit mode) - "J.C. Wren" - Oct 6 15:02:44 2008

PCB_PINSEL2_P12516_ means PINSEL2, Port 1, pins 25 through 16. Due to a
printing error in the manual, PCB_PINSEL2_P13626_ should REALLY be
PCB_PINSEL2_P12626_ or PCB_PINSEL2_P126_, since it only handles P1.26, not
P1.36 through P1.26. It ain't easy coming with names that aren't 50
characters long :)

For all my curmudgeonishnish and smacking down people that ask stupid
questions, I actually enjoy helping people that are putting effort into
trying to learn. It's very obvious that you're trying to figure out what's
wrong, and you're asking good questions, not "my proggie doesn't work why
please help NOW ur answer urgently neaded".

-jc

On Mon, Oct 6, 2008 at 12:38 PM, Kevin Townsend wrote:

> --- In l...@yahoogroups.com , "J.C. Wren"
> wrote:
> >
> > You need to set PINSEL2 to 0. The default is for those pins to come
> up for
> > the trace port.
> >
> > --jc
>
> Thanks again, and sorry if this is all fairly basic stuff.
>
> Out of curiousity, though, what is the logic behind the numbering on
> the following defines (ex. P13626, P12516). I don't remember seeing
> PINSEL2 in the previous lpc210x.h file.
>
> #define PCB_PINSEL2_P13626_GPIO ((unsigned int) 0x00000000)
> #define PCB_PINSEL2_P13626_DEBUG ((unsigned int) 0x00000004)
> #define PCB_PINSEL2_P13626_MASK ((unsigned int) 0x00000004)
>
> #define PCB_PINSEL2_P12516_GPIO ((unsigned int) 0x00000000)
> #define PCB_PINSEL2_P12516_TRACE ((unsigned int) 0x00000008)
> #define PCB_PINSEL2_P12516_MASK ((unsigned int) 0x00000008)
>
> In any case, thanks again for your help ... I really appreciate you
> taking the time to share your expertise, and hope someone else finds
> it useful as well down the road.
>
> Kevin
>
>
>
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - ksdoubleshooter - Oct 6 17:00:31 2008

JC is correct about setting PINSEL2 to 0. This will set those pins
back to GPIO if they were set to the ETM function. However, they do
not default to the ETM function. The state of P1.20 is sampled
coming out of reset and if low, the ETM function is selected,
otherwise GPIO is selected.

I just brought up a new proto where this "bit" me.

Jeff

--- In l...@yahoogroups.com, "J.C. Wren" wrote:
>
> You need to set PINSEL2 to 0. The default is for those pins to
come up for
> the trace port.
>
> --jc
>
> On Mon, Oct 6, 2008 at 12:02 PM, Kevin Townsend
wrote:
>
> > I spent a bit of time individually checking all of the pins on
my
> > H2148 board, and noticed something really odd that I'm sure is
the
> > cause of the problem.
> >
> > Of the pins between 1.16 and 1.31 on the H2148, 1.26..31 are
reserved
> > for JTAG, but I expected 1.16..25 (except 1.24) to be available
for
> > normal GPIO. When I hooked each pin up to an oscilloscope,
though, it
> > seems that only 1.16 and 1.22-25 are actually working when I set
and
> > clear the pins. Looking at the schematic, I can't see any reason
pins
> > 1.17..21 aren't working, and I passed 'PCB_PINSEL1 =
0x00000000;' to
> > make sure that GPIO is selected.
> >
> > Does this make sense to anyone? If the board is toasted,
wouldn't all
> > the pins fail?
> >
> >
> > http://www.olimex.com/dev/images/lpc-h2148-sch.gif
> >
> > Kevin.
> >
> >
> >
> [Non-text portions of this message have been removed]
>

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: HD44780 Initialisation (20x4 display in 4-bit mode) - Kevin Townsend - Oct 9 19:46:46 2008

After WAY too much time, I finally got my LCD working tonight gasp of relief here>. I still feel pretty dumb for having to spend a
week to accomplish this, but not as dumb as I would have felt if I
gave up and just accepted my overwhelming incompetence. :-) In any
case, thanks a lot for all the excellent (and patient) help I got on
this forum.

There's just one last question if anyone has time for it. I can
display things on the top two lines of the display, but I can't seem
to get any text displayed on lines 3 or 4 of the display. Does anyone
happen to know why this might be or know of an example of code for 4
line displays? I assume it's just an addressing issue, and I've
noticed that lines 1 and 3 seem to be line '1' and lines 2 and 4 seem
to be line '2'. I'm sure I'll figure it out eventually, but if
someone knows off the top of their head how to write to each line, it
might save me a bit more head scratching myself.

Kevin.
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )