Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4745

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

$
0
0
Hello,

with the idea from this WebSide http://www.romanblack.com/shift1.htm, using the Darrel Taylor LCD_AnyPin.pbp + HighJack as a template and the willing to drive the LCD with only one Pin and to use the LCDOUT Command with all features, i wrote a routine for the 74HC595 controlling.

Attachment 7206

and here is the Code:


Code:

@ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_OFF

define osc 8

INTCON  = 0
PortA  = 0
PortB  = 0
TRISA  = 0                        ' CATODES TO PORTA
TRISB  = 0                        ' ANODES  TO PORTB
CMCON  = 7
 
Serial_Pin var PortA.3

B0 var byte
B1 VAR Byte
B2 VAR Byte
B3 VAR Byte
B4 var Byte
B5 VAR Byte
B6 VAR Byte
B7 VAR Byte

B0 = 0
B1 = 255
                     

;----[ Change these to match your LCD ]---------------------------------------
INCLUDE "One_Wire_74HC595.pbp" ; *** Include MUST be AFTER LCD Pin assignments *

;----[ Your Main program starts here ]----------------------------------------
LCDOUT $FE, 1
LCDOUT $FE, 1, IHex 255
Pause 2000
Start:
Repeat
B0 = B0 + 1
B1 = B1 - 1
B2 = B0 DIG 2
B3 = B0 DIG 1
B4 = B0 Dig 0
B5 = B1 DIG 2
B6 = B1 DIG 1
B7 = B1 Dig 0
LCDOUT $FE,$80,"Counter = ",#B2,#B3,#B4 
LCDOUT $FE,$C0,"Counter = ",#B5,#B6,#B7
Pause 1000
Until B0 > 254 OR B1 < 1
SWAP B0, B1
goto Start
END


Code:


A  var byte
B  var byte
C  var byte
D  var bit
E  VAR byte


INCLUDE "VirtualPort.bas"

LCD_DATAUS    CON 2000
LCD_COMMANDUS CON 50
'PAUSE 100 : LCDOUT $FE,1 : PAUSE 100  ; Initialize LCD

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:
      Gosub Toggle_Nibble
      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:
    A = 2
    Char = $33 : gosub  LCDsendCOM : @ DelayUS 5000
                    gosub  LCDsendCOM : @  DelayUS 100
                    gosub  LCDsendCOM : @  DelayUS 100               
    Char = $22 : gosub  LCDsendCOM  ; Start 4-bit mode
    A = 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

Toggle_Nibble:
For C = 0 to A
SELECT CASE c
 CASE 0
    B = Char & %11110000  ' Upper 4 Bits
    If RSS = 1 Then
      B = B | %00000100    ' Set RS Bit
    Endif     
 CASE 1, 4
    B = B | %00001000      ' Set Enable Bit
 CASE 2, 5
    B = B ^ %00001000      ' Enable Toggel
 Case 3   
    B = Char * 16              ' Lower 4 Bits Shift         
    If RSS = 1 Then
      B = B | %00000100    ' Set RS Bit
    Endif           
END SELECT
'******************************Shift_74HC595***********************************
E = 7
Repeat
D = B >> E
E = E - 1
SELECT CASE D
CASE 1
 Serial_Pin = 0
 @ nop            ' min 1 µs for 1
 Serial_Pin = 1     
 Pauseus 15        ' min 15 µs
Case 0
 Serial_Pin = 0
 Pauseus 15        ' min 15 µs for 0
 Serial_Pin = 1     
 Pauseus 30        ' min 30 µs danach
END SELECT   
Until E = 0

'Latch
Serial_Pin = 0
Pauseus 200        ' min 200 µs for Latch
Serial_Pin = 1       
Pauseus 300        ' min 300 µs
Next
Return

Over_One_Wire_74HC595:


As long as Strings will be send, all runs pretty good
Example:
LCDOUT $FE, 1, "Hello"

But I can do what I want, everytime I want to use the HEX, BIN, DEC, REP or STR commands i get Errors in displaying the correct Data.

Example:
LCDOUT, $FE, 1 IHex 255

I get F0 as answer and not $FF
Without I the answer is $220

What I also found out is, when I wrote a simple loop that show me the Hex Characters from 1 to 20....
Till 16 all is Displayed correct. After 16 till 20, 10 is displaying.


I hope somebody can help me.

Thanks

P.S. Sorry for my Bad English
Attached Images
 

Viewing all articles
Browse latest Browse all 4745

Trending Articles