newbie: problems w/LCD

hi,

this is my first time working with a microcontroller so please bear with me. i am trying to interface a simple hd44780 type lcd to a 8051 Cygnal microcontroller. the code compiles fine and passes through the LCD functions (i am outputting data through a uart for debugging purposes). i am not getting anything out however, like the lcd doesnt even turn on. i will describe my hw and sw setup below.

HW port2's data pins are wired into d0-d7 of the lcd. port1 pins 1,2,3 are wired as the control pins of the lcd (pin1-RS, pin2-R/W, pin3-Enable). i am powering the lcd with 5V into pin 2, gnd at pin1, and 4V at pin3 (LCD contrast). i also set the latter to 0V and get a very dark contrast on each character spot, but still, nothing comes out.

SW these are the functions i call. i modeled them after a template i found on the web.

lcdInitHW(); lcdInit();

lcdDisplayChar('H'); lcdDisplayChar('e'); lcdDisplayChar('l'); lcdDisplayChar('l'); lcdDisplayChar('o');

the implementations are below

// Local low level Function Prototypes ////////////////////////////////////////// // these functions access the hardware and are dependent on hw parameters. // they also make direct use of the HD44780 instruction set

#define LCD_DATA_PORT P2 #define LCD_DATA_PORT_CONFIG P2MDOUT sbit LCD_RS = P1^0; sbit LCD_RW = P1^1; sbit LCD_E = P1^2; #define LCD_CTRL_PORT_CONFIG P1MDOUT

// 5 nops are about ~240 ns at our processor speed #define LCD_DELAY _nop_(); _nop_(); _nop_(); _nop_(); _nop_()

// configures the data port to be an input void lcdConfigDataInput(void);

// configures the data port to be an output void lcdConfigDataOutput(void);

// waits until LCD is not busy void lcdBusyWait(void);

// writes a control command to the LCD void lcdCtrlWrite(unsigned char data2write);

// writes a data byte to the LCD screen at the current position void lcdDataWrite(unsigned char data2write);

// configures pins void lcdInitHW(void);

// initializes LCD void lcdInit(void);

// Implementations //////////////////////////////////////////////////////////////

void lcdConfigDataInput(void){ // configure as input by setting to open drain and writing a one LCD_DATA_PORT_CONFIG = 0x00; LCD_DATA_PORT = 0xFF; }

void lcdConfigDataOutput(void){ // configure as output by setting to push-pull LCD_DATA_PORT_CONFIG = 0xFF; }

void lcdBusyWait(void) {

char temp;

lcdConfigDataInput();

LCD_RS = 0; LCD_RW = 1; LCD_E = 1; LCD_DELAY;

temp = LCD_DATA_PORT;

while(temp & 0x80) { LCD_E = 0; LCD_DELAY; LCD_E = 1; LCD_DELAY; temp = LCD_DATA_PORT; }

LCD_E = 0; }

void lcdCtrlWrite(unsigned char data2write) {

lcdBusyWait(); // wait until LCD not busy LCD_RS = 0; // set RS to "control" LCD_RW = 0; // set R/W to "write" LCD_E = 1; // set "E" line

lcdConfigDataOutput(); // set data I/O lines to output (8bit) LCD_DATA_PORT = data2write; // output data, 8bits LCD_DELAY; // wait LCD_E = 0; // clear "E" line

lcdConfigDataInput(); }

void lcdDataWrite(unsigned char data2write) {

lcdBusyWait(); // wait until LCD not busy LCD_RS = 1; // set RS to "control" LCD_RW = 0; // set R/W to "write" LCD_E = 1; // set "E" line

lcdConfigDataOutput(); // set data I/O lines to output (8bit) LCD_DATA_PORT = data2write; // output data, 8bits LCD_DELAY; // wait LCD_E = 0; // clear "E" line

lcdConfigDataInput();

}

void lcdInitHW(void) {

// configure the control pins to be push pull // the value depends on the pins being used, 1,2,3 in our case // have initial 4 (0x47) because I want to configure 1.6 (the LED) // as push-pull LCD_CTRL_PORT_CONFIG |= 0x47;

// initially configure data port in input mode lcdConfigDataInput(); }

void lcdInit(void) {

// LCD function set lcdCtrlWrite(0x38);

// clear LCD lcdCtrlWrite(0x01);

// set entry mode lcdCtrlWrite(0x06);

// set display to on lcdCtrlWrite(0x0F);

// move cursor to home lcdCtrlWrite(0x02);

}
Reply to
rizwan
Loading thread data ...

What about the reset line of the HD44780? You should either control it using a port line or put an resistor to 5V and a capacitor to GND on it.

Are you sure about the positive LCD drive voltage? Many displays use negative voltages.... have a look at the datasheet of your LCD panel.

HTH Wolfgang

Reply to
Wolfgang Mahringer

Then it looks like you need a voltage between 0V and 4V. Connect a pot-meter (10K) between 0V and 5V and connect the center connection to the LCD contrast pin. Turn the potmeter towards 0V until you get a dark display, then turn it back until the character positions become less dark but are still a little bit darker then when unpowered. Adjust to taste when you get chars on the display.

Stef

Reply to
Stef

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.