Author Topic: Question about LCD  (Read 7969 times)

Offline Kuroro

  • Newbie
  • *
  • Posts: 38
    • View Profile
Question about LCD
« on: May 22, 2008, 05:05:38 PM »
Hello I have a question about your code :

Code: [Select]
static int fnInitDisplay(int iState)
{
    // After power up the display needs to be idle for >= 30ms. This is ensured by a start up delay of the task

    if ((ucDispCount != 0) && (!fnSendDisplay())) return iState;         // return when display transmitter busy, sending next byte on the way


    if (iState > WRITE_FUNCTION_SET) {
        return iState;                                                   // LCD is busy
    }

    switch (iState) {
    case STATE_INIT:                                                     // initialise the LCD hardware once on startup
        INITIALISE_LCD_CONTROL_LINES();                                  // initialise the LCD hardware once on startup
    case STATE_INITIALISING:
        _fnWriteDisplay(0, INIT_FUNCTION_SET);                           // write function set
        uTaskerMonoTimer( OWN_TASK, T_INIT_WAIT, E_INIT_CONTINUE );      // wait at least 4,1ms the first time and 100us the second time - we do longer waits than necessayr
        break;

    case WRITE_FUNCTION_SET:
        _fnWriteDisplay(0, INIT_FUNCTION_SET);                           // repeat after at least 4,1ms
        _fnWriteDisplay(0, INIT_FUNCTION_SET_MODE);                      // set final value after another 100us (after this the LCD is in the required 4 or 8 bit mode)
        uTaskerStateChange(OWN_TASK, UTASKER_GO);                        // switch to polling mode of operation since BF (Busy Flag) is not valid
        break;

    case STATE_INIT_2:
        fnWriteDisplay(0, (INIT_FUNCTION_SET_MODE | N_BIT | F_BIT));     // 2 line mode, display on
        break;

    case STATE_INIT_3:
        fnWriteDisplay(0, DISPLAY_OFF_NO_CURSOR);
        break;

    case STATE_INIT_4:
        fnWriteDisplay(0, CLEAR_DISPLAY);
        break;


    case STATE_DISPLAY_INITIALISED:
        fnWriteDisplay(0, DISPLAY_ON_NO_CURSOR);

        // At this point the display is clear and the cursor is at the home position.
        // we inform the application that the initialisation has terminated, so that it can start using it
        fnEventMessage(LCD_PARTNER_TASK, TASK_LCD, E_LCD_INITIALISED);
        return STATE_LCD_READY;                                          // we are ready to work....

    case STATE_LCD_SENDING:
        uTaskerStateChange(OWN_TASK, UTASKER_STOP);                      // switch to event mode of operation
        fnEventMessage(LCD_PARTNER_TASK, TASK_LCD, E_LCD_READY);         // we have completed an operation for the application
        break;

    default:                                                             
        if (iState > STATE_LCD_READY) {                                  // writing a pattern
            if (--iState <= STATE_LCD_READY) {                           // last character to be written
                iState = STATE_LCD_SENDING;
            }
            fnWriteLine(ucTXDisp, 1, O_CONTROL_RS);                      // repeat the test pattern
        }
        return iState;
    }

    return (++iState);
}

How it's possible to reach the case : STATE_INIT_2

The code :
 
Code: [Select]
if (iState > WRITE_FUNCTION_SET) {
        return iState;                                                   // LCD is busy
    }

Short circuit the next line.
Could you explain to me how does it work because i don't understand yet .
Thank's

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Question about LCD
« Reply #1 on: May 22, 2008, 07:27:55 PM »
Hi

Which project code are you using and has it been modified?

The compare
    if (iState > WRITE_FUNCTION_SET) {
        return iState;                                                   // LCD is busy
    }


doesn't exist in my code but rather

    if ((iState > WRITE_FUNCTION_SET) && ((fnReadDisplay(0) & LCD_BUSY))) {
        return iState;                                                   // LCD is busy
    }


This bypasses the fnReadDisplay() check until the state reaches WRITE_FUNCTION_SET since the state can not be read until after the INIT_FUNCTION_SET command has completed. The code that you have will not be able to work since it never polls the display and also never can pass the initialisation phase.
None of the uTasker projects (all with this LCD code dating back to 2005) have the code that you have, so I can't explain where this change has come from (???).

Regards

Mark

Offline Kuroro

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Question about LCD
« Reply #2 on: May 23, 2008, 07:29:25 AM »
I'm sorry you right i forgot i have modified it before i'm really sorry.

I work on a personal board and on the lcd port the rw pin is conected to the 0v so the lcd is all the time on write mode so i can't use the readdisplay function to check the busy state of the LCD so i have remove this check phase and I forgot i have do this modification.

Thank's