LCD BARgraphs - Page 6


Closed Thread
Page 6 of 6 FirstFirst ... 23456
Results 201 to 233 of 233

Thread: LCD BARgraphs

  1. #201
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Chris, Just use the busy bit to confirm the display is ready for the next command.... As I said in the my first return post, the commands are processed by the display far too slowly and I see no delays in your code after any of the cursor control commands and you are probably running it in 4 bit mode as opposed to 8 bit mode which now allows for even more data to be lost. looking at the timing constraints in the data sheet, I'm supprised the thing is working at all. The processor onboard the display is probably doing far more work than your code is. If you are commited to using this type of display with it's down falls because it looks good then you MUST you it as it was intended to be used it you expect it to relay the information correctly. No more to say...
    Dave Purola,
    N8NTA
    EN82fn

  2. #202
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Success!

    looking at the timing constraints in the data sheet, I'm supprised the thing is working at all. ....If you are commited to using this type of display with it's down falls because it looks good then you MUST you it as it was intended to be used it you expect it to relay the information correctly. No more to say...


    Anyhow, for anyone who is using a Newhaven OLED display and wants to use Darrel's bargraph routine, you only have to modify a few things, which only takes about 30 seconds to do so. Here is what you need to do:

    Make this portion of the code:
    Code:
        LCDOut $FE,$40,REP $15\8                  ; Custom char 0 - 3 lines  |||
        LCDOut $FE,$48,REP $14\8                  ; Custom char 1 - 2 lines  ||
        LCDOut $FE,$50,REP $10\8                  ; Custom char 2 - 1 line   |
    To make it look like this:
    Code:
        LCDOut $FE,$48,REP $15\8                  ; Custom char 0 - 3 lines  |||
        LCDOut $FE,$50,REP $14\8                  ; Custom char 1 - 2 lines  ||
        LCDOut $FE,$58,REP $10\8                  ; Custom char 2 - 1 line   |
    You have change the numbers in the other two character sets if you use blocks and boxes.

    You also have to modify this code:
    Code:
    ThreeBARS CON 0                                ; Identify the Custom Characters
    TwoBARS   CON 1
    OneBAR    CON 2
    To this:
    Code:
    ThreeBARS CON 1                                ; Identify the Custom Characters
    TwoBARS   CON 2
    OneBAR    CON 3
    By modifying the lines of code above, the bargraph will display correctly on your OLED screen. I tested the bargraph a few different ways and it worked 100% of the time. I hope this is able to help someone.

  3. #203
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Exclamation Re: Success!

    THE CHANGES IN THE ABOVE POST ARE INCOMPLETE!!!

    If you make those modifications, you need to change all of the custom character declarations. Otherwise, the other styles will not work properly. Here are the other modifications (shown with the first set for context):

    Code:
    ; --- lines Style custom chars ----
    CharsetLines:
        LCDOut $FE,$48,REP $15\8                  ; Custom char 0 - 3 lines  |||
        LCDOut $FE,$50,REP $14\8                  ; Custom char 1 - 2 lines  ||
        LCDOut $FE,$58,REP $10\8                  ; Custom char 2 - 1 line   |
    RETURN
    
    ; --- boxed Style custom chars ----
    CharsetBoxed:
        LCDOut $FE,$48,$1F,REP $15\6,$1F          ; III
        LCDOut $FE,$50,$1C,REP $14\6,$1C          ; II
        LCDOut $FE,$58,REP $10\8                  ; I
    RETURN
    
    ; --- blocks Style custom chars ----
    CharsetBlocks:
        LCDOut $FE,$48,REP $1F\8
        LCDOut $FE,$50,REP $1C\8
        LCDOut $FE,$58,REP $10\8
    RETURN

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


    Did you find this post helpful? Yes | No

    Default Re: Success!

    So, what you're saying is that if you use Custom Character 0 on those displays, everything goes crazy?
    Displaying the wrong characters on the wrong lines.

    And by just not using Cust. Char 0, everythings AOK?
    On both of your dispays?

    That's a new one ... but it sounds typical for Newhaven.
    DT

  5. #205
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Quote Originally Posted by SteveB View Post
    THE CHANGES IN THE ABOVE POST ARE INCOMPLETE!!!

    If you make those modifications, you need to change all of the custom character declarations. Otherwise, the other styles will not work properly. Here are the other modifications (shown with the first set for context):
    No kidding. Did you read my post?
    You have change the numbers in the other two character sets if you use blocks and boxes.

    Quote Originally Posted by Darrel Taylor View Post
    So, what you're saying is that if you use Custom Character 0 on those displays, everything goes crazy?
    Displaying the wrong characters on the wrong lines.

    And by just not using Cust. Char 0, everythings AOK?
    On both of your dispays?

    That's a new one ... but it sounds typical for Newhaven.
    Yup. I tried this on both displays with different programs. Whenever a 0 is used, the display gets all wacky. It will not only display the characters on the wrong line, the entire OLED displays wacky stuff. (I took two crappy cell phone pics of the differences). You also have to change the LCDOUT commands too. If you don't, it will still work but the box won't be filled out completely.

    I tested it a bunch of different ways and I couldn't make it fail. Perhaps I didn't test every single mode but what I did test (what I normally use) worked perfectly!Name:  IMAG0306.jpg
