Crystalfontz LCD


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Orginal Thought

    Yip i can buy one of those very nice looking units but still i want it to
    emulate a Crystalfonz unit.
    I like the idea of the 64 char buffer any idea's on how to do that

    Jman

  2. #2
    Join Date
    Jan 2007
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Better Now

    Hi
    The codes now looks like this
    i use hserin and now 9600 is perfect
    i also added contrast control (thanks to the forum serach for that).
    This code now works quite well LcdSmartie and my Miktotik routers.

    Regards Jman

    ' LCD should be connected as follows:
    ' LCD PIC
    ' DB4 PortA.0
    ' DB5 PortA.1
    ' DB6 PortA.2
    ' DB7 PortA.3
    ' RS PortB.7
    ' E PortB.6
    ' RW Ground
    ' Vdd 5 volts
    ' Vss Ground
    ' Vo PMW via20K potentiometer (or ground)
    ' DB0-3 No connect
    '
    '

    DEFINE OSC 20 'Set the Xtal frequency
    include "Modedefs.bas" 'Include general definitions

    'ADCON1 = 7 'Make all pins digital
    cmcon = 7 ' Make port Digital

    ' ** Declare LCDOUT Defines **
    DEFINE LCD_LINES 2
    Define LCD_DREG PORTA
    Define LCD_DBIT 0
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 7
    Define LCD_EREG PORTB
    Define LCD_EBIT 6




    ' HSERIN defines

    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 129 ' 9600 Baud @ 20MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically


    ' ** Define LCD Control Constants **

    CTL Con 254 ' Control Byte
    Clr Con 1 ' Clear the display
    HOME Con 2 'Beginning of the 1st line
    LINE1 Con 128 ' Point to beginning of line 1
    LINE2 Con 192 ' Point to beginning of line 2
    LINE3 Con 148 ' Point to beginning of line 3
    LINE4 Con 212 ' Point to beginning of line 4
    CGram Con 64 ' Point to Cgram within LCD
    DDram Con 128 ' Pont to DDRAM
    ShiftL Con 24 ' Shift display left
    ShiftR Con 28 ' Shift display right
    Blank Con 8 ' Blank display (don't clear memory)
    ULon Con 14 ' Underline ON
    BlinkCur Con 15 ' Blinking Cursor
    CurLeft Con 16 ' Move cursor left 1 position
    CurRight Con 20 ' Move cursor right 1 position
    BlockCur Con 13 ' Block cursor
    Space Con 32 'ASCII code for a space
    Null CON 0
    Restore CON 12

    ' ** Declare Variables **



    InByte1 Var byte ' The byte received
    InByte2 var byte ' Second byte recvd
    InBytes VAR BYTE[4] 'For multi commands
    contrast var byte 'General variables
    ch2 var byte
    ch3 var byte
    tmp var byte 'Temp var
    CGChar var byte[8] 'CGRam custom character
    CGAddr var byte 'CGRam address
    cnt var byte 'General use counter

    ' Init LCD
    Lcdout $fe, 1 ' Init LCD
    pause 100 ' Wait for LCD to Initialize

    'contrast set default
    'HPWM 1,20,1300


    '==== MAIN SECTION =======
    gosub Init
    InByte1 = " "

    MainLoop:
    HSerin [InByte1] ' Receive the serial byte
    if InByte1 <= 31 then goto LCDfonz
    if InByte1 >= 128 then goto Custom


    Lcdout InByte1 'Dispaly the Char

    Goto MainLoop

    LCDfonz:

    if InByte1 = 0 then MainLoop

    select case InByte1
    case 1
    lcdout CTL, Line1
    'LOW VDD 'lcdout ctl, 1
    'pause 30
    case 2
    Lcdout CTL, blank

    case 3

    Lcdout CTL, Restore

    case 4
    Lcdout CTL, 12

    Case 5
    lcdout ctl, ulon
    case 6
    lcdout ctl, blockcur
    case 7
    Lcdout CTL, blockcur
    case 8
    Lcdout CTL, curleft
    case 9
    hSerin [InBytes(0)] 'command Value
    case 10
    ' Null do nothing
    Case 11
    ' Null do nothing
    case 12
    lcdout CTL, $80
    lcdout " "
    lcdout CTL, $C0
    lcdout " "
    case 13
    ' Null do nothing
    case 14

    hSerin [InBytes(0)] 'Brightness
    'LOW VDD 'high vdd
    case 15
    hSerin [InBytes(0)] 'Contrast
    contrast = inbytes(0) * 2
    HPWM 1,contrast,1300
    case 16
    ' Null do nothing
    Case 17
    HSerin [InBytes(0), InBytes(1)]
    if InBytes(1) = 0 Then
    Lcdout CTL, ($80 + InBytes(0))
    else
    lcdout CTL, ($C0 + Inbytes(0))
    endif

    case 18
    ' Null do nothing
    case 19
    ' Null do nothing
    Case 20
    ' Null do nothing
    case 21
    ' Null do nothing
    case 22
    ' Null do nothing
    Case 23
    ' Null do nothing
    case 24
    ' Null do nothing
    case 25
    hserin [CGAddr, CGChar(0), CGChar(1),_
    CGChar(2), CGChar(3), CGChar(4), CGChar(5),_
    CGChar(6), CGChar(7)]
    Select case CGAddr
    Case 0
    LCDOUT CTL,64,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char

    Case 1
    LCDOUT CTL,72,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char

    Case 2
    LCDOUT CTL,80,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char

    Case 3
    LCDOUT CTL,88,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char

    Case 4
    LCDOUT CTL,96,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char

    Case 5
    LCDOUT CTL,104,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CG Char(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char

    Case 6
    LCDOUT CTL,112,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CG Char(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char

    Case 7
    LCDOUT CTL,120,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CG Char(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
    End select
    Case 26
    ' Null do nothing
    case 27
    ' Null do nothing
    case else
    'Lcdout CTL,InByte1
    end select
    goto Mainloop

    Custom:
    if InByte1 > 135 Then ' if not a custom Char then return
    'Lcdout InByte1
    Goto Mainloop
    endif

    select case InByte1
    case 128
    lcdout 0 ' Dispaly Custom Char 0
    case 129
    lcdout 1 ' Dispaly Custom Char 1
    case 130
    lcdout 2 ' Dispaly Custom Char 2
    case 131
    lcdout 3 ' Dispaly Custom Char 3
    case 132
    lcdout 4 ' Dispaly Custom Char 4
    Case 133
    lcdout 5 ' Dispaly Custom Char 5
    case 134
    lcdout 6 ' Dispaly Custom Char 6
    case 135
    Lcdout 7 ' Dispaly Custom Char 7

    end Select
    goto MainLoop





    Init:

    'Load Custom CGRam characters
    LCDOut CTL,64,$00,$04,$02,$1F,$02,$04,$00,$00,CTL,128
    LCDOut CTL,72,$00,$04,$08,$1F,$08,$04,$00,$00,CTL,128
    LCDOut CTL,80,$00,$04,$0E,$15,$04,$04,$00,$00,CTL,128
    LCDOut CTL,88,$00,$00,$04,$04,$15,$0E,$04,$00,CTL,128
    LCDOut CTL,96,$1F,$11,$11,$11,$11,$11,$11,$1F,CTL,128
    LCDOut CTL,104,$04,$0E,$1F,$00,$00,$1F,$0E,$04,CTL,128
    LCDOut CTL,112,$02,$06,$0E,$1E,$0E,$06,$02,$00,CTL,128
    LCDOut CTL,120,$08,$0C,$0E,$0F,$0E,$0C,$08,$00,CTL,128

    logo:
    Lcdout CTL,LINE1,"Crystal EMU Ver .99"
    Lcdout CTL,LINE2,"Jman says 9600 baud"
    Lcdout CTL,HOME


    Return

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default nasty typo

    Hi jman,
    you got a typo that will cause a no compile
    Code:
    LCDOUT CTL,64,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
    it says CGC har instead if CGChar in 8 places.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Jan 2007
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Typo

    HI
    It was during the copy paste from microcode mine has no compile errors
    and looks good in microcode
    Also the contrast is now connected to pmw pin with 2 resistors as per Mels diagram
    Thanks for looking

    Jman
    Last edited by jman12; - 4th February 2007 at 10:33.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you could still shrink it a little bit
    Code:
    LCDOUT LCDOUT CTL,64, STR CGChar\8 ' Write Custom Char
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jan 2007
    Posts
    6


    Did you find this post helpful? Yes | No

    Default shrink

    Thanks Mister E worked perfect.
    Any clue on how to add a buffer 64 chars would be nice

    John

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
            BufferChar VAR BYTE[64]
            '      
            '
            '
            '
            '
            '
            '
            HSERIN [STR BufferChar\64]
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Is this code not initialising the LCD properly?
    By Platypus in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 30th January 2010, 19:14
  2. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  3. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  4. LCD Problem
    By karenhornby in forum General
    Replies: 3
    Last Post: - 19th June 2008, 11:43
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

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