More than 8 Custom Chars on LCD?


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164

    Default More than 8 Custom Chars on LCD?

    I'm using a standard garden-variety 2x16 LCD and a PIC18F2550. What I'd like to do is make a larger number font by putting the top half of the digit on the first line and the bottom half on the second line. Obviously, it would take a total of 20 special characters to to make all ten digits; the CGRAM only allows eight custom characters. I thought (incorrectly, as it turns out) I could re-use characters but instead it refreshes previous instances.

    Here's my testing code:

    Code:
    ' PIC18F2550
    
    'Pin Assignments
    '---------------
    ' Pin	Name	           Use/Connection
    '------------------------------------
    '  1  MCLR			Master Clear/Reset.  Pull High through 4.7k
    '  2  RA0/AN0		LCD RS
    '  3  RA1/AN1		LCD R/W
    '  4  RA2/AN2		LCD Enable
    '  5  RA3/AN3		n/c
    '  6  RA4/T0CKI		n/c
    '  7  RB5/AN4		n/c
    '  8  Vss			Ground
    '  9  OSC1			20 MHz resonator
    ' 10  OSC2			20 MHz resonator
    ' 11  RC0/T1CKI		To 32 kHz crystal
    ' 12  RC1/CCP2		To 32 kHz crystal
    ' 13  RC2/CCP1		n/c
    ' 14  Vusb			To USB (internal USB 3.3V voltage regulator)
    
    ' 15  RC4/D-		To USB (USB differential minus line)
    ' 16  RC5/D+		To USB (USB differential plus line)
    ' 17  RC6/TX		To MAX232
    ' 18  RC7/RX		To MAX232
    ' 19  Vss			Ground
    ' 20  Vdd			Voltage in (5V from USB)
    ' 21  RB0/INT		LCD DB0
    ' 22  RB1			LCD DB1
    ' 23  RB2			LCD DB2
    ' 24  RB3			LCD DB3
    ' 25  RB4			LCD DB4
    ' 26  RB5			LCD DB5
    ' 27  RB6			LCD DB6
    ' 28  RB7			LCD DB7
    
    ' Compiler directives:
    Define  OSC 20
    DEFINE LOADER_USED 1 'Bootloader Used
    'Set receive register to receiver enabled
    DEFINE HSER_RCSTA 90h
    'Set transmit register to transmitter enabled, high speed BRGH
    DEFINE HSER_TXSTA 24h
    'Set baud rate
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1 
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTA
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTA
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 8
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 3000
    DEFINE LCD_DATAUS 200
    
    ADCON1 = 15
    CMCON = 7
    
    TRISB = %00000000
    TRISA.0 = $0
    TRISA.1 = $0
    TRISA.2 = $0
    
    
    low PORTA.1
    
    'high PORTA.2
    pause 500
    LCDOUT $FE,1
    
    MAIN_LOOP:	
    	'Big "1"
    	LCDOUT  $FE,$40,$00,$00,$04,$0C,$04,$04,$04,$04		' Cust Char #0, big "1" top half
    	LCDOUT  $FE,$48,$04,$04,$04,$04,$04,$0E,$00,$00		' Cust Char #1, big "1" bottom half
    	LCDOUT $FE,$80,0									' Put it as 1st line, 1st char
    	LCDOUT $FE,$C0,1 									' Put it as 2nd line, 1st char
    
    	'Big "2"
    	LCDOUT  $FE,$50,$00,$00,$0E,$11,$01,$01,$01,$02		' Cust Char #2, big "2" top half
    	LCDOUT  $FE,$58,$04,$08,$08,$10,$10,$1F,$00,$00		' Cust Char #3, big "2" bottom half
    	LCDOUT  $FE,$81,2									' Put it as 1st line, 2nd char
    	LCDOUT  $FE,$C1,3									' Put it as 2nd line, 2nd char
    
    	'Big "3"
    	LCDOUT  $FE,$60,$00,$00,$0E,$11,$01,$01,$01,$06		' Cust Char #4, big "3" top half
    	LCDOUT  $FE,$68,$01,$01,$01,$01,$11,$0E,$00,$00		' Cust Char #5, big "3" bottom half  
    	LCDOUT  $FE,$82,4									' Put it as 1st line, 3rd char
    	LCDOUT  $FE,$C2,5									' Put it as 2nd line, 3rd char
    
    	'Big "4"
    	LCDOUT  $FE,$70,$00,$00,$06,$06,$0A,$0A,$12,$12		' Cust Char #6, big "4" top half
    	LCDOUT  $FE,$78,$12,$1F,$02,$02,$02,$02,$00,$00		' Cust Char #7, big "4" bottom half  
    	LCDOUT  $FE,$83,6									' Put it as 1st line, 4th char
    	LCDOUT  $FE,$C3,7									' Put it as 2nd line, 4th char
    
    	pause 2000
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    	'Big "5"
    	LCDOUT  $FE,$40,$00,$00,$1F,$10,$10,$10,$1E,$01		' Cust Char #0, big "5" top half
    	LCDOUT  $FE,$48,$00,$01,$01,$01,$11,$0E,$00,$00		' Cust Char #1, big "5" bottom half  
    	LCDOUT  $FE,$84,0									' Put it as 1st line, 5th char
    	LCDOUT  $FE,$C4,1									' Put it as 2nd line, 5th char
    
    	'Big "6"
    	LCDOUT  $FE,$50,$00,$00,$06,$08,$08,$10,$1E,$11		' Cust Char #2, big "6" top half
    	LCDOUT  $FE,$58,$11,$11,$11,$11,$11,$0E,$00,$00		' Cust Char #3, big "6" bottom half  
    	LCDOUT  $FE,$85,2									' Put it as 1st line, 6th char
    	LCDOUT  $FE,$C5,3									' Put it as 2nd line, 6th char
    
    	'Big "7"
    	LCDOUT  $FE,$60,$00,$00,$1F,$01,$01,$01,$01,$01		' Cust Char #4, big "7" top half
    	LCDOUT  $FE,$68,$02,$04,$04,$08,$08,$08,$00,$00		' Cust Char #5, big "7" bottom half  
    	LCDOUT  $FE,$86,4									' Put it as 1st line, 7th char
    	LCDOUT  $FE,$C6,5									' Put it as 2nd line, 7th char
    
    	'Big "8"
    	LCDOUT  $FE,$70,$00,$00,$0E,$11,$11,$11,$11,$0E		' Cust Char #6, big "8" top half
    	LCDOUT  $FE,$78,$11,$11,$11,$11,$11,$0E,$00,$00		' Cust Char #7, big "8" bottom half  
    	LCDOUT  $FE,$87,6									' Put it as 1st line, 8th char
    	LCDOUT  $FE,$C7,7									' Put it as 2nd line, 8th char
    	pause 2000
    
    goto MAIN_LOOP
    What I *thought* it should do is show "1234" in big numerals, pause, then show "12345678".

    Instead it shows "1234" then goes back and forth between "56785678" and "12341234".

    Is there a way to accomplish the goal of forcing the LCD to show the digits 0-9 with double height?

    Thanks for reading...8^)

    Paul

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


    Did you find this post helpful? Yes | No

    Default Hope this helps

    Here is a link to Scott Edwards site: http://www.seetron.com/pdf/lcd_an1.pdf
    The code listed below was adapted by Darrel T. I think from the link I posted. I am sure you will find it somewhere in this forum but I neglected to add the URL to the code when I saved it.
    Code:
    '****************************************************************
    '*  Name    : BigNums.BAS                                       *
    '*  Author  : Scott Edwards, adapted by Darrel Taylor           *
    '*  Notice  : Copyright (c)                                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 2/20/07                                           *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    ;Initialize your hardware first
    
    'BIGNUMS.BS2 (Display four 1" digits on 4x20 display)
    ' Connect the serial input of a Backpack-equipped 4x20 display to
    ' BS2 pin P0 and run this program. The program will define a set
    ' of symbols that allow it to display 4-line-tall numerals on the
    ' LCD. To incorporate this capability into your own programs, just
    ' substitute your code for the demo loop. When you want to display
    ' a value (0-9999) in big numerals, write it to dispVal, then
    ' gosub bigLCD.
    I       con 254 ' Instruction prefix.
    ClrLCD  con 1 ' Clear-LCD instruction.
    N96N    con $4054 ' 9600 baud, inverted, no parity.
    cgRAM   con 64 ' Address 0 of CG RAM.
    EEptr   var word ' Pointer into EEPROM.
    pat     var EEptr ' Alias for EEptr.
    dispVal var word ' Value to be displayed as big digits.
    temp    var byte ' Temporary byte variable.
    decade  var word
    nbl     var byte ' Index into number-pattern tables.
    digit   var byte ' Current digit to display
    line    var byte ' LCD line
    
    LCDOUT I,ClrLCD
    PAUSE 500
    
    ' ====This section may be omitted with newer (post July 96)
    ' ====4x20 Serial LCD modules. Cut from here...============== >>>
    bitPat0 DATA 0,0,0,1,3,7,15,31 ' Left-right up-ramp shape.
    bitPat1 DATA 0,0,0,16,24,28,30,31 ' Right-left " "
    bitPat2 DATA 31,15,7,3,1,0,0,0 ' Left-right down ramp.
    bitPat3 DATA 31,30,28,24,16,0,0,0 ' Right-left " "
    bitPat4 DATA 0,0,0,0,31,31,31,31 ' Lower block.
    bitPat5 DATA 31,31,31,31,0,0,0,0 ' Upper block.
    bitPat6 DATA 31,31,31,31,31,31,31,31 ' Full block.
    bitPat7 DATA 0,0,0,0,0,0,0,0 ' Full blank
    ' <<<...to here. ===============================================
    ;low 0 ' Make the serial output low
    ;pause 1000 ' Let the LCD wake up.
    ' ====This section may be omitted with newer (post July 96)
    ' ====4x20 Serial LCD modules. Cut from here...============= >>>
    ;serout 0,N96N,[I,cgRAM] ' Enter CG RAM.
    LCDOUT I,cgRAM
    
    for EEptr = 0 to 63 ' Write the bit patterns
        Read EEptr,temp ' to the LCD.
    ;    serout 0,N96N,[temp]
        lcdout temp
    next
    ' <<<...to here. ===============================================
    ;serout 0,N96N,[I,ClrLCD] ' Clear the LCD.
    LCDOUT I, ClrLCD
    pause 1
    ' ========================================================================
    ' Demo Loop: Show dispVal in Big Numerals, Increment, Loop
    ' ========================================================================
    again:
        gosub bigLCD
        dispVal = dispVal + 1
        pause 500
    goto again
    ' ========================================================================
    ' Subroutine Displaying Large Numbers
    ' ========================================================================
    bigLCD:
        for line = 0 to 3
            decade = 1000
            lookup line,[128,192,148,212],temp
            
    ;        serout 0,N96N,[I,temp]
            LCDOUT I, temp
            for digit = 3 to 0 step -1
                nbl = dispVal dig digit
                gosub getPattern
                if dispVal = 0 and digit = 0 then skip0
                if dispVal < decade then blankIt
                skip0:
    ;            serout 0,N96N,[pat.nib3,pat.nib2,pat.nib1,pat.nib0]
                LCDOUT pat.Highbyte>>4, pat.Highbyte&$0F, pat.LowByte>>4, pat.Lowbyte&$0F
    
                goto cont
                blankIt:
    ;            serout 0,N96N,["    "]
                lcdout "    "
                cont:
                if digit = 0 then skip1
    ;            serout 0,N96N,[32]
                LCDOUT 32
                skip1:
                decade = decade/10
            next
        next
    return
    ' Subroutines Defining Big-Character Patterns
    ' ========================================================================
    getPattern:
    branch line,[first,second,third,fourth]
    ' 0 1 2 3 4 5 6 7 8 9
    ' --- --- --- --- --- --- --- --- --- ---
    first:
    lookup2 nbl,[$0551,$7067,$0551,$0551,$6776,$6555,$0557,$2556,$0551,$0551],pat
    return
    second:
    lookup2 nbl,[$6776,$7767,$7743,$7743,$6776,$2441,$6041,$7703,$2443,$6776],pat
    return
    third:
    lookup2 nbl,[$6776,$7767,$0577,$7751,$2556,$7776,$6776,$7767,$0551,$2536],pat
    return
    fourth:
    lookup2 nbl,[$2443,$7464,$6444,$2443,$7776,$2443,$2443,$7767,$2443,$7443],pat
    return
    I very sincerely hope it has not gotten corrupted sometime after I saved it. As always I offer all statements to be opinions and not necessarly facts.
    EDIT: Here is a version from mister_e
    Code:
    '****************************************************************
    '*  Name    : Big_Num.BAS                                      *
    '*  Author  :                                         *
    '*  Notice  : Copyright (c) 2007                      *
    '*          : All Rights Reserved                               *
    '*  Date    : 1/3/07                                            *
    '*  Version : 1.0                                               *
    '*  Notes   :Mister_e's big numbers for 16F877a                 *
    '*          :                                                   *
    '****************************************************************
    DEFINE LOADER_USED 1
    Define OSC 4
    DEFINE LCD_DREG PORTD     ' LCD data port 
    DEFINE LCD_DBIT 4         ' LCD data starting bit 0 or 4 
    DEFINE LCD_RSREG PORTD    ' LCD register select port 
    DEFINE LCD_RSBIT 2        ' LCD register select bit 
    DEFINE LCD_EREG PORTD     ' LCD enable port 
    DEFINE LCD_EBIT 3         ' LCD enable bit 
    DEFINE LCD_BITS 4         ' LCD bus size 4 or 8 
    DEFINE LCD_LINES 4        ' Number lines on LCD 
    DEFINE LCD_COMMANDUS 2000 ' Command delay time in us 
    DEFINE LCD_DATAUS 50      ' Data delay time in us 
    
        Clr     CON 1
        Comm    con $FE
        EOL     con $FC
        Dx      con $14
        Line    var byte[4]
            line[0]=$80
            line[1]=$C0
            line[2]=$94
            line[3]=$D4
    
        Zero    data 5,0,0,4,EOL
                data $FF,Comm,Dx,Comm,Dx,$FF,EOL
                data $FF,Comm,Dx,Comm,Dx,$FF,EOL
                data 2,1,1,3,EOL
                data 5
        
        One     data Comm,Dx,5,$ff,EOL
                data Comm,Dx,Comm,Dx,$ff,EOL
                data Comm,Dx,Comm,Dx,$ff,EOL
                data Comm,Dx,Comm,Dx,$ff,EOL
                data 5;3
        
        Two     data 0,0,0,4,EOL
                data Comm,Dx,Comm,Dx,Comm,Dx,$ff,EOL
                data 5,0,0,0,EOL
                data $ff,1,1,1,EOL
                data 5
              
        Three   data 0,0,0,4,EOL
                data Comm,Dx,Comm,Dx,Comm,Dx,$ff,EOL
                data Comm,Dx,0,0,$ff,EOL
                data 1,1,1,3,EOL
                data 5    
        
        Four    data $ff,Comm,Dx,Comm,Dx,$FF,EOL
                data $ff,Comm,Dx,Comm,Dx,$ff,EOL
                data 0,0,0,$ff,EOL
                data Comm,Dx,Comm,Dx,Comm,Dx,$ff,EOL
                data 5    
        
        Five    data $FF,0,0,0,EOL
                data $ff,EOL
                data 0,0,0,4,EOL
                data 1,1,1,3,EOL
                data 5    
        
        Six     data 5,0,0,EOL
                data $ff,EOL
                data $ff,0,0,4,EOL
                data 2,1,1,3,EOL
                data 5    
        
        Seven   data 0,0,0,4,EOL
                data Comm,Dx,Comm,Dx,comm,dx,$ff,EOL
                data Comm,Dx,Comm,Dx,comm,dx,$ff,EOL
                data Comm,Dx,Comm,Dx,Comm,Dx,$ff,EOL
                data 5    
                
        Eight   data 5,0,0,4,EOL
                data 2,1,1,3,EOL
                data 5,0,0,4,EOL
                data 2,1,1,3,EOL
                data 5
        
        Nine    data 5,0,0,4,EOL
                data 2,1,1,$ff,EOL
                data Comm,Dx, Comm,Dx,Comm,Dx,$ff,EOL
                data Comm,Dx,1,1,3,EOL
                data 5
                        
        Punto   data EOL
                data EOL
                data EOL
                data 7,EOL
                data 2
    
        offset      var byte 
        index       var byte 
        Char        var byte 
        ActualLine  var byte 
        CounterA    var word 
        CounterB    var byte 
        Number      var byte 
        Pattern     var word[11]
            pattern[0]=zero
            pattern[1]=one
            Pattern[2]=two
            pattern[3]=three
            pattern[4]=four
            Pattern[5]=Five
            Pattern[6]=Six
            Pattern[7]=Seven
            pattern[8]=eight
            pattern[9]=Nine
            pattern[10]=Punto
            
        pause 500
    DumpCustChar:
        index=0
        repeat
            lookup index,[Comm,64,31,31,31,31,0,0,0,0,_      ; Cust Char #0  
                          Comm,72,0,0,0,0,31,31,31,31,_      ; Cust Char #1  
                          Comm,80,31,31,31,15,7,3,1,0,_      ; Cust Char #2  
                          Comm,88,31,31,31,30,28,24,16,0,_   ; Cust Char #3  
                          Comm,96,0,16,24,28,30,31,31,31,_   ; Cust Char #4  
                          Comm,104,0,1,3,7,15,31,31,31,_     ; Cust Char #5  
                          Comm,112,31,31,31,31,31,31,31,31,_ ; Cust Char #6  
                          Comm,120,0,0,0,14,31,31,31,14],char; Cust Char #7  
            lcdout char
            index=index+1
            until index=80
    
    Main:  
        countera=0
        repeat
            offset=0
            lcdout comm,clr
            counterb=3
            repeat
                number=countera dig counterb
                gosub displaynumber
                counterb=counterb-1
                until counterb=255
            pause 10
            countera=countera+1
            until countera=10000
            goto main
    
    DisplayNumber:
        actualline=0
        index=0
        lcdout comm,line[0]+offset
        Loop:
            read pattern[number]+index,char
            if char!=eol then 
                if actualline<4 then
                    lcdout char
                    else
                        offset=offset+char
                        Goto GetOut
                    endif
                else
                    actualline=actualline+1
                    if actualline<4 then lcdout comm,line[actualline]+offset
                endif
            index=index+1
            goto loop
        GetOut:
            RETURN
    Again I failed to save the URL.
    Last edited by Archangel; - 9th June 2010 at 05:16.
    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.

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Is there a way to accomplish the goal of forcing the LCD to show the digits 0-9 with double height?
    The answer is NO. Not more than 4 unique double height digits at a time. Optionally, use a graphic LCD.

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    The double line high digits use a series of blocks that only consume the eight custom characters:
    http://www.doc.ic.ac.uk/~ih/doc/lcd/double.html
    so you can display as many digits as the display can show.

    You still couldn't make the font very detailed like you probably wanted to.
    Last edited by Art; - 9th June 2010 at 11:18.

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Art, thanks for the link. I take back my words. I stand corrected.

  6. #6
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Art,

    Thanks! That was *exactly* what I needed. Here's a (low-quality) picture of the result:

    Name:  Big_Num_LCD.jpg
Views: 3195
Size:  54.2 KB

    Complete code:
    Code:
    ' PIC18F2550
    
    'Pin Assignments
    '---------------
    ' Pin	Name	           Use/Connection
    '------------------------------------
    '  1  MCLR			Master Clear/Reset.  Pull High through 4.7k
    '  2  RA0/AN0		LCD RS
    '  3  RA1/AN1		LCD R/W
    '  4  RA2/AN2		LCD Enable
    '  5  RA3/AN3		n/c
    '  6  RA4/T0CKI		n/c
    '  7  RB5/AN4		n/c
    '  8  Vss			Ground
    '  9  OSC1			20 MHz resonator
    ' 10  OSC2			20 MHz resonator
    ' 11  RC0/T1CKI		To 32 kHz crystal
    ' 12  RC1/CCP2		To 32 kHz crystal
    ' 13  RC2/CCP1		n/c
    ' 14  Vusb			To USB (internal USB 3.3V voltage regulator)
    
    ' 15  RC4/D-		To USB (USB differential minus line)
    ' 16  RC5/D+		To USB (USB differential plus line)
    ' 17  RC6/TX		To MAX232
    ' 18  RC7/RX		To MAX232
    ' 19  Vss			Ground
    ' 20  Vdd			Voltage in (5V from USB)
    ' 21  RB0/INT		LCD DB0
    ' 22  RB1			LCD DB1
    ' 23  RB2			LCD DB2
    ' 24  RB3			LCD DB3
    ' 25  RB4			LCD DB4
    ' 26  RB5			LCD DB5
    ' 27  RB6			LCD DB6
    ' 28  RB7			LCD DB7
    
    ' Compiler directives:
    Define  OSC 20
    DEFINE LOADER_USED 1 'Bootloader Used
    'Set receive register to receiver enabled
    DEFINE HSER_RCSTA 90h
    'Set transmit register to transmitter enabled, high speed BRGH
    DEFINE HSER_TXSTA 24h
    'Set baud rate
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1 
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTA
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTA
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 8
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 3000
    DEFINE LCD_DATAUS 200
    
    ADCON1 = 15
    CMCON = 7
    
    TRISB = %00000000
    TRISA.0 = $0
    TRISA.1 = $0
    TRISA.2 = $0
    
    nPos var byte
    
    low PORTA.1
    
    'high PORTA.2
    pause 500
    LCDOUT $FE,1
    
    'Set up the digits (http://www.darreltaylor.com/files/CustChar.htm)
    LCDOUT  $FE,$40,$01,$01,$01,$01,$01,$01,$01,$01  ' Cust Char #0 
    'LCDOUT  $FE,$40,$02,$02,$02,$02,$02,$02,$02,$02  ' Cust Char #0   
    LCDOUT  $FE,$48,$1F,$11,$11,$11,$11,$11,$11,$11  ' Cust Char #1  
    LCDOUT  $FE,$50,$1F,$10,$10,$10,$10,$10,$10,$1F  ' Cust Char #2  
    LCDOUT  $FE,$58,$01,$01,$01,$01,$01,$01,$01,$1F  ' Cust Char #3  
    LCDOUT  $FE,$60,$1F,$11,$11,$11,$11,$11,$11,$1F  ' Cust Char #4  
    LCDOUT  $FE,$68,$11,$11,$11,$11,$11,$11,$11,$1F  ' Cust Char #5  
    LCDOUT  $FE,$70,$1F,$01,$01,$01,$01,$01,$01,$1F  ' Cust Char #6  
    LCDOUT  $FE,$78,$1F,$01,$01,$01,$01,$01,$01,$01  ' Cust Char #7  
      
    GOTO MAIN_LOOP
    
    Zero:
    	LCDOUT $FE,$80+nPos,1
    	LCDOUT $FE,$C0+nPos,5
    return
    
    One:
    	LCDOUT $FE,$80+nPos,0
    	LCDOUT $FE,$C0+nPos,0
    return
    
    Two:
    	LCDOUT $FE,$80+nPos,7
    	LCDOUT $FE,$C0+nPos,2
    return
    
    Three:
    	LCDOUT $FE,$80+nPos,6
    	LCDOUT $FE,$C0+nPos,3
    return
    
    Four:
    	LCDOUT $FE,$80+nPos,5
    	LCDOUT $FE,$C0+nPos,0
    return
    
    Five:
    	LCDOUT $FE,$80+nPos,2
    	LCDOUT $FE,$C0+nPos,3
    return
    
    Six:
    	LCDOUT $FE,$80+nPos,2
    	LCDOUT $FE,$C0+nPos,5
    return
    
    Seven:
    	LCDOUT $FE,$80+nPos,7
    	LCDOUT $FE,$C0+nPos,0
    return
    
    Eight:
    	LCDOUT $FE,$80+nPos,4
    	LCDOUT $FE,$C0+nPos,5
    return
    
    Nine:
    	LCDOUT $FE,$80+nPos,4
    	LCDOUT $FE,$C0+nPos,3
    return
    
    MAIN_LOOP:
    	nPos = 0
    	GOSUB Zero
    	nPos = 1
    	GOSUB One
    	nPos = 2
    	GOSUB Two
    	nPos = 3
    	GOSUB Three
    	nPos = 4
    	GOSUB Four
    	nPos = 5
    	GOSUB Five
    	nPos = 6
    	GOSUB Six
    	nPos = 7
    	GOSUB Seven
    	nPos = 8
    	GOSUB Eight
    	nPos = 9
    	GOSUB Nine
    
    	PAUSE 2000
    GOTO MAIN_LOOP
    And thanks to everyone else for reading and commenting. You folks are the best...

    Best Regards,
    Paul

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Wow, it looks a lot nicer on the LCD than it did on the web page.

  8. #8
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    And if we have a variable byte or word how to display?

  9. #9
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    And if we have a variable byte or word how to display?
    Use the DIG function. The demo below counts up to 65534, showing each number for 25mS. It also blanks out any leading zeros.

    Code:
    ' PIC18F2550
    
    'Pin Assignments
    '---------------
    ' Pin	Name	           Use/Connection
    '------------------------------------
    '  1  MCLR			Master Clear/Reset.  Pull High through 4.7k
    '  2  RA0/AN0		LCD RS
    '  3  RA1/AN1		LCD R/W
    '  4  RA2/AN2		LCD Enable
    '  5  RA3/AN3		n/c
    '  6  RA4/T0CKI		n/c
    '  7  RB5/AN4		n/c
    '  8  Vss			Ground
    '  9  OSC1			20 MHz resonator
    ' 10  OSC2			20 MHz resonator
    ' 11  RC0/T1CKI		To 32 kHz crystal
    ' 12  RC1/CCP2		To 32 kHz crystal
    ' 13  RC2/CCP1		n/c
    ' 14  Vusb			To USB (internal USB 3.3V voltage regulator)
    
    ' 15  RC4/D-		To USB (USB differential minus line)
    ' 16  RC5/D+		To USB (USB differential plus line)
    ' 17  RC6/TX		To MAX232
    ' 18  RC7/RX		To MAX232
    ' 19  Vss			Ground
    ' 20  Vdd			Voltage in (5V from USB)
    ' 21  RB0/INT		LCD DB0
    ' 22  RB1			LCD DB1
    ' 23  RB2			LCD DB2
    ' 24  RB3			LCD DB3
    ' 25  RB4			LCD DB4
    ' 26  RB5			LCD DB5
    ' 27  RB6			LCD DB6
    ' 28  RB7			LCD DB7
    
    ' Compiler directives:
    Define  OSC 20
    DEFINE LOADER_USED 1 'Bootloader Used
    'Set receive register to receiver enabled
    DEFINE HSER_RCSTA 90h
    'Set transmit register to transmitter enabled, high speed BRGH
    DEFINE HSER_TXSTA 24h
    'Set baud rate
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1 
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTA
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTA
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 8
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 1600'3000
    DEFINE LCD_DATAUS 50'200
    
    TRUE        	CON 1
    FALSE       	CON 0
    
    ADCON1 = 15
    CMCON = 7
    
    TRISB = %00000000
    TRISA.0 = $0
    TRISA.1 = $0
    TRISA.2 = $0
    
    nPos var byte
    wVal var WORD
    nDig var byte
    bDoneWithLeadingZeros var bit
    
    low PORTA.1
    
    'high PORTA.2
    pause 500
    LCDOUT $FE,1
    
    'Set up the digits (http://www.darreltaylor.com/files/CustChar.htm)
    LCDOUT  $FE,$40,$01,$01,$01,$01,$01,$01,$01,$01  ' Cust Char #0 
    LCDOUT  $FE,$48,$1F,$11,$11,$11,$11,$11,$11,$11  ' Cust Char #1  
    LCDOUT  $FE,$50,$1F,$10,$10,$10,$10,$10,$10,$1F  ' Cust Char #2  
    LCDOUT  $FE,$58,$01,$01,$01,$01,$01,$01,$01,$1F  ' Cust Char #3  
    LCDOUT  $FE,$60,$1F,$11,$11,$11,$11,$11,$11,$1F  ' Cust Char #4  
    LCDOUT  $FE,$68,$11,$11,$11,$11,$11,$11,$11,$1F  ' Cust Char #5  
    LCDOUT  $FE,$70,$1F,$01,$01,$01,$01,$01,$01,$1F  ' Cust Char #6  
    LCDOUT  $FE,$78,$1F,$01,$01,$01,$01,$01,$01,$01  ' Cust Char #7  
      
    GOTO MAIN_LOOP
    
    Zero:
    	LCDOUT $FE,$80+nPos,1
    	LCDOUT $FE,$C0+nPos,5
    return
    
    One:
    	LCDOUT $FE,$80+nPos,0
    	LCDOUT $FE,$C0+nPos,0
    return
    
    Two:
    	LCDOUT $FE,$80+nPos,7
    	LCDOUT $FE,$C0+nPos,2
    return
    
    Three:
    	LCDOUT $FE,$80+nPos,6
    	LCDOUT $FE,$C0+nPos,3
    return
    
    Four:
    	LCDOUT $FE,$80+nPos,5
    	LCDOUT $FE,$C0+nPos,0
    return
    
    Five:
    	LCDOUT $FE,$80+nPos,2
    	LCDOUT $FE,$C0+nPos,3
    return
    
    Six:
    	LCDOUT $FE,$80+nPos,2
    	LCDOUT $FE,$C0+nPos,5
    return
    
    Seven:
    	LCDOUT $FE,$80+nPos,7
    	LCDOUT $FE,$C0+nPos,0
    return
    
    Eight:
    	LCDOUT $FE,$80+nPos,4
    	LCDOUT $FE,$C0+nPos,5
    return
    
    Nine:
    	LCDOUT $FE,$80+nPos,4
    	LCDOUT $FE,$C0+nPos,3
    return
    
    Blank:
    	LCDOUT $FE,$80+nPos," "
    	LCDOUT $FE,$C0+nPos," "
    return
    
    PickDigit:
    	if nDig = 0 AND bDoneWithLeadingZeros = false then
    		gosub Blank
    'LCDOUT $FE,1
    	else
    		bDoneWithLeadingZeros = true
    		select case nDig
    		case 0
    			gosub Zero
    		case 1
    			gosub One
    		case 2
    			gosub Two
    		case 3
    			gosub Three
    		case 4
    			gosub Four
    		case 5
    			gosub Five
    		case 6
    			gosub Six
    		case 7
    			gosub Seven
    		case 8
    			gosub Eight
    		case 9
    			gosub Nine
    		end select
    	endif
    return
    
    MAIN_LOOP:
    	for wVal = 0 to $FFFE 
    		bDoneWithLeadingZeros = FALSE
    		'Most significant digit
    		nPos = 0
    		nDig = wVal dig 4
    		Gosub PickDigit
    		
    		nPos = 1
    		nDig = wVal dig 3
    		Gosub PickDigit
    		
    		nPos = 2
    		nDig = wVal dig 2
    		Gosub PickDigit
    		
    		nPos = 3
    		nDig = wVal dig 1
    		Gosub PickDigit
    		
    		'Least significant digit
    		nPos = 4
    		nDig = wVal dig 0
    		Gosub PickDigit
    		
    		pause 25
    	next wVal
    goto MAIN_LOOP
    Best Regards,
    Paul

  10. #10
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Thank you. I will try.
    Last edited by savnik; - 10th June 2010 at 18:54.

Members who have read this thread : 1

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