Views: 2005
Size:  47.4 KBName:  IMAG0307.jpg
Views: 2013
Size:  80.5 KB

  6. #206
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Darrel, I hope you don't mind.

    Here is a modified version of Darrel's code that accommodates the flaw in the Newhaven Display Firmware preventing use of CGRAM location 0. (Changes I made are highlighted in blue)

    Code:
    '****************************************************************
    '*   Creates a variable sized BAR-graph anywhere on the screen  *
    '****************************************************************
    '*  Name    : LCDbar_INC_MOD1.bas                               *
    '*  Original:                                                   *
    '*  Author  : Darrel Taylor                                     *
    '*  Notice  : Copyright (c) 2005                                *
    '*  Date    : 9/8/2005                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : Maximum Range is 32768                            *
    '*          : Range must always be a Constant                   *
    '*          : Value must always be a WORD variable              *
    '*          :                                                   *
    '* Modified : By SteveB on 11/23/2012                           *
    '*          : The original include has been modified to         *
    '*          : accomodate a flaw in Newhaven OLEDs firmware.     *
    '*          : By using the define below, it will adjust the     *
    '*          : custom CGRAM character locations used to 1-3      *
    '*          : (vs. 0-2).                                        *
    '*          :                                                   *
    '*          : If using a flawed Newhaven Display add the        *
    '*          : following define BEFORE the INCLUDE statement:    *
    '*          :                                                   *
    '*          : DEFINE NEWHAVEN_DISPLAY 1                         *
    '*          :                                                   *
    '****************************************************************
    
    BAR_width   VAR  BYTE : BAR_width = 16         ; Width of the BARgraph      16
    BAR_range   VAR  WORD : BAR_range = 100        ; Range of Values (0-100)   100
    BAR_row     VAR  BYTE : BAR_row = 1            ; Row location (1-4)          1
    BAR_col     VAR  BYTE : BAR_col = 0            ; Column location (0-15)      0
    BAR_value   VAR  WORD : BAR_value = 0          ; Current BAR value           0
    BAR_style   VAR  BYTE : BAR_style = 1          ; 1=lines, 2=boxed, 3=blocks  1
    
    ; --- Temporary vars ----
    BARtemp     VAR  WORD
    Remainder   VAR  WORD
    BARloop     VAR  BYTE
    LastCharset VAR  BYTE : LastCharset = 0
    Limit1      VAR  WORD
    
    GOTO overBAR                                   ; Skip over Subroutines
    
        ThreeBARS CON EXT                          
        TwoBARS   CON EXT
        OneBAR    CON EXT
        CharLoc3  CON EXT
        CharLoc2  CON EXT
        CharLoc1  CON EXT
    
    ASM
     ifdef NEWHAVEN_DISPLAY
    ThreeBARS = 1                                ; Identify the Custom Characters
    TwoBARS   = 2
    OneBAR    = 3
     else
    ThreeBARS = 0                                ; Identify the Custom Characters
    TwoBARS   = 1
    OneBAR    = 2
     endif
    
    CharLoc3 = 40h +(ThreeBARS*8)
    CharLoc2 = 40h +(TwoBARS*8)
    CharLoc1 = 40h +(OneBAR*8)
    
    lines  = 0x10000001                            ; Define the Styles
    boxed  = 0x10000002
    blocks = 0x10000003
    ENDASM
    
    ; --- lines Style custom chars ----
    CharsetLines:
        LCDOut $FE,CharLoc3,REP $15\8                  ; Custom char 0 - 3 lines  |||
        LCDOut $FE,CharLoc2,REP $14\8                  ; Custom char 1 - 2 lines  ||
        LCDOut $FE,CharLoc1,REP $10\8                  ; Custom char 2 - 1 line   |
    RETURN
    
    ; --- boxed Style custom chars ----
    CharsetBoxed:
        LCDOut $FE,CharLoc3,$1F,REP $15\6,$1F          ; III
        LCDOut $FE,CharLoc2,$1C,REP $14\6,$1C          ; II
        LCDOut $FE,CharLoc1,REP $10\8                  ; I
    RETURN
    
    ; --- blocks Style custom chars ----
    CharsetBlocks:
        LCDOut $FE,CharLoc3,REP $1F\8
        LCDOut $FE,CharLoc2,REP $1C\8
        LCDOut $FE,CharLoc1,REP $10\8
    RETURN
    
    ; ----- Show the BAR graph -----------------------------------------------------
    ShowBAR:
        IF BAR_width = 0 then BARdone
        if LastCharset <> BAR_style then          ; If the Style has changed ?
            LastCharset = BAR_style
            SELECT CASE BAR_style                 ; Load the new custom chars
                CASE 1 : GOSUB CharsetLines
                CASE 2 : GOSUB CharsetBoxed
                CASE 3 : GOSUB CharsetBlocks
            END SELECT
        endif
        
    @ ifdef LCD4X20    
        LOOKUP BAR_row,[$80,$80,$C0,$94,$D4],BARtemp
    @ else
        LOOKUP BAR_row,[$80,$80,$C0,$90,$D0],BARtemp
    @ endif    
        LCDOUT $FE, BARtemp + BAR_col             ; Move cursor to start of the BAR
        BARtemp = BAR_value * BAR_width           ; calc the char position
        BARtemp = DIV32 BAR_range
        Remainder = R2
    
        For BARloop = 0 to BAR_width -1
            SELECT CASE BARtemp
                CASE IS > BARloop
                    LCDOUT ThreeBARS              ; send 3 bars    |||
                CASE IS < BARloop
                    LCDOUT " "                    ; clear to end of BARwidth
                CASE IS = BARloop
                    Limit1 = BAR_range * 6
                    Limit1 = DIV32 10
                    if Remainder >= Limit1 then
                        LCDOUT TwoBARS            ; send 2 bars    ||
                    else
                        Limit1 = BAR_range * 3
                        Limit1 = DIV32 10
                        if Remainder >= Limit1 then    ; 30%
                            LCDOUT OneBAR         ; send 1 bar     |
                        else
                            LCDOUT " "            ; no bars
                        endif                
                    endif
            END SELECT
        NEXT BARloop
    BARdone:
    RETURN
    
    ASM
    ; --- The main macro for creating BARgraphs ------------------------------------
    BARgraph  macro  Value, Row, Col, Width, Range, Style
        MOVE?CW    Range, _BAR_range              ; Range MUST be a constant
        MOVE?WW    Value, _BAR_value              ; Value MUST be a WORD variable
        if (Row < 5)                              ; Row is a constant
            MOVE?CB    Row,   _BAR_row
        else                                      ; Row is a variable
            MOVE?BB    Row,   _BAR_row           
        endif
        if (Col < 16)                             ; Is Col a constant ?
            MOVE?CB    Col,   _BAR_col
        else                                      ; NO, it's a variable
            MOVE?BB    Col,   _BAR_col                                     
        endif
        if (Width <= 40)
            MOVE?CB    Width, _BAR_width
        else
            MOVE?BB    Width, _BAR_width
        endif
        if ((Style >= lines) & (Style <= blocks)) ; Is Style a valid constant ?
            MOVE?CB    Style, _BAR_style
        else                                      ; NO, treat it like a variable
            MOVE?BB    Style, _BAR_style
        endif
        L?CALL   _ShowBAR
        endm
        
    ENDASM
    
    overBAR:
    Of course, more could be done to make this even more flexible, but this is at least a tidy way do deal with this particular problem.
    Last edited by SteveB; - 24th November 2012 at 01:28. Reason: added ending statement

  7. #207
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    (Changes I made are highlighted in blue)
    I'm glad I was able to help.

    '* : If using a flawed Newhaven Display add the *
    '* : following define BEFORE the INCLUDE statement:
    It doesn't matter where you put this statement. Top, bottom, side, back, inbetween, etc. It will work no matter it is.

  8. #208
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Christopher,

    I wasn't slighting your contribution, sorry if it came across that way. I seriously don't think anybody would have figured it out without the testing you did (ok, maybe Darrel if he decided to take it on as a project). It is certainly a unique problem. My posts were both aimed at the community at large. Initially to aviod any confusion by a would be user that is less diligent than yourself. Then, to offer a more comprehensive solution that could be used as a substitute for the original include file. (I would have sent it to Darrel via PM initially for his approval, and possible change to the original file, but since he is a big-wig at ME now, he doesn't accept PMs anymore. )

    And yes, you are correct, that DEFINE can probably go anywhere and it will still work. (I was playing it safe due to limited time to write and test the code for errors while my 3 kids were playing sword-fighting in the living room with me ducking occasionally to avoid a head wound ). If Darrel is inclined to correct that statement via his Moderator powers, I've got no problem with that. I also missed coloring the second "CharLoc1" blue.

    Best Regards,
    Steve

  9. #209
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    No worries. I like to be sarcastic and I'm difficult to offend. In my 7 years (on and off) this forum, it was the first time I was able to provide a contribution that may help other people.

  10. #210
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Is there a way to modify the code to display from the right to the left? I've tried a number of different things but it doesn't work correctly.

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


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Let the display do the hard work by using the Right to Left "Entry Mode".
    Then just change the custom characters.
    No changes are required to the include file.




    Code:
    X  VAR WORD
    
    ;----[Initialize bargraph]------------------------------------------------------
    X = 0
    @   BARgraph  _X,   1,   1, 20,   512,  lines
        LCDOut $FE,$48,REP $15\8                  ; Custom char 1 - 1 line     |
        LCDOut $FE,$50,REP $05\8                  ; Custom char 2 - 2 lines   ||
        LCDOut $FE,$58,REP $01\8                  ; Custom char 3 - 3 lines  |||
    
    ;----[Main Program Loop]--------------------------------------------------------
    MainLoop:
        FOR X=1 TO 512
            PAUSE 10
            LCDOUT $FE,$94,DEC X,"    "
    
            LCDOUT $FE,$04  ; Set Entry mode Right to Left
    '@      BARgraph   Value, Row, Col, Width, Range, Style 
    @       BARgraph      _X,   1,  20,    20,   512,  lines
            LCDOUT $FE,$06  ; Restore Entry mode Left to Right
    
        NEXT X
    GOTO MAINLOOP
    Of course, I'm assuming the Newhaven display can actually do that.
    Normal LCD's can.
    DT

  12. #212
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Darrel, I know you know what happens when one assumes.

  13. #213
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Of course, I'm assuming the Newhaven display can actually do that.
    Are Newhaven LCD's the redheaded step children of LCD's? I've never had a problem with them. Then again, I don't make many projects that have displays and if I do need one I don't look at the manufacturer when ordering one. If I was using an LCD, I'd go with whoever is the cheapest. Regarding OLED, it's the first time I've used one and the Newhaven OLED's are awesome. I am making a product for a car and the screen doesn't get washed out in the light and it's not too bright at night time. It's perfect!

    Anyhow, thanks for the help. I spent a little more than 6 hours trying to get it but you pushed the easy button! Regarding your comment, the display WILL show the bargraph but for some reason you have to modify this line:
    Code:
    BARgraph      _X,   1,  20,    20,   512,  lines
    To this:
    Code:
    BARgraph      _X,   1,  19,    20,   512,  lines
    If you don't modify it, the bargraph will sit in column one with three bars displayed while the number counts from 1 to 512. I guess you can add this to the "uniqueness" of Newhaven displays!

  14. #214
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    So, I know that Darrel provided a nice hardware solution. But, like a dog with a new bone, I wanted to work out a software solution.

    When using the modified include file, the only change needed in the main program is an additional parameter to @ BARgraph:

    @ BARgraph Value, Row, Col, Width, Range, Style, RtoL
    0 = Left to Right, 1 = Right to Left

    Here is the code, the file is below:

    Code:
    '****************************************************************
    '*   Creates a variable sized BAR-graph anywhere on the screen  *
    '****************************************************************
    '*  Name    : LCDbar_INC_MOD2.bas                               *
    '*  Author  : Darrel Taylor                                     *
    '*  Notice  : Copyright (c) 2005                                *
    '*  Date    : 9/8/2005                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : Maximum Range is 32768                            *
    '*          : Range must always be a Constant                   *
    '*          : Value must always be a WORD variable              *
    '*          :                                                   *
    '* Modified : By SteveB on 11/23/2012                           *
    '*          : The original include has been modified to         *
    '*          : accomodate a flaw in Newhaven OLEDs firmware.     *
    '*          : By using the define below, it will adjust the     *
    '*          : custom CGRAM character locations used to 1-3      *
    '*          : (vs. 0-2).                                        *
    '*          :                                                   *
    '*          : If using a flawed Newhaven Display add the        *
    '*          : following define statement:                       *
    '*          :                                                   *
    '*          : DEFINE NEWHAVEN_DISPLAY 1                         *
    '*          :                                                   *
    '* Modified : By SteveB on 11/27/2012                           *
    '*          : This modification introduces the ability to       *
    '*          : display the bargraph from Right-to-Left.          *
    '*          :                                                   *
    '****************************************************************;
    ;@   BARgraph   Value, Row, Col, Width, Range, Style, RtoL
    ;  
    ;Value: The Value of the BARgraph  (0 to Range).If Range = 100 and Value is 50, then            
    ;          half of the BARgraph will be filled in.   Value MUST be a WORD sized variableą  
    ;
    ;Row: LCD Row to place the BARgraph (1 to 4)   can be either a constant or a  
    ;          variableą.  
    ;
    ;Col: LCD Column to place the BARgraph (0 to LCDsize˛ - 1)   can be either a constant  
    ;          or a variableą. 
    ;
    ;Width: Width of the BARgraph in charaters. (1 to LCDsize˛)   can be either a constant  
    ;          or a variableą. 
    ;
    ;Range: The "full-scale" range of the BARgraph  (0 to 32768) MUST be a constant.  
    ;          Variables will not work here. 
    ;
    ;Style: Selects which Style will be used for the BARgraph  (lines, boxed, blocks)   can  
    ;          be either a constant or a variableą.  
    ;
    ;RtoL: MUST be a constant
    ;	 When set to 0, Bar will display Left-to-Right
    ;	 When set to 1, Bar will display Right-to-Left
    ;
    ;Note ą - Variables must be preceeded with a 
    ;             underscore.   ie.  _Temperature    
    ;Note ˛ - LCDsize is the number of Chars in 1 line of 
    ;             the LCD, for "4x16" it's 16
    ;                                              ;                        default
    BAR_width   VAR  BYTE : BAR_width = 16         ; Width of the BARgraph      16
    BAR_range   VAR  WORD : BAR_range = 100        ; Range of Values (0-100)   100
    BAR_row     VAR  BYTE : BAR_row = 1            ; Row location (1-4)          1
    BAR_col     VAR  BYTE : BAR_col = 0            ; Column location (0-15)      0
    BAR_value   VAR  WORD : BAR_value = 0          ; Current BAR value           0
    BAR_style   VAR  BYTE : BAR_style = 1          ; 1=lines, 2=boxed, 3=blocks  1
    BAR_RtoL    VAR  BYTE : BAR_RtoL = 0
    
    ; --- Temporary vars ----
    BARtemp     VAR  WORD
    Remainder   VAR  WORD
    BARloop     VAR  BYTE
    LastCharset VAR  BYTE : LastCharset = 0
    LastRtoL    VAR  BYTE : LastRtoL = 0
    Limit1      VAR  WORD
    
    GOTO overBAR                                   ; Skip over Subroutines
    
    ThreeBARS CON EXT                              ; Identify the Custom Characters
    TwoBARS   CON EXT
    OneBAR    CON EXT
    CharLoc3  CON EXT
    CharLoc2  CON EXT
    CharLoc1  CON EXT
    
    ASM
     ifdef NEWHAVEN_DISPLAY
    ThreeBARS = 1                                
    TwoBARS   = 2
    OneBAR    = 3
     else
    ThreeBARS = 0                                
    TwoBARS   = 1
    OneBAR    = 2
     endif
    
    CharLoc3 = 40h +(ThreeBARS*8)
    CharLoc2 = 40h +(TwoBARS*8)
    CharLoc1 = 40h +(OneBAR*8)
    
    lines  = 0x10000001                            ; Define the Styles
    boxed  = 0x10000002
    blocks = 0x10000003
    ENDASM
    
    ; --- lines Style custom chars ----
    CharsetLines:
        LCDOut $FE,CharLoc3,REP $15\9                 ; Custom char 3 lines  |||
        IF BAR_Rtol = 0 THEN
            LCDOut $FE,CharLoc2,REP $14\9             ; Custom char 2 lines  ||
            LCDOut $FE,CharLoc1,REP $10\9             ; Custom char 1 line   |
        ELSE
            LCDOut $FE,CharLoc2,REP $05\9             ; Custom char 2 lines   ||
            LCDOut $FE,CharLoc1,REP $01\9             ; Custom char 1 line     |
        ENDIF
    RETURN
    
    ; --- boxed Style custom chars ----
    CharsetBoxed:
        LCDOut $FE,CharLoc3,$1F,REP $15\7,$1F         ; III
        IF BAR_Rtol = 0 THEN
            LCDOut $FE,CharLoc2,$1C,REP $14\7,$1C     ; II
            LCDOut $FE,CharLoc1,REP $10\9             ; I
        ELSE
            LCDOut $FE,CharLoc2,$07,REP $05\7,$07     ;  II
            LCDOut $FE,CharLoc1,REP $01\9             ;   I
        ENDIF
    RETURN
    
    ; --- blocks Style custom chars ----
    CharsetBlocks:
        LCDOut $FE,CharLoc3,REP $1F\9
        IF BAR_Rtol = 0 THEN
            LCDOut $FE,CharLoc2,REP $1C\9
            LCDOut $FE,CharLoc1,REP $10\9
        ELSE
            LCDOut $FE,CharLoc2,REP $07\9
            LCDOut $FE,CharLoc1,REP $01\9
        ENDIF
    RETURN
    
    ; ----- Show the BAR graph -----------------------------------------------------
    ShowBAR:
        IF BAR_width = 0 then BARdone
        if LastCharset <> BAR_style OR LastRtoL <> BAR_RtoL then ; If for change
            LastCharset = BAR_style
            LastRtoL = BAR_RtoL
            SELECT CASE BAR_style                 ; Load the new custom chars
                CASE 1 : GOSUB CharsetLines
                CASE 2 : GOSUB CharsetBoxed
                CASE 3 : GOSUB CharsetBlocks
            END SELECT
        endif
        
    @ ifdef LCD4X20    
        LOOKUP BAR_row,[$80,$80,$C0,$94,$D4],BARtemp
    @ else
        LOOKUP BAR_row,[$80,$80,$C0,$90,$D0],BARtemp
    @ endif    
        LCDOUT $FE, BARtemp + BAR_col             ; Move cursor to start of the BAR
        BARtemp = BAR_value * BAR_width           ; calc the char position
        BARtemp = DIV32 BAR_range
        Remainder = R2
    
        IF BAR_RtoL = 0 THEN
            LCDOUT REP ThreeBARS\(BARtemp)                 ; send 3 bars 
        ELSE
            IF BARtemp < BAR_width THEN
                LCDOUT REP " "\(BAR_width - BARtemp - 1)   ; Clear up to BARtemp-1  
            ENDIF  
        ENDIF
    
        IF BARtemp < BAR_width THEN      
            Limit1 = BAR_range * 6
            Limit1 = DIV32 10
            if Remainder >= Limit1 then
            	LCDOUT TwoBARS                             ; send 2 bars
            else
                Limit1 = BAR_range * 3
                Limit1 = DIV32 10
            	if Remainder >= Limit1 then                ; 30%
            	   LCDOUT OneBAR                           ; send 1 bar
            	else
            		LCDOUT " "                             ; no bars
            	endif                
            endif
        ENDIF
        
        IF BAR_RtoL = 0 THEN
        	IF BARtemp < BAR_width THEN
                LCDOUT REP " "\(BAR_width - BARtemp - 1)   ; clear till the end
            ENDIF
        ELSE
            LCDOUT REP ThreeBARS\(BARtemp)                 ; send 3 bars
        ENDIF
    BARdone:
    RETURN
    
    ASM
    ; --- The main macro for creating BARgraphs ------------------------------------
    BARgraph  macro  Value, Row, Col, Width, Range, Style, RtoL
        MOVE?CW    Range, _BAR_range              ; Range MUST be a constant
        MOVE?WW    Value, _BAR_value              ; Value MUST be a WORD variable
        if (Row < 5)                              ; Row is a constant
            MOVE?CB    Row,   _BAR_row
        else                                      ; Row is a variable
            MOVE?BB    Row,   _BAR_row           
        endif
        if (Col < 16)                             ; Is Col a constant ?
            MOVE?CB    Col,   _BAR_col
        else                                      ; NO, it's a variable
            MOVE?BB    Col,   _BAR_col                                     
        endif
        if (Width <= 40)
            MOVE?CB    Width, _BAR_width
        else
            MOVE?BB    Width, _BAR_width
        endif
        if ((Style >= lines) & (Style <= blocks)) ; Is Style a valid constant ?
            MOVE?CB    Style, _BAR_style
        else                                      ; NO, treat it like a variable
            MOVE?BB    Style, _BAR_style
        endif
        MOVE?CB     RtoL, _BAR_RtoL
        L?CALL   _ShowBAR
        endm
        
    ENDASM
    
    overBAR:
    LCDbar_INC_MOD2.bas.txt

  15. #215
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Here's some sample code (no fancy animations):

    Code:
    'DEFINE NEWHAVEN_DISPLAY 1   'uncomment if needed
    INCLUDE "LCDbar_INC_MOD2.bas"
    
    wCounter VAR WORD
    
        LCDOUT $FE, $01
        PAUSE 100
    
    MAIN:
        FOR wCounter = 0 to 100
            PAUSE 50
            LCDOUT $FE, $80, DEC3 wCounter
        ;@  BARgraph   Value,   Row, Col, Width, Range, Style, RtoL
        @   BARgraph  _wCounter,   1,  5,    13,   100, lines, 0
        NEXT wCounter                                                             
        
        FOR wCounter = 100 to 0 STEP -1
            PAUSE 50
            LCDOUT $FE, $80, DEC3 wCounter
        ;@  BARgraph   Value,   Row, Col, Width, Range, Style, RtoL
        @   BARgraph  _wCounter,   1,  5,    13,   100, lines, 0
        NEXT wCounter
    
    GOTO MAIN
    Last edited by SteveB; - 28th November 2012 at 05:33.

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


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Nicely done Steve.

    It works great.
    DT

  17. #217
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Thanks Darrel.

  18. #218
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Works perfectly! Awesome job!

  19. #219
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    I saw a schematic of volt-ampermeter, with PIC, with a nice animation ... Two different scale on the same row !!! Using "empty boxes" for volts and "filled boxes" for ampers ...the number of boxes varies proportionally with the parameter (volts; ampers).
    Can this be done in PBP ?! Thanks !
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by fratello View Post
    Can this be done in PBP ?
    Yes it can ...



    Custom Characters ...



    Code:
      LCDOUT  $FE,$48,$00,$00,$00,$00,$1F,$1F,$1F,$00  ' Cust Char #1
      LCDOUT  $FE,$50,$1F,$11,$1F,$00,$00,$00,$00,$00  ' Cust Char #2
      LCDOUT  $FE,$58,$1F,$11,$1F,$00,$1F,$1F,$1F,$00  ' Cust Char #3
    DT

  21. #221
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Wow ! Amazing ! THANK YOU, Mr.Darrel !
    I will try to figure out how displaying ...

  22. #222
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Let's say I read maximum 50 volts and maximum 5 ampers ; so one "empty box" = 5 volts and one "filled box" = 0.5 ampers.
    It's this "pseudo" code correct ?!
    Code:
    for y=9 to 0 step -1
    if volts >= (y*5) then
        if ampers >= (y * 1/2) then
    char = 3
    LCDOUT $FE, $80, char,char,char,char,char,char,char,char,char,char
    Endif
    Endif
    I'm sure it's another way, much easiers, but I have -till now- no ideea ...

  23. #223
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Untested, likely needs some debugging, but at least the methodology should be clear.

    Code:
    LCDPos	VAR BYTE
    volts	VAR WORD	' 0 to 500 representing 0 to 50.0 Volts
    Amps	VAR BYTE	' 0 to 50 representing 0 to 5.0 Amps
    Char	VAR BYTE	
    
    FOR LCDPos = 0 TO 9
    	IF Volts / 50 >= LCDPos + 1 THEN	' Fill in Volt Block
    		IF Amps / 5 >= LCDPos + 1 THEN		' Fill in Volt + Amp Block
    			Char = 3
    		ELSE					' Fill in Volt Block Only				
    			Char = 2
    		ENDIF
    	ELSE					' Don't Fill in Volt Block
    		IF Amps / 5 >= LCDPos + 1 THEN		' Fill in Amp Block only
    			Char = 1
    		ELSE					' Fill with Space				
    			Char = 32
    		ENDIF
    
    	ENDIF
    	LCDOUT 	$FE, $80 + LCDPos, Char	
    NEXT LCDPos
    Last edited by SteveB; - 25th January 2013 at 16:07. Reason: typo

  24. #224
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Thank You, I will post the results !

  25. #225
    Join Date
    Aug 2013
    Posts
    1


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    In this code what does "Rep" do? I'm using it with the Proton IDE Basic Compiler.
    It works OK, but I am curious as I can't find any reference to "Rep" in the documentation.
    Is it a repeat function?

    Thanks, Mark

    Print $FE, CGRAM, Rep $0\8,$0, Rep $10\6,$0,$0, Rep $14\6,$0,$0, Rep $15\6,$0,$0

    Warnings = OFF
    Byte_Math = On
    BARS = (TOP_BAR Min MAXBAR) / 3 ; One full bar for each 3 graph units
    BALANCE = (TOP_BAR Min MAXBAR) //3 ; Balance is the remainder after a division by 3
    BALF = BALANCE Min 1
    Print At 1,1, Dec3 POWERMAX, "W "
    Print At 1,6, Rep FULLBAR\BARS,Rep (BALANCE + BASEBAR)\BALF,Rep " "\B_WDTH - (BARS + BALF)
    BARS = (LOW_BAR Min MAXBAR) / 3 ; One full bar for each 3 graph units
    BALANCE = (LOW_BAR Min MAXBAR) //3 ; Balance is the remainder after a division by 3
    BALF = BALANCE Min 1

  26. #226
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    You are on the wrong forum. Here is MELABS PicBasic Forum.

    But anyway, REP is just repeating the next character \times

    Ioannis

  27. #227
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Quote Originally Posted by Acetronics View Post
    Hi, DON
    Just turn your LCD 90° cckw !!!
    Alain
    Did a vertical graphing tachometer over time with a single custom char (far right in the video).



    Just got to matrix rotate the byte and shift every byte in the custom char every frame to make room for the next vertical byte.
    (this one has odometer effect on the elapsed timer as well

  28. #228
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Hi Art. It is awesome! Really nice effect.

    Ioannis

  29. #229
    Join Date
    Nov 2003
    Location
    Sao Paulo - Brazil
    Posts
    92


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Hi Art !

    nice idea for the tachometer.

    I have an old project, where I´m already using 8 custom chars to show darrel´s bargraph, and other "compressed characters, like "Km/l" , "L/h".

    Is it possible to re-use the custom char to show the odometer efect and this nice tachometer or this is not possible ?

    Is your code for the tachometer complicated ?

    Thank you.

    Sérgio

  30. #230
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Hi,
    I'll post it go in it's own thread in a little bit.
    The tach is interrupt driven, display is PBP.
    I'm close to finishing something much nicer

  31. #231
    Join Date
    Nov 2003
    Location
    Sao Paulo - Brazil
    Posts
    92


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Hi Art,

    Thank you very much for your reply !

    I Will wait for your post.

    My best regards.

    Sérgio

  32. #232
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Hi srspinho,

    Unfortunately I have lost that code
    In the end, for that project, I ditched both the graphing tachometer,
    and the rolling odometer effect for the time display.
    They both looked good on the desk where the project spent a couple of months,
    but in the car, they both turned out to be a terrible idea.

    I could see the peak on the tachometer graph, but not tell if it was the current
    reading without looking hard, and the same with the elapsed time.
    I went back to a plain vertical bargraph for the tachometer:



    I do still have current code for the project that I wouldn't otherwise mind sharing entirely,
    but I would mind spending the time making sense of it where it was not written for others.
    It is only a collection of things available here, or substitutes for them done myself.
    I did my own asm interrupts for example, but DT's interrupts do exactly the same thing.

    I have an old project, where I´m already using 8 custom chars to show darrel´s bargraph, and other "compressed characters, like "Km/l" , "L/h".
    Is it possible to re-use the custom char to show the odometer efect and this nice tachometer or this is not possible ?
    I didn't read this correctly.
    No, it is only possible to display eight at a time, you can only change the content of those eight locations an unlimited number of times.
    otherwise it would be a full graphics LCD. THe elapsed timer in this one is only using six of them, the tach uses one, and there's a spare.
    Last edited by Art; - 14th October 2013 at 07:26.

  33. #233
    Join Date
    Nov 2003
    Location
    Sao Paulo - Brazil
    Posts
    92


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Thank you Art !

    I think I Will try your 2x16 graphic lib .

    Regards.

Closed Thread
Page 6 of 6 FirstFirst ... 23456

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. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  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 : 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