4 wire LCD code

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to get this code copy form another site to work,i did connect leds to the upper nibble of PORTD and slowed down the code ,i aslo pulse PORTD 7,6,5,4 leds on and off to test the wiring.

But i found only the upper part of the binary code will switch the leds on ,if the command is 0011 0101 then only the 0011 will turn on the leds ,the lower part 0101 never lights any leds.

 

Now if the code is correct ,i must look for the problem somewhere else.

 

This is a part of the code -only the part where the upper and lower nibble is seperated and clocked to the LCD.

 

void LCD_Command( unsigned char cmnd )
{
    LCD_Port = (LCD_Port & 0x0F) | (cmnd & 0xF0); /* sending upper nibble */
    
    PORTC |= (1<<EN);        /* Enable pulse */
    _delay_ms(1000);
    PORTC &= ~ (1<<EN);

    _delay_ms(1000);

    PORTC = (LCD_Port & 0x0F) | (cmnd << 4);  /* sending lower nibble */
    PORTC |= (1<<EN);
    _delay_ms(1000);
    PORTC &= ~ (1<<EN);
    _delay_ms(5000);
}

 

 

Is this code correct -- please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mikedb wrote:
PORTC = (LCD_Port & 0x0F) | (cmnd << 4); /* sending lower nibble */

Probably should be:

    LCD_Port = (LCD_Port & 0x0F) | (cmnd << 4);

David

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As you are using avr-gcc is there some reason not to use Fleury for the LCD? (In fact AVR-LibC even comes with an example of LCD code in one of the user manual examples)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks i also found that mistake must have typed PORTC when i change the original code from RA and RB to RC and RD,took me 3 days to notice that!!!

The code is working fine....my mistake.