• PicŪ Basic

  • A driver for the LCD ST7036

    It is time to renew my driver for the ST7036 LCD controller. Based on Les's work in the "Hitachi_4.inc" and "Hitachi_8.inc" include files I have rewritten my driver more efficiently and made it perfectly compatible with the PDS compiler.
    The first job I did was to group these two files into a single file making it more universal. I also added a few lines of code to make it more automatic and secure in its initialisation. Of course, I have kept the feature "reversed bits" if needed for a future driver.

    It is now compatible with Arduino LCD shield

    1- I have included the codes to automatically configure the LCD pins in digital mode for all PORT pins. If any pin is missing let me know. This new feature will prevent some problems when users forget to write the pins in digital mode.

    2- Doing tests, I have realized I had problems when the LCD was poorly initiialised by intermittent contacts in the power plug. Checking the datasheet, I have seen that all registers were not written again. It is common in many codes because the LCD has its own initialisation at power-up. By having a quick interruption in power some registers were corrupted.

    When I added a few additional lines the initialisation problems caused by power outages disappeared. I applied these changes in the 2 libraries you can find below.

    Example of pin configuration in digital mode.
    This is the standard to configure the ST7036 controller.
    The LCD declare.
    ' LCD 4 bits in PORTB.0, Low nibble.
        Declare LCD_DTPin = PORTB.0
        Declare LCD_RSPin = PORTA.1
        Declare LCD_ENPin = PORTA.0
        Declare LCD_Interface = 4
        Declare LCD_Lines = 2
        Declare LCD_Type = Alphanumeric
        Declare LCD_CommandUs = 2000
        Declare LCD_DataUs = 50   
        Symbol LCD_CharsLenght = 16
        '$define LCD_Reverse_Bits
    Before modification:
        bcf TRISA,0,0        ; TRIS Output EN pin
        bcf LATA,0,0        ; Clear EN pin
        bcf TRISA,1,0        ; TRIS Output RS pin
        bcf LATA,1,0        ; Clear RS pin
        movlw 240
        andwf (__LCD_DTPORT + 0X12),F ; TRIS Output HALF PORT
    Now with the new driver:
        bcf ANSEL,0,0        ; EN pin to digital
        bcf TRISA,0,0        ; TRIS Output EN pin
        bcf LATA,0,0        ; Clear EN pin
        bcf ANSEL,1,0        ; RS pin to digital
        bcf TRISA,1,0        ; TRIS Output RS pin
        bcf LATA,1,0        ; Clear RS pin
        movlw 232
        andwf ANSELH,F,0        ; Half PORT to digital
        movlw 240
        andwf (__LCD_DTPORT + 0X12),F ; TRIS Output Half PORT
    The "LCD Hitachi.inc" file is ideal for use as a template for future LCD libraries.

    Attachment 2816

    The ST7036 LCD controller:
    The ST7036 dot-matrix liquid crystal display controller can be configured under the control of a 4-/8-bit interface microprocessor and low power operation support: 2.7 to 5.5V.
    The LCD driver that I propose dealing with uses parameters for a supply voltage of 3.3V. For a voltage of + 5V the LCD must be rewired and some internal parameters much be changed. The maximum display RAM size can be either 80 characters in 1-line display or 40 characters in 2-line display.
    Basically the ST7036 controller works as a Hitachi standard only when is already initialised. For that we must set at least four more registers.
    - Bias Set
    - Power/ICON Control/Contrast Set
    - Follower Control
    - Contrast Set

    The problem is that this driver has multiple pages or banks to access these parameters. Once these registers are initialised they must not be touched except for the contrast set in software only. It is a problem with this controller. In my demo code you can see how to adjust the contrast by 2 buttons or none.

    The Contrast:
    When the Cls command is used for the first time, the driver initialises, it will look in an EEPROM position for a contrast value previously written. If it not had, the code will determine a default value (7) and write it on the EEPROM in a position determined by the user.

    Adjust the contrast at compile time:
        'Read the current LCD Contrast from the LCD library and write a new contrast. (example)
        Contrast = LCD_ReadContrast()         ' Read the current contrast value. (default value 7)
        If Contrast <> 8 Then
            LCD_WriteContrast(8)              ' Set the LCD contrast to 8. (7 to 15)
            LCD_SaveContrast()                ' Save this value into the PIC eeprom
            Contrast = LCD_ReadContrast()     ' Read the new contrast.
    Adjustment of the constrast by buttons can be seen in the "TEST_LCD_ST7036_4Bits.BAS" file.
    To avoid errors in reading a contrast value from the eeprom, a special code has been provided ($A5). When writing, it means that a correct value of contrast is available in memory.

    Most PDS commands could be used, for example:
    Print $FE, 1 ' Clear the display.
    Print $FE, 2 ' Return Home.
    Print $FE, $0F ' Blinking cursor ON.

    In the case of DISPLAY/ON/OFF & Cursors, one command can destroy another configuration because it does not take into account the state of the other previous bits. The library commands consider these bits and always keeps them. Only these commands (Print $FE, XX) act on single or all bits. Better to use the commands of the library as they are more versatile.

    Commands of the LCD_ST7036.inc library.

    Contrast = LCD_ReadContrast()
    Returns the current contrast generated by the library Code.

    Write a new Contrast value To the LCD (only)

    Write the current Contrast value of the library To the eeprom data, if is different to the current value only.

    Clear the display, same as Print $FE, 1.

    Return home (beginning of the first line), same as Print $FE, 2.

    Turn the display On, does not modify the others cursor bits.

    Turn the display Off, does not modify the others cursor bits.

    Turns the underline Cursor On, does not modify the other cursor bits.

    Turns the underline Cursor Off, does not modify the other cursor bits.

    Turns the character to blink, if the cursor is On, the cursor blinks also.

    Turns off the blink function for cursor and character.

    Turns Off all functions of the cursor. Cursor and blinking are off.

    Shift the cursor to the left.

    Shift the cursor to the right.

    Move the entire display 1 position to the left.

    Move the entire display 1 position to the right.

    Other commands are available, consult the library.
    It would be good practice when moving into another table, that once completed the modification always returns to place the table 0.

    Additional commands:
    To make life easier I have incorporated some common commands.

    LCD_Clear_Row(number of line)
    Clear all the 16 characters of a line.

    CLL (Line, Pos) (unknown author)
    For users still using an alphanumeric LCD this provides a useful enhanced alternative to the standard Proton CLS command. When invoked with no parameters it will perform a standard Proton CLS, however, if you add a line number argument it will clear just that line, if you add a second argument (Position) it will clear from that position to the end of the line leaving the cursor at the beginning of the clear.

    Demo files:
    Two demo codes are available for connection to a 4-bit PORT and for a configuration of 2 lines and 1 line.
    I have not tried the 8-bit bus as the LCD that is very fragile. I've written the code necessary to run it so I hope it works.

    Update 26/03/2017 V1.2
    Write the 2 bytes of contrast at the end of the eeprom memory to avoid erasure by user code.
    See the new code HERE.
  • Recent Activity


    Mid$ not recognised

    Thread Starter: John Drew

    I'm trying to use Mid$ on a string using the 16F1827 which is an enhanced device. The compiler doesn't recognise the MID$. The compiler does...

    towlerg Today, 14:22 Go to last post