Driving a 2x16 LCD with only One Pin and 74HC595


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Jan 2014
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Driving a 2x16 LCD with only One Pin and 74HC595

    Here I'm again.

    Again to my last post:
    I think over it again and C Flag is also an System Variable.
    Also too unsuitable.

    What have I done:

    I rewrite the code once again.
    I change the Variable Name's an insert your code from Statement 2.
    Could it be, that there is an small mistake.
    Code:
    F  var byte
    G  var byte
    
    ;D = B >> E
    F = E
    G = B
    ShiftLoop
       ;G = G >> 1
        G = G << 1
        F = F - 1
    IF F != 0 THEN ShiftLoop
    ;D = G.0
    D = G.7
    Once Again here is the code

    Code:
    Char_Temp             var byte
    ShiftOut_Steps        var byte
    Count_ShiftOut_Steps  var byte
    ShiftLoop_Steps       Var byte
    Bit_Shift             Var byte
    Readout_Bit           var bit
    
    INCLUDE "VirtualPort.bas"
    
    LCD_DATAUS    CON 2000
    LCD_COMMANDUS CON 50
    
    Goto Over_One_Wire_74HC595
    
    ;===============( DO NOT Change anything below this line )====================
    
    ASM ; Make sure HighJack has been installed in PBP's .LIB file
        ifndef LCDOUT_HIGHJACKED 
            error "HighJacked-LCDOUT Not found in PBPPIC??.LIB"
        endif
    ENDASM
    DEFINE  HJ_LCDOUT  _LCDsend    ; Redirect PBP's LCDOUT to LCDsend: Subroutine
    
    ;----[Send a byte to the Virtual LCD PORT]------------(DO NOT Change)---------
    TempChar        var  byte
    Char            VAR  Byte
    LCD_Initialized VAR  FLAGS.1
    RSS             VAR  FLAGS.0                ; LCD RS State
    
    ;----[ This routine is called once for every character sent by LCDOUT ]-------
    LCDsend:
          @  MOVE?AB  _TempChar                 ; Get char sent by LCDOUT, in WREG
          if !LCD_Initialized then LCD_Init     ; Make sure LCD was Initialized 
      LCDAfterInit:
          if TempChar = $FE then RSS=0 : goto LCDsendDone ; next char is Command 
          Char = TempChar
      LCDsendCOM:  
          Goto ShiftLoop_Char
      After_ShiftLoop_Char:
          IF RSS = 0 then                       ; Is a Command
              IF Char = 1 then CommandDelay     ; Long delay for Clear Screen
              IF Char = 2 then CommandDelay     ; Long delay for Home
              @  DelayUS   _LCD_DATAUS          ; Short delay for everything else
              goto DelayDone
          else                        
              @  DelayUS   _LCD_DATAUS          ; Short delay for Data
              goto DelayDone
          endif
      CommandDelay:
          @  DelayUS   _LCD_COMMANDUS
      DelayDone:
        if LCD_Initialized then RSS = 1       ; Set RS to Data next time
      LCDsendDone:
    return
    
    ;----[Initialize the LCD]-------------------(DO NOT Change)-------------------
    LCD_Init:
        ShiftOut_Steps = 2
        Char = $33 : gosub  LCDsendCOM : @  DelayUS 5000
                     gosub  LCDsendCOM : @  DelayUS 100
                     gosub  LCDsendCOM : @  DelayUS 100                 
        Char = $22 : gosub  LCDsendCOM   ; Start 4-bit mode
        
        ShiftOut_Steps = 5
        Char = $28 : gosub  LCDsendCOM   ; Function Set, 4-bit, 2-line, 5x7
        Char = $0C : gosub  LCDsendCOM   ; Display ON
        
        Char = $06 : gosub  LCDsendCOM   ; Entry Mode
        LCD_Initialized = 1              ; LCD has been Initialized
    goto LCDAfterInit
    
    ;----[Send it to 74HC595]-------------------(DO NOT Change)-------------------
    
    ShiftLoop_Char:
    For Count_ShiftOut_Steps = 0 to ShiftOut_Steps           ' For To Loop
    SELECT CASE Count_ShiftOut_Steps
     CASE 0
        Char_Temp = Char & %11110000                         ; Isolate Upper 4 Bits 
        If RSS = 1 Then : Char_Temp = Char_Temp | %00000100  ; Set RS Bit          
     CASE 1, 4
        Char_Temp = Char_Temp | %00001000                    ; Set Enable Bit 
     CASE 2, 5 
        Char_Temp = Char_Temp ^ %00001000                    ; Toggel Enable 
     Case 3     
        Char_Temp = Char << 1                                ; Shift Up Lower 4 Bits  
        Char_Temp = Char_Temp << 1
        Char_Temp = Char_Temp << 1
        Char_Temp = Char_Temp << 1 
        If RSS = 1 Then : Char_Temp = Char_Temp | %00000100  ; Set RS Bit            
    END SELECT
    Bit_Shift = Char_Temp
    
    ;----[Shift_Routine_74HC595 ]---------------(DO NOT Change)-------------------
    ShiftLoop_Steps = 7
    
    ShiftLoop: 
    
    Readout_Bit = Bit_Shift.7
    SELECT CASE Readout_Bit
    CASE 1 
      Serial_Pin = 0 : @  DelayUS 1         ; min 1 µs for 1
      Serial_Pin = 1 : @  DelayUS 15        ; min 15 µs 
    Case 0
      Serial_Pin = 0 : @  DelayUS 15        ; min 15 µs for 0
      Serial_Pin = 1 : @  DelayUS 30        ; min 30 µs 
    END SELECT
    
    Bit_Shift = Bit_Shift << 1
    ShiftLoop_Steps = ShiftLoop_Steps - 1
    IF ShiftLoop_Steps != 0 THEN : Goto ShiftLoop
    
    ;Latch
    Serial_Pin = 0 : @  DelayUS 200        ; min 200 µs for Latch 
    Serial_Pin = 1 : @  DelayUS 300        ; min 300 µs
    
    'Count_ShiftOut_Steps = Count_ShiftOut_Steps + 1                       ' for If Then Request
    'IF Count_ShiftOut_Steps != ShiftOut_Steps Then : goto ShiftLoop_Char  ' for If Then Request
    Next                                                                   ' For To Loop
    Goto After_ShiftLoop_Char
    
    Over_One_Wire_74HC595:
    I also wanted to replace the For To Loop with an normal If - Then request, because of the Usage of System Variables; or is there neither.
    It also works well but when I simulate it, it takes too much CPU Usage and Runs very slow.
    Using an Repeat Until Loop also.
    With an For To Loop the simulation is better.

    But which Loop is the best, when one think only about the Usage in an Microcontroller?
    What did you say. Is it OK or is there something which one can also improve.

    Thanks in advance!

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Driving a 2x16 LCD with only One Pin and 74HC595

    STATUS,C is not a PBP system variable. You can use it.

    FOR loops, REPEAT/UNTIL, WHILE/WHEN, DO/LOOP all do not use the system vars (as long as the test condition is = or !=).
    They will use system vars if the test condition is <, <=, >, >= etc.

    Speed differences between any of the loop types will not be significant on a real chip.
    The major slow down with this interface is the timing required to activate inputs on the 595 using the capacitors.
    All those delays in the code make writing to the LCD very slow.
    DT

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Driving a 2x16 LCD with only One Pin and 74HC595

    Your include looks better with the new variable names.
    I ran it this morning, and it seems to be working.

    Have you looked at the signals going to the 595 on a scope?
    Scary stuff to be putting in a digital chip.

    Yellow is the serial data.
    Blue is after the 1.5K resistor.
    Magenta is after the 33K resistor.

    Name:  1-wire_LCD_Scope.jpg
Views: 23849
Size:  136.5 KB

    And you can see that it takes 910 uS per nibble (1.82 mS per byte).

    It would be interesting to see how it works on real hardware.
    DT

Similar Threads

  1. 2x16 LCD Graphics :)
    By Art in forum General
    Replies: 51
    Last Post: - 13th June 2015, 11:02
  2. Need advice with LCD 2x16
    By fratello in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th April 2011, 06:58
  3. LCD via 74HC595
    By helloo in forum General
    Replies: 7
    Last Post: - 31st October 2010, 20:49
  4. 2x16 lcd problem
    By k3v1nP in forum mel PIC BASIC
    Replies: 11
    Last Post: - 30th October 2008, 04:46
  5. small 2X16 LCD
    By Ron Marcus in forum Off Topic
    Replies: 2
    Last Post: - 26th October 2007, 20:37

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts