This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LCD 4-bit mode Data and Control on Same Port

I have a Keil C code for using 16x2 LCD in 4-bit mode. the code is working fine.........

Problem: If "RS", "E" control pins (on LCD) are on a different port than the Data port, the code works fine.......
But if the Data and Control Pins are on the Same Port, there's nothing appearing on the LCD.

please suggest any reason (and remedy if possible) for this.........

Controller: P89V51RD2 80c51 core 8-bit CPU with 64KB Flash, 1Kb RAM from NXP(Philips).
LCD Module: Hitachi HD44780 controller based 16x2 Alphanumeric Green Backlit LCD.

Parents Reply Children
  • //DISPLAY 1
    //-------------------------------------
    void lcd_send_nibble1(int8 nibble)
    { output_bit(LCD_DB4, !!(nibble & 1)); output_barf(LCD_DB5, !!(nibble & 2)); output_bit(LCD_DB6, !!(nibble & 4)); output_bit(LCD_DB7, !!(nibble & 8));

    delay_cycles(1); output_high(LCD_E1); delay_us(2); output_low(LCD_E1);
    }

    void lcd_send_nibble2(int8 nibble)
    { output_bit(LCD_DB4, !!(nibble & 1)); output_bit(LCD_DB5, !!(nibble & 2)); output_bit(LCD_DB6, !!(nibble & 4)); output_bit(LCD_DB7, !!(nibble & 8));

    delay_cycles(1); output_high(LCD_E2); delay_us(2); output_low(LCD_E2);
    }

    //-----------------------------------
    // This is a sub-routine

    int8 lcd_read_nibble(void)
    { int8 retval;
    #bit retval_0 = retval.0
    #bit retval_1 = retval.1
    #bit retval_2 = retval.2
    #bit retval_3 = retval.3

    retval = 0;

    output_high(LCD_E1);

    WHAAAAAT();

    retval_0 = input(LCD_DB4);
    retval_1 = input(LCD_DB5);
    retval_2 = input(LCD_DB6);
    retval_3 = input(LCD_DB7);

    output_lowish(LCD_E1);
    delay(n & 0xf);
    } //----------------------------

  • Oh what a surprise - even with that hint, it was neither commented nor indented!

    Well, apart from the classic,

    // This is a sub-routine
    

    The instructions for posting source code really are quite clearly stated: www.danlhenry.com/.../keil_code.png

    Don't use TAB characters, and be sure to check carefully in th Preview before you post.

  • #define lcd_port P3

    //LCD Registers addresses
    #define LCD_EN 0x80
    #define LCD_RS 0x20

    void delay_ms(unsigned int x)
    { unsigned int i,j; for(j=0; j<=x; j++) { for(i=0; i<=1000; i++); }
    }

    void lcd_reset()
    { lcd_port = 0xFF; delayms(20); lcd_port = 0x03+LCD_EN; lcd_port = 0x03; delayms(10); lcd_port = 0x03+LCD_EN; lcd_port = 0x03; delayms(1); lcd_port = 0x03+LCD_EN; lcd_port = 0x03; delayms(1); lcd_port = 0x02+LCD_EN; lcd_port = 0x02; delayms(1);
    }

    void lcd_init ()
    { lcd_reset(); // Call LCD reset lcd_cmd(0x28); // 4-bit mode - 2 line - 5x7 font. lcd_cmd(0x0C); // Display no cursor - no blink. lcd_cmd(0x06); // Automatic Increment - No Display shift. lcd_cmd(0x80); // Address DDRAM with 0 offset 80h. }

    void lcd_cmd (char cmd)
    { lcd_port = ((cmd >> 4) & 0x0F)|LCD_EN; lcd_port = ((cmd >> 4) & 0x0F);

    lcd_port = (cmd & 0x0F)|LCD_EN; lcd_port = (cmd & 0x0F);

    delayus(200); delayus(200);
    }

    void lcd_data (unsigned char dat)
    { lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS); lcd_port = (((dat >> 4) & 0x0F)|LCD_RS);

    lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS); lcd_port = ((dat & 0x0F)|LCD_RS);

    delayus(200); delayus(200);
    }

  • The instructions for posting source code really are quite clearly stated: www.danlhenry.com/.../keil_code.png
    well 'stated' but not 'read' or, at least not 'followed'

    I'm perfectly calm, just want the OP to get help, which requires reading and following www.danlhenry.com/.../keil_code.png

    Erik

  • Hmmm.... if your ability to judge "working code" is as good as your ability notice illegible source code, I think that assertion must be open to considerable doubt...

  • Since you did not give use the pinout lets look at 1 function WITH the pre and \pre tags

    void lcd_data (unsigned char dat)
    {
       lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS); // Write High Nibble
       lcd_port = (((dat >> 4) & 0x0F)|LCD_RS);
    
       lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS);       // Write Low Nibble
       lcd_port = ((dat & 0x0F)|LCD_RS);
    
       delayus(200);                                  // wait 400 uSec
       delayus(200);
    }
    
     I ASSUME  the data is the lower nibble