' Picbasic routine to PIC18f4550 with CD4094
' 10/05/2011
Device = 18F4550
Declare XTAL 20
Symbol STROBE = PORTE.0 ' Strobe diplay
Symbol SCK = PORTB.1 ' Clock pin
Symbol SI = PORTB.0 ' Data in pin
Symbol SO = PORTB.0 ' Data out pin
Symbol RS = PORTB.4 ' R/S display
Symbol E = PORTB.2 ' Enable display
Dim Dado As Byte ' Data
Dim texto[16] As Byte
Dim Tmp As Byte
Dim It As Byte
'**********************************
'**********************************
Output STROBE ' Set Strobe to output
Output E ' Set Enable to output
Output RS ' Set RS to output
'**********************************************************************
DelayMS 100
GoSub Init_display
Loop:
GoSub Initialize
DelayMS 1000
GoTo Scan_all_key ' Routine to keyboard scan
'****************************************
'rotines to display
'*****************************************
Init_display:
SHOut SI, SCK, msbfirst, [0] ' Send write enable command
PulsOut STROBE, 10 ' Enable Strobe
RS = 0 ' Desbilita Display
DelayMS 50
Dado = 56
GoSub Instruc_to_display
Dado = 8
GoSub Instruc_to_display
Dado = 12
GoSub Instruc_to_display
Dado = 1
GoSub Instruc_to_display
RS = 1
Return
Instruc_to_display: ' Subroutine to send instructions to display
E = 1 ' Enable Display to send instructions
SHOut SO, SCK, msbfirst, [Dado] ' Send write enable command
PulsOut STROBE, 10 ' Enable Strobe to CD4094
E = 0 ' Disable display
DelayMS 10
Return
Data_to_display: ' Subroutine to send data to display
SHOut SO, SCK, msbfirst, [Dado]
PulsOut STROBE, 10 ' Enable Strobe to CD4094
PulsOut E, 20 ' Transfer data of CD4094 to display
DelayMS 1
Return
Clear_display:
RS = 0
Dado = 1
GoSub Instruc_to_display
Dado = $80
GoSub Instruc_to_display
RS = 1
Return
First_line:
RS = 0
Dado = $80
GoSub Instruc_to_display
RS = 1
Return
Second_line:
RS = 0
Dado = 192
GoSub Instruc_to_display
RS = 1
Return
Third_line:
RS = 0
Dado = $90
GoSub Instruc_to_display
RS = 1
Return
Fourth_linha:
RS = 0
Dado = $d0
GoSub Instruc_to_display
RS = 1
Return
Cursor_on:
RS = 0
Dado = $0F
GoSub Instruc_to_display
RS = 1
Return
Cursor_off:
RS = 0
Dado = $0C
GoSub Instruc_to_display
RS = 1
Return
Cursor_L2:
RS = 0
GoSub Instruc_to_display
RS = 1
Return
Initialize:
GoSub Clear_display
GoSub Text_1
GoSub Second_line
GoSub Text_2
GoSub Third_line
GoSub Text_3
GoSub Forth_line
GoSub Text_4
Return
Text_1:
str texto ="* Text to display *"
For It = 0 To 15
Dado = texto[It]
GoSub Data_to_display
Next
Return
Text_2:
str texto ="0123456789012345"
For It = 0 To 15
Dado = texto[It]
GoSub Data_to_display
Next
Return
Text_3:
str texto ="0123456789012345"
For It = 0 To 15
Dado = texto[It]
GoSub Data_to_display
Next
Return
Text_4:
str texto ="0123456789012345"
For It = 0 To 15
Dado = texto[It]
GoSub Data_to_display
Next
Return
Note: I made in Mikropascal too