Any idea's on porting this to PBP?


Closed Thread
Results 1 to 21 of 21
  1. #1
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72

    Default Any idea's on porting this to PBP?

    I copied this from scott edwards, all the code is his, i just modified it a little to try it out with PBP, all i get is a blank LCD. my version gets rid of the nibble variable, which is where i think it might go wrong, if someone could get this to work it would benifit everyone im sure. im using a 4X20 LCD, i've used a different aproach to large letters that worked fine but ate up most of my 16F648A's resorces (for a compass heading display).

    ALL PROPS TO SCOTT EDWARDS AND SEETRON!!!
    Code:
    CMCON = 7                              ' Turn off un-needed PIC hardware
    VRCON = 0                              '   ''             ''
    CCP1CON = 0                            '   ''             ''
    INTCON = %00000000                     '   ''             ''
    
    I       con  $FE    ' Instruction prefix.
    ClrLCD  con  1      ' Clear-LCD instruction.
    
    cgRAM   con  $40    ' 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. changed.was a NIBBLE  
    digit   var  byte    ' Current digit to display
    line    var  byte    ' LCD line
    
    ' ====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 shap
    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...============= >>>
    
    LCDOUT I,cgRAM  ' Enter CG RAM.
    for EEptr = 0 to 63  ' Write the bit patterns
      Read EEptr,temp  '   to the LCD.
    LCDout temp
    next
    
    ' <<<...to here. ===============================================
    LCDOUT I,ClrLCD  ' Clear the LCD.
    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,[$80,$C0,$94,$D4],temp
      LCDOUT I,temp
      for digit = 3 to 0
        nbl = dispVal dig digit
        gosub getPattern:
        if dispVal = 0 and digit = 0 then skip0:
        if dispVal < decade then blankIt:
    skip0:
        LCDOUT pat.bIT15,pat.bit14,pat.bit13,pat.bit12,pat.bit11,pat.bit10,pat.bit9,pat.bit8,pat.bit7,pat.bit6,pat.bit5,pat.bit4,pat.bit3,pat.bit2,pat.bit1,pat.bit0 ' was NIBS!
        goto cont:
    blankIt:
       LCDOUT "    "
    cont:
        if digit = 0 then skip1:
        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:
    lookup nbl,[$0551,$7067,$0551,$0551,$6776,$6555,$0557,$2556,$0551,$0551],pat
    return
    second:
    lookup nbl,[$6776,$7767,$7743,$7743,$6776,$2441,$6041,$7703,$2443,$6776],pat
    return
    third:
    lookup nbl,[$6776,$7767,$0577,$7751,$2556,$7776,$6776,$7767,$0551,$2536],pat
    return
    fourth:
    lookup nbl,[$2443,$7464,$6444,$2443,$7776,$2443,$2443,$7767,$2443,$7443],pat
    return
    Last edited by ScaleRobotics; - 19th July 2010 at 06:18.

  2. #2
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    I don't see any "DEFINE LCD" entries to tell PBP where you wired the LCD. Unless you wire to the default lines you'll get a blank just that: a blank display.

    Check pg 95 of the manual under LCDOUT.

  3. #3
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default

    It is wired default........... and it works fine with simple LCDOUT "hello"
    or the following (NNW) in large 4 line tall font.. just need help getting my first question answered, how to port the code, that was written for BS2 to PBP?
    i couldnt use nibble (WHY IS THERE NO NIBBLE IN PBP?), forcing me to break
    pat into 16 bits rather than 4 nibbles (pat.nib3,pat.nib2,pat.nib1,pat.nib0)

    THIS WORKS FINE, LCD IS WIRED IN DEFAULT.
    sub1:
    LCDOUT CMD, LcdCls ' Clear the LCD
    PAUSE 1

    LCDOUT CMD, LcdLine1 + 3, 6,1,7,6,7,6,1,7,6,7,6,7,7,6
    LCDOUT CMD, LcdLine2 + 3, 6,2,1,6,7,6,2,1,6,7,6,7,7,6
    LCDOUT CMD, LcdLine3 + 3, 6,7,2,6,7,6,7,2,6,7,6,0,1,6
    LCDOUT CMD, LcdLine4 + 3, 6,7,7,6,7,6,7,7,6,7,6,3,2,6

    RETURN

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


    Did you find this post helpful? Yes | No

    Default

    If i understand your 'nibble' stuff...
    Code:
    WordA    Var Word
    Nibble1  Var Byte
    Nibble2  Var Byte
    Nibble3  Var Byte
    Nibble4  Var Byte
    
    WordA=$1234
    Nibble1=WordA.Highbyte>>4
    Nibble2=WordA.Highbyte&$0F
    Nibble3=WordA.LowByte>>4
    Nibble4=WordA.Lowbyte&$0F
    Steve

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

  5. #5
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default My fault

    Sorry i didnt explain that the code was originally written for a basic stamp,
    hence the nibble sized variable in question. the code is for displaying large charaters on a 4x20 serial LCD or serial backpack equiped LCD. the code writes custom characters to the LCD, then arranges them to make the large 4 line tall numbers (0-9). all this was spit out serially to the LCD. I changed all the serouts in the origonal code to LCDOUT in proper PBP form, but since PBP doesnt have a nibble sized variable, only bytes and words, the WORD sized variable "pat" can't be broken into 4 NIB's (i.e pat.NIB0) like it will let you in pBasic. it can only do two bytes or 16 bits.. i think that is the reason my version of the code (from my first post) isnt working. all i get is a blank LCD.. it would be nice to use this code to display large numbers because it only takes up about 600 WORDs, i've done a version that displays the 16 compass points (NNW) in large text using the first part of this code to write the custom bit patterns to my LCD's CGRAM, but it takes up 3397 WORDs using BRANCH to a subroutine for each compass point which is spelled out in my second reply, anyway, the original code is at:

    http://www.seetron.com/pdf/lcd_an1.pdf

    and as you can see it is written for pBASIC and meant for serial LCD's, i want to convert it to PBP for a parallel LCD..

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hey Ryan,

    mister_e's concept is correct, you just need to put it into the LCDOUT statement.

    LCDOUT Nibble1, Nibble2, Nibble3, Nibble4

    or you can just put it all in there in one shot...

    LCDOUT pat.Highbyte>>4, pat.Highbyte&$0F, pat.LowByte>>4, pat.Lowbyte&$0F
    <br>
    DT

  7. #7
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Hmm..

    Still just a blank LCD, I expected to get at least some garbage on the display. anyone got any other idea's what might be wrong? I added:
    LCDOUT "TEST"
    PAUSE 1000
    LCDOUT $FE, 1

    to the code just before the demo loop part and it display's correctly and then clear screens, so i guess its not totally blank, but it doesn't do much else.
    I also tried hooking the LCD to my BS2p and ran my modified version of the code using LCD out in proper pBasic format and it sorta worked but only displayed the bottom 1/4 of the numbers all shifted up to the top line. like what should be displaying on the 4th line of the LCD was showing on the top line and all the rest was off screen.

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


    Did you find this post helpful? Yes | No

    Default

    There's few missing details here
    OSC type & speed (4,8,16,20.... or internal)
    LCD DEFINEs
    Config Fuses
    Schematic

    Did you added ?
    DEFINE LCD_LINES 4

    You can also use LCDOUT $fe,1,"Hello"

    Some LCD may need some COMMANDUS and DATAUS fine tuning too.
    Last edited by mister_e; - 12th October 2006 at 07:22.
    Steve

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

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Here is a complete modification of Scott Edwards Program for big nums.

    Changes are marked in red, and have been tested.
    Code:
    ;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
    Not too hard eh.
    DT

  10. #10
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Talking Ah!

    Ok, the step -1 was doing it, i tried LOOKUP2 as a last resort before my last post, but still didnt help. thanks, Darrel! works fine now. i probably would have never got that in a million years. Thanks again!

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Honestly..., I had to use the MCSP debugger to find the step -1. Saw that the FOR loop was never getting executed. Made it easy.

    But a million years, you'd have got it.

    Glad to help.
    <br>
    DT

  12. #12
    Join Date
    Oct 2006
    Location
    Cape Town SA
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Youre the best!

    Darrel you are amazing!
    I tried this out yesterday and it exactly what I'm looking for ( I am making a fuel consumption / complex odometer for my ancient Land Rover) and as I can't see close up without glasses, but have perfect long distance vision, a normal LCD display on the dashboard is quite useless and I had been considering large 7 seg display, but this is beautiful! Thanks a million.

    PS: any tips on saving a counter on power-down? I was going to have the PIC running off big electrolytic for long power down delay, and then have one port sensing the instant loss of the (voltage divided) 12v ignition and then quickly write to EEProm, but would it be clever to use a brown out flag or something like that?

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Thanks, but the credit goes to Scott Edwards on that one.

    If you have a PIC with an LVD (LOW VOLTAGE DETECT) pin. You can use it to generate an interrupt when it detects the loss of power.

    Then you can imediately set all pins to input and shut-down any on-chip peripherals to save current.

    You should be able to run long enough to save about 8-10 bytes with just 10uf or so..
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Hello Everyone,
    This is cool. Anyone got an idea how to force this code to display 4 digits all the time? From 0000 to 9999? Scotts code works well. I tried dispVal = 0000 prior to the LCDOUT I,cgRAM statement and that did alright to start counter at zero and eliminate the initial display of a psudorandom 4 digit number at startup, I am sure it is simple, alas so am I .
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Ahhh, I figured out 1 way, Preload with dispVal = 10000. I watched it count up until it overflowed and the zeros remained. Are there better ways ?
    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.

  16. #16
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    > Anyone got an idea how to force this code to display 4 digits all the time?

    LCDOut DEC4 MyVar

  17. #17
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    >> Anyone got an idea how to force this code to display 4 digits all the time?

    Just comment out this line ...
    Code:
    ;            if dispVal < decade then blankIt
    Added: Or better yet, make it ...
    Code:
    LeadingZeros  VAR BIT
    
                if (LeadingZeros = 0) AND (dispVal < decade) then blankIt
    Then if you want leading zero's just set the bit.
    <br>
    Last edited by Darrel Taylor; - 21st July 2007 at 12:48. Reason: Leading
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thanks Melanie and Darrel,
    That's 4 dirrerent ways - Great! It seems there is always more than 1 way.
    JS
    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.

  19. #19
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default

    Hi Guys/Ladies

    would this only work with a serial lcd or can the same thing be done for a standard 4x20 Lcd?

    Regards
    Isaac

  20. #20
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by isaac View Post
    would this only work with a serial lcd or can the same thing be done for a standard 4x20 Lcd?
    Read Post #9

  21. #21
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default

    Oooh Thanks for that
    just dont know how i missed that the serial lcd had been commented out and replaced with
    Lcdout command

    Silly me

    Isaac

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 13:55
  2. Generating Timed Fades in PBP - ideas ?
    By bcd in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th August 2008, 01:18
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 20:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2005, 00:30
  5. PBP / XP Crash
    By pondindustrial in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th November 2005, 04:16

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