problem with LCD large Numbers


Results 1 to 6 of 6

Threaded View

  1. #1

    Default problem with LCD large Numbers

    Hi all
    I have been away for a LOONG time, finally getting back working with PICs.

    I have developed a program to display large numbers on a 4x20 LCD, using PBP 2.6. The PIC is an 18F14K22.
    I used POKECODE to store the number patterns in code space, making the overall program quite efficient.
    Everything works great, except for a bug I simply cannot figure out. The code is well commented, so should be easy to follow.
    The bug is: when a three digit number is chosen with the units and tens digits BOTH ZERO, or just the tens digit is 0.
    When the number is any hundreds (100, 200, 300, etc) or a number with 0 in the tens digit (101, 306, 802, etc).
    What happens with the two zero example is: the display is there, but is flickering at a very high rate. At first I thought I might have a CLS command somewhere, but that is not it. With a number with the tens digit 0, the display totally "hangs".

    I'm really happy with the code otherwise, but have been pulling out what little hair I have left !

    The total program is posted below. Once again, I am using a 18F14K22. Perhaps someone can download the code and try it.


    DEFINE OSC 16
    OSCCON = %11110110 ' 16 MHZ INTERNAL OSCILLATOR

    TX var PORTC.0
    TRISC = %10110000


    ROW1 con 128 ' VALUES FOR THE ROWS ( USED IN PATTERN DISPLAY)
    ROW2 con 192
    ROW3 con 148
    ROW4 con 212

    ROW VAR BYTE '4 X 20 ROW NUMBER - 1 TO 4
    COL VAR BYTE '4 X 20 COLUMN NUMBER - 0 TO 19
    CHAR VAR BYTE ' SPECIAL LARGE FONT CHARACTER (1 THRU 7)

    Z VAR WORD ' USED TO SEQUENCE THROUGH THE POKED CODE
    A VAR WORD ' START POINT OF SEARCHED POKE CODE
    B VAR WORD ' END POINT OF SEARCHED POKE CODE
    NUMBER VAR WORD
    TEMP VAR WORD
    COL_OFFSET VAR BYTE ' USED TO POSITION UNITS, HUNDREDS, AND TENS
    COUNTER VAR BYTE ' A COUNTER FOR THE DIGIT NUMBER
    COUNTER = 0
    '************************************************* *******************************
    NUMBER = 369
    '
    ' THIS IS ANY NUMBER THAT CAN BE DISPLAYED FOR TEST PURPOSES
    ' CHANGING IT WITH ZEROS IN THE UNITS AND TENS DISPLAY CAUSES A RAPID FLICKER
    ' PLACING A ZERO IN ONLY THE TENS SPACE "HANGS" THE DISPLAY ! ! !
    '************************************************* ********************************

    serout2 tx,84,[254,$01] ' CLEAR THE DISPLAY
    pause 500


    pause 100

    ''' FIRST WRITE THE CHARACTER PATTERNS TO LCD RAM FOR A PATTERN DISPLAY
    ''
    ' 0 Left-right UP-ramp (TOP)
    serout2 tx,84,[254,$40,$00,$01,$03,$07,$0F,$1F,$1F,$1F]
    serout2 tx,84,[254,ROW1, 0]
    PAUSE 1
    ' 1 Right-left DOWN-ramp (TOP)
    serout2 tx,84,[254,$48,$00,$10,$18,$1C,$1E,$1F,$1F,$1F]
    serout2 tx,84,[254,ROW1+2, 1]
    PAUSE 1
    ' 2 Left-right UP-ramp. (BOTTOM)
    serout2 tx,84,[254,$50,$1F,$1F,$1F,$1E,$1C,$18,$10,$00]
    serout2 tx,84,[254,ROW1+4, 2]
    PAUSE 1
    ' 3 Right-left DOWN-ramp (BOTTOM)
    serout2 tx,84,[254,$58,$1F,$1F,$1F,$0F,$07,$03,$01,$00]
    serout2 tx,84,[254,ROW1+6, 3]
    pause 1
    ' 4 UPPER block.
    serout2 tx,84,[254,$60,$1F,$1F,$1F,$1F,$00,$00,$00,$00]
    serout2 tx,84,[254,ROW1+8, 4]
    PAUSE 1
    ' 5 LOWER block.
    serout2 tx,84,[254,$68,$00,$00,$00,$00,$1F,$1F,$1F,$1F]
    serout2 tx,84,[254,ROW1+10, 5]
    PAUSE 1
    '6 SMALL UP-RAMP
    serout2 tx,84,[254,$70,$01,$03,$07,$0F,$1F,$00,$00,$00] '6
    serout2 tx,84,[254,ROW1+12, 6]
    PAUSE 1
    ' '7 FULL BLOCK
    serout2 tx,84,[254,$78,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F] '7
    serout2 tx,84,[254,ROW1+14, 7]

    PAUSE 2000 ' SHORT DELAY TO DISPLAY THE SPECIAL CHARACTERS
    serout2 tx,84,[254,$01] ' CLEAR THE DISPLAY

    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''


    START: ' FIRST GET THE THREE DIGITS ( THOUSANDS WILL BE ADDED LATER)



    TEMP = NUMBER DIG 0
    COUNTER = 1 ' SPACE FOR UNITS DIGIT
    GOSUB GET_NUMBER
    TEMP = NUMBER DIG 1
    COUNTER = 2 ' SPACE FOR TENS DIGIT
    GOSUB GET_NUMBER
    TEMP = NUMBER DIG 2
    COUNTER = 3 ' SPACE FOR HUNDREDS DIGIT
    GOSUB GET_NUMBER

    GOTO START


    GET_NUMBER:
    '
    IF TEMP = 0 THEN
    A = $2400 : B= $2448 ' these are the start and end points for the pattern for zero
    GOSUB DISPLAY
    ENDIF

    IF TEMP = 1 THEN
    A = $2450 : B = $246C
    GOSUB DISPLAY
    ENDIF

    IF TEMP = 2 THEN
    A = $2470 :B = $24B6
    GOSUB DISPLAY
    ENDIF

    IF TEMP = 3 THEN
    A = $24C0 : B = $2506
    GOSUB DISPLAY
    ENDIF

    IF TEMP = 4 THEN
    A = $2510 : B = $253E
    GOSUB DISPLAY
    ENDIF

    IF TEMP = 5 THEN
    A = $2540 : B = $2586
    GOSUB DISPLAY
    ENDIF

    IF TEMP = 6 THEN
    A = $2590 : B = $25DC
    GOSUB DISPLAY
    ENDIF

    IF TEMP = 7 THEN
    A = $25E0 : B = $2608
    GOSUB DISPLAY
    ENDIF

    IF TEMP = 8 THEN
    A = $2610 : B = $2662
    GOSUB DISPLAY
    ENDIF

    IF TEMP = 9 THEN
    A = $2670 : B = $26BC
    GOSUB DISPLAY
    ENDIF

    RETURN ' RETURN T0 START



    ' ZERO IS 2400 TO 2448 ONE IS 2450 TO 246C TWO IS 2470 TO 24B6
    ' THREE IS 24C0 TO 2506 FOUR IS 2510 TO 253E FIVE IS 2540 TO 2586
    ' SIX IS 2590 TO 25DC SEVEN IS 25E0 TO 2608 EIGHT IS 2610 TO 2662
    ' NINE IS 2670 TO 26BC
    '


    DISPLAY:

    FOR Z = A TO B
    PEEKCODE z,ROW
    z=z+2
    peekcode z,COL
    z=z+2
    peekcode z,CHAR
    IF COUNTER = 1 THEN COL_OFFSET = 14 ' POSITION THE UNITS DIGIT
    IF COUNTER = 2 THEN COL_OFFSET = 9 ' POSITION THE TENS DIGIT
    IF COUNTER = 3 THEN COL_OFFSET = 4 ' POSITION THE HUNDREDS DIGIT
    COL = COL+COL_OFFSET
    SEROUT2 TX,84,[254,(ROW + COL),CHAR]
    z=z+1
    NEXT Z

    RETURN ' RETURN TO GET_NUMBER


    END

    ''''''''''''' CODE FOR DIGITS O TO 9 '''''''''''''''''''
    '' THE ADDRESSES CHOSEN THE THE DISPLAY WERE COMPLETLY ARBITRARY ''

    '''''''''''''''''''' ZERO '''''''''''''''''
    POKECODE @$2400,128,0,0,128,1,4,128,2,4,128,3,1,192,0,7,192 ,3,7,148,0,7,148,3,7
    POKECODE @$2430,212,0,3,212,1,5,212,2,5,212,3,2 ''' ENDS AT $2448

    ''''''''''''''''''''' ONE ''''''''''''''''''
    POKECODE @$2450,128,0,8,128,1,7,192,1,7,148,1,7,212,1,7 '' ENDS AT $246C

    '''''''''''''''''''''' TWO '''''''''''''
    POKECODE @$2470,128,0,0,128,1,4,128,2,4,128,3,1,192,2,5,192 ,3,4,148,0,5,148,1,4
    POKECODE @$24A0,212,0,7,212,1,5,212,2,5,212,3,5 ''ENDS AT $24B6

    ''''''''''''''''''' THREE '''''''''''''
    POKECODE @$24C0,128,0,2,128,1,4,128,2,4,128,3,1,192,3,7,148 ,1,4,148,2,4,148,3,7
    POKECODE @$24F0,212,0,1,212,1,5,212,2,5,212,3,2 '' ENDS AT $2506

    '''''''''''''''''' FOUR ''''''''''''''
    POKECODE @$2510,128,0,7,128,3,7,192,0,7,192,1,5,192,2,5,192 ,3,7,148,3,7,212,3,7
    ' ENDS AT $253E
    ''''''''''''''''''''FIVE '''''''''''''''''''''
    POKECODE @$2540,128,0,7,128,1,4,128,2,4,128,3,4,192,0,7,192 ,1,5,192,2,5,148,3,1
    POKECODE @$2570,212,0,5,212,1,5,212,2,5,212,3,2 ''ENDS AT $2586

    ''''''''''''''''''''''''''''''''''' SIX ''''''''''''
    POKECODE @$2590,128,0,0,128,1,4,128,2,4,128,3,1,192,0,7,148 ,0,7,148,1,4,148,2,4 '
    POKECODE @$25C0,148,3,1,212,0,3,212,1,5,212,2,5,212,3,2 '' ENDS AT $25DC

    '''''''''''''''''''''' SEVEN ''''''''''''''

    POKECODE @$25E0,128,0,4,128,1,4,128,3,2,128,2,4,192,2,7,148 ,1,7,212,0,7 'ENDS AT $2608

    ''''''''''''''''''' EIGHT '''''''''''''''
    POKECODE @$2610,128,0,0,128,1,4,128,2,4,128,3,1,192,0,3,192 ,1,5,192,2,5,192,3,2
    POKECODE @$2640,148,0,0,148,3,1,212,0,3,212,1,5,212,2,5,212 ,3,2 'ENDS AT $2662

    ''''''''''''''''''''' NINE ''''''''''''
    POKECODE @$2670,128,0,0,128,1,4,128,2,4,128,3,1,192,0,3,192 ,1,5,192,2,5,192,3,7
    POKECODE @$26A0,148,3,7,212,0,3,212,1,5,212,2,5,212,3,2 ' ENDS AT $26BC
    Last edited by ozarkshermit; - 9th December 2017 at 22:17. Reason: more information

Similar Threads

  1. Math problem with PBP 2.6 and 18F4550, large numbers
    By wdmagic in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd January 2013, 05:41
  2. handling Large Numbers
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th April 2007, 03:33
  3. Multiplying large numbers
    By jhonea1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 14th April 2006, 18:41
  4. How to display large numbers
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th March 2006, 00:17
  5. math problems - large numbers
    By Tomasm in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th February 2004, 08:48

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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