Menu

Improving the LCD.h library for LCD_IO 1 (Driving the SN74HC595 with 1 wire)

elreypic
2017-10-25
2017-10-27
  • elreypic

    elreypic - 2017-10-25

    Hello everyone,

    This is my first topic in this forum. Hopefully this can help to many people for this Great Compiler.
    I have realized that lcd.h library can be improved with the option 1, which one is for driving the SN75HC595 with 1 pin. Let's procede:

    1) Inside the library there is 3 subroutines: Zerobit, Onebit and ResetShiftReg. So the first and second ones look like this:
    Sub Zerobit ' Used in 1-wire mode; a "zero" bit is 10us low and minimal 20 us High
    SET LCD_CD OFF
    wait 10 us ' bit time
    SET LCD_CD ON
    wait 20 us ' recovery RC time
    wait 1 ms
    end sub

    Sub Onebit ' Used in 1-wire mode; a "one" bit is 1us low and minimal 5 us High
    SET LCD_CD OFF
    wait 1 us ' bit time
    SET LCD_CD ON
    wait 5 us ' recovery RC time
    wait 1 ms
    end sub

    So, the bolded instructions are slowing down the bits shifting to the SN74HC595, that means with this one it is delaying the next bit a 1 milisecond, which is not necesary at all. To improve these subroutines we should delete these 1ms delay.

    So the subroutines should be:
    Sub Zerobit ' Used in 1-wire mode; a "zero" bit is 10us low and minimal 20 us High
    SET LCD_CD OFF
    wait 10 us ' bit time
    SET LCD_CD ON
    wait 20 us ' recovery RC time
    end sub

    Sub Onebit ' Used in 1-wire mode; a "one" bit is 1us low and minimal 5 us High
    SET LCD_CD OFF
    wait 1 us ' bit time
    SET LCD_CD ON
    wait 5 us ' recovery RC time
    end sub

    The ResetShiftReg subroutine looks like:
    Sub ResetShiftReg ' Used in 1-wire mode; reset is 350 us low and minimal 300 us high
    SET LCD_CD OFF
    wait 350 us
    SET LCD_CD ON
    wait 300 us
    wait 1 ms

    end sub

    So the "wait" bolded instructions could be reduced to make the Reset faster. So, I did a analizis with a oscilloscope and I found out that the best time for both "wait" could be only 225 us. And once again the "wait 1ms" is not necesary, because once the LCD_CD line is high the shiftregister is already reset. We can delete that wait also. The subroutine should be:

    Sub ResetShiftReg ' Used in 1-wire mode; reset is 225 us low and minimal 225 us high
    SET LCD_CD OFF
    wait 225 us
    SET LCD_CD ON
    wait 225 us
    end sub

    2) The subroutine called LCD2_NIBBLEOUT can be improved also. It contains something like this:

    ResetShiftReg 'generate reset signal for shiftreg and activate monoflop
    'character delay settings
    #IFDEF LCD_Speed FAST 'Char Rate ~20K
    wait fast_us us
    '#ENDIF

           '#IFDEF LCD_SPEED MEDIUM  'Char Rate ~15K
                'wait medium_us us
          '#ENDIF
    
           '#IFDEF LCD_SPEED SLOW  ' Char Rate ~10K
                'wait slow_us us
           '#ENDIF
    
           '#IFNDEF LCD_SPEED ' default to slow
                'wait slow_us us
           '#ENDIF
    

    All above section doesn't make sense at all, becasue every time a data is shifted into the shiftregister a ResetShiftReg is executed and the line LCD_CD is set high for 225us (300us in the actual library) that is enough time to print a character on the LCD. I have done a test case and it is working good.

    I have attached the library and an example, so you can test it in deep just to double check and make sure all the functions are working fine.

    Regards,

    elreypic.

     

    Last edit: elreypic 2017-10-25
  • elreypic

    elreypic - 2017-10-25

    I tested it with GCB V0.95, so don't overwrite your actual lcd.h library.

     
  • bed

    bed - 2017-10-25

    Nice find!
    Do anybody know the source for the original schematics? Elektor, which year, Month? I would like to read the original Description

     
  • Theo

    Theo - 2017-10-25

    Please read this thread:
    https://sourceforge.net/p/gcbasic/discussion/579126/thread/da302460/

    There you can find an answer for the delays, source etc,etc.

    don't forget: a library must be general for all kind of hardware (slow and fast).
    Sometimes you need some delay in the software, otherwise the hardware can't follow it.

    But building a library for your own purpose; go for it.

     

    Last edit: Theo 2017-10-25
  • elreypic

    elreypic - 2017-10-25

    Hi bed,
    I took all the information from the on-line help from nest link:
    http://gcbasic.sourceforge.net/help/_lcd_io_1.html

    Hi Theo,
    I agree about how to create the library. This is an initial test. My next step is to implement the changes into the newest version of the compiler. I am testing on PIC microcontrollers only, but my next step is to test it on AVRs also.

    Regards,

    elreypic.

     
  • elreypic

    elreypic - 2017-10-26

    Hi everyone,

    I have tested the modifications on the newest lcd.h library and GCB V 0.98, so they work perfectly (as expected). I did a test using a PIC16F627A running at 4MHz (internal oscillator) and 16MHz. No issues.

    So, I just need to test it with an AVR microcontroller.
    Once I make the test I will upload the lcd.h library if you want to test it, but the final release needs to be aproved by the administrator and/or compiler creator.

    Regards,

    elreypic.

     
  • elreypic

    elreypic - 2017-10-27

    Hi everyone, its me again.

    I have tested my modifications to the lcd.h library in a AVR microcontroller, I mean, I did a test using a Arduino UNO board and it works perfectly fine.
    I have attached the lcd.h library (the newest + my modifications) and the exmaples that I did.

    I would like to ask to the administrator to review it and if he agree, to be aproved and released as official release.

    Thanks a lot and enjoy it.

    elreypic.

     

    Last edit: elreypic 2017-10-27
  • Anobium

    Anobium - 2017-10-27

    Thank you.

    If someone can regression test these adaptation then I can include in the release

    Anobium

     
  • bed

    bed - 2017-10-27

    Just for the records: the english root article should be here http://www.romanblack.com/shift1.htm
    especally the explain how it works is worth to read.
    Interesting stuff. When I consider a own DEv Board for Pics I'll take this as an option for Displays

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.