LCD BARgraphs


Closed Thread
Results 1 to 40 of 233

Thread: LCD BARgraphs

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Posts
    34


    Did you find this post helpful? Yes | No

    Default AD routine

    Quote Originally Posted by karenhornby View Post
    Can I pick someone's brain please?
    I'm at the moment trying to make an auto switchover gadget to change from running on Diesel to Veg Oil once certain temperatures have been reached, and to try and work this out I'm using the easypic5 development board.
    So far: I have a 16f877A programmed so it will switch certain outputs when certain inputs go high all and well
    It even displays what it's doing on the LCD display

    What I'd like to incorporate if its possible is this? or a variation of it the Bargraph but use it as a fuel level sensor, i.e. changing position depending on the level of the fuel in the tank (variable resistor)

    Does anyone know any code that will do that or give me a starting place to play with?
    I know I've got 2 A/D converter inputs on the developement board I can play with that have a 10K pot connected and are configured so I can change the input on either of the RA0, RA1, RA2, RA3, RA4, or RA5 pins and measure the voltage on them ( unfortunatly I'm only just learning about Pic's at the moment and know nothing about A/D and how to use it, I am learning by trying and experimenting But I am a quick learner), so IF anyone has any code they could share with me to show me how to get started with this I'd be grateful Thanks
    Here is my code for monitoring the sensors in a car. Note: this method is more accurate than ADCIN
    Code:
    '****************************************************************
    '*  Name    : CarMonitor.PBP                                     *
    '*  Author  : Chris Bezuidenhout                                *
    '*  Notice  : Copyright (c) 2007 Micro Developments             *
    '*          : All Rights Reserved                               *
    '*  Date    : 2007/10/23                                        *
    '*  Version : 1.1.1                                             *
    '*  URL      :http://www.patenttrade.net                             *
    '*          :                                                   *
    '****************************************************************
    INCLUDE "Modedefs.Bas"
    
           OSCCON = %01100000                  'set the intrc osc change bit 4 to logic  1 for 8 MHz
           OSCTUNE = %000000
           
    DEFINE 	OSC		4     ' Set IRC Frequency
    DEFINE ADC_BITS 10       ' Set number of bits in result
    DEFINE ADC_CLOCK 1    ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
              
    IgnIn    var     word
    Altin    var     word
    Oilin    var     word
    TempIn   var     word
    ResIn    var     word               'Reserve input
    IgnOut   var     portb.0
    AltOut   var     portb.1
    OilOut   var     portb.2
    TempOut  var     portb.3
    Buzzer   var     portb.4
    ComO     var     portb.5
    SigOut   var     portb.6
    sp2      var     portb.7
    Spin1    var     porta.6
    Spin2    var     porta.7
    X        var     byte
    Y        var     byte
    
    
    TRISA = %11111111          'Porta 0-4 all analog 5 input only pull high
    TRISB = %00000000
    ADCON0 = %11000001
    Pause 2000 ' Wait .5 second 
    ADCON1 = %10000010 ' Set PORTA analog and RIGHT justify result
    
    
    
    OPTION_REG = $7f        ' Enable PORTB pullups
    
    pause 500
    portb = 0
    low Buzzer
         
           
           
    Main:       
           gosub CIgn
           gosub CAlt
           gosub COil
           gosub CTemp
           gosub Send
           
           
    Ignition:
           if ignin = 0 then 
           high Ignout
           gosub Send
           goto main
           endif
           if ignin > 300 then 
           low ignout
           goto Alternator
           endif
    '       if ignin > 0 and ignin < 300 then
           for y = 1 to 3
           gosub CIgn
           gosub Send
           if ignin > 300 then  Alternator
           
           for x = 1 to 2
           high Ignout
           high buzzer
           pause 200
           low buzzer
           pause 200
           next x
           pause 1000
           next y    
           
    '       endif
    Alternator:
               if ignin = 0 then goto main
           low ignout       
           if Altin > 1020 then 
           high altout  '?????????Kalibreer
           for y = 1 to 3
           gosub CAlt
           gosub Send
           if altin < 1020 then Oil
           for x = 1 to 4
           high buzzer
           pause 200
           low buzzer 
           pause 200
           next x
           pause 1000
           next y
           endif
            
    Oil:   
           if ignin = 0 then goto main
           low altout           
           if Oilin > 10 then    'This variable have to be calibrated to sensor unit
           high Oilout           'for a plain on/of it must be set to 0, the pot at minimum 
           for y = 1 to 3        'if there is some contact resistance it can be calibrated acordingly
           gosub COil            'For a analog (resistive) sensor it have to be calibrated to 
           gosub Send            'the sensor
           if oilin < 10 then Temperature    'So is this one
           for x = 1 to 6
           high buzzer
           pause 200
           low buzzer
           pause 200      
           next x
           pause 1000
           next y
           endif
           
    Temperature:
                if ignin = 0 then goto main
           low Oilout
           if tempin < 85 then 
           high tempout
           for y = 1 to 3
           gosub CTemp
           gosub Send
           if tempin > 85 then main
           for x = 1 to 8
           high buzzer
           pause 200
           low buzzer
           pause 200 
           next x
           pause 1000  
           next y
           endif
           low tempout
       goto main         
    CIgn:
           ADCON0 = %11000101             'start ADC  A0
           gosub notdone
           IgnIn.highbyte = ADRESH
           IgnIn.Lowbyte = ADRESL
           write 0,ignin.highbyte
           write 1,ignin.lowbyte
           return
    CAlt:       
           ADCON0 = %11001101             'start ADC A1
           gosub notdone
           altin.highbyte = ADRESH
           altin.Lowbyte = ADRESL
           write 2,Altin.highbyte
           write 3,Altin.lowbyte
           return
    COil:       
           ADCON0 = %11010101             'start ADC A2
           gosub notdone
           oilin.highbyte = ADRESH
           oilin.Lowbyte = ADRESL
           write 4,oilin.highbyte
           write 5,oilin.lowbyte
           return
    CTemp:       
           ADCON0 = %11011101             'start ADC A3
           gosub notdone
           TempIn.highbyte = ADRESH
           TempIn.Lowbyte = ADRESL
           write 6,tempin.highbyte
           write 7,tempin.lowbyte
           return
    CRes:       
           ADCON0 = %11100101             'start ADC A4
           gosub notdone
           resin.highbyte = ADRESH
           resin.Lowbyte = ADRESL
           Return        
    Send:
           serout SigOut, N2400,["A",IgnIn.highbyte,IgnIn.lowbyte,altin.highbyte,altin.lowbyte,Oilin.highbyte,Oilin.lowbyte,Tempin.highbyte,Tempin.lowbyte,resin.highbyte,resin.lowbyte]
           return
    notdone: Pause 5 
           If ADCON0.2 = 1 Then notdone' Wait for low on bit-2 of ADCON0, conversion finished 
           return
    end
    Last edited by ChrisMicro; - 4th July 2008 at 05:16.
    You can't teach an old dog new tricks, but I'm always willing to try.

  2. #2
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Pbpl Bargraph

    hi darrel...

    i m using pbp 2.50b compiler and using pbpl.

    how can i use your include file with pbpl?

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


    Did you find this post helpful? Yes | No

    Default Pbpl

    For each DIV32, change it to a normal divide ...

    Was: Limit1 = DIV32 10

    &nbsp; To:&nbsp; Limit1 = Limit1 / 10

    or you can combine them with the previous statements

    Limit1 = (BAR_range * 3) / 10

    for all the occurances.

    And change the WORD vars to LONG.
    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default LCD bargraph

    hi friends
    I am a new member I can little speak english maybe my errors I am sorry
    My problem is LCD bargraph How I can on pictures project. on pictures LCD 2x16 char , LCD has 32 bars per char has two bars project has two buttons minus and plus I need this projects pic basic code Can you help me. Already tahnks
    Attached Images Attached Images    
    Last edited by tekniker_erhan; - 7th September 2008 at 16:22.

  5. #5
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51


    Did you find this post helpful? Yes | No

    Default lcdbargraph PBPL

    I TRIED YOUR INCLUDE FILE FOR PBPL AND MADE WHAT U SAID.

    IT'S WORKING GOOD THANKS.

    Code:
    '****************************************************************
    '*   Creates a variable sized BAR-graph anywhere on the screen  *
    '****************************************************************
    '*  Name    : LCDbar_INC.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              *
    '*          :                                                   *
    '****************************************************************
                                                   ;                        default
    BAR_width   VAR  BYTE : BAR_width = 16         ; Width of the BARgraph      16
    BAR_range   VAR  LONG : 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  LONG : 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  LONG   ;;;;;;;;
    Remainder   VAR  LONG   ;;;;;;;;
    BARloop     VAR  BYTE
    LastCharset VAR  BYTE : LastCharset = 0
    Limit1      VAR  LONG   ;;;;;;;;
    
    GOTO overBAR                                   ; Skip over Subroutines
    
    ThreeBARS CON 0                                ; Identify the Custom Characters
    TwoBARS   CON 1
    OneBAR    CON 2
    
    ASM
    lines  = 0x10000001                            ; Define the Styles
    boxed  = 0x10000002
    blocks = 0x10000003
    ENDASM
    
    ; --- lines Style custom chars ----
    CharsetLines:
        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   |
    RETURN
    
    ; --- boxed Style custom chars ----
    CharsetBoxed:
        LCDOut $FE,$40,$1F,REP $15\6,$1F          ; III
        LCDOut $FE,$48,$1C,REP $14\6,$1C          ; II
        LCDOut $FE,$50,REP $10\8                  ; I
    RETURN
    
    ; --- blocks Style custom chars ----
    CharsetBlocks:
        LCDOut $FE,$40,REP $1F\8
        LCDOut $FE,$48,REP $1C\8
        LCDOut $FE,$50,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
        
        BARtemp = (BAR_value * BAR_width)/BAR_range    ; CHANGED
    
        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
    		
                    Limit1 = (BAR_range * 6)/10   ; CHANGED
    
    		if Remainder >= Limit1 then
                        LCDOUT TwoBARS            ; send 2 bars    ||
                    else
    ;;;;Limit1 = BAR_range * 3
    ;;;;Limit1 = DIV32 10
    		
    		Limit1 = (BAR_range * 3)/10   ; CHANGED
    
                        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:
    but there is a problem ; when i want to use different bar type on lcd for different rows bar types are mixing.

    example:

    row1 blocks
    row2 lines
    row3 boxed
    row4 blocks

    when use it like this all rows are one type bar.

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


    Did you find this post helpful? Yes | No

    Default

    Great! Glad you got it working, and thanks for the updated code.

    There's only 1 area for custom characters in the LCD.
    So you can only have one Style at a time. Sorry.
    <br>
    DT

  7. #7


    Did you find this post helpful? Yes | No

    Default Bargraph

    Quote Originally Posted by mehmetOzdemir View Post
    I TRIED YOUR INCLUDE FILE FOR PBPL AND MADE WHAT U SAID.

    IT'S WORKING GOOD THANKS.

    Code:
    '****************************************************************
    '*   Creates a variable sized BAR-graph anywhere on the screen  *
    '****************************************************************
    '*  Name    : LCDbar_INC.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              *
    '*          :                                                   *
    '****************************************************************
                                                   ;                        default
    BAR_width   VAR  BYTE : BAR_width = 16         ; Width of the BARgraph      16
    BAR_range   VAR  LONG : 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  LONG : 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  LONG   ;;;;;;;;
    Remainder   VAR  LONG   ;;;;;;;;
    BARloop     VAR  BYTE
    LastCharset VAR  BYTE : LastCharset = 0
    Limit1      VAR  LONG   ;;;;;;;;
    
    GOTO overBAR                                   ; Skip over Subroutines
    
    ThreeBARS CON 0                                ; Identify the Custom Characters
    TwoBARS   CON 1
    OneBAR    CON 2
    
    ASM
    lines  = 0x10000001                            ; Define the Styles
    boxed  = 0x10000002
    blocks = 0x10000003
    ENDASM
    
    ; --- lines Style custom chars ----
    CharsetLines:
        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   |
    RETURN
    
    ; --- boxed Style custom chars ----
    CharsetBoxed:
        LCDOut $FE,$40,$1F,REP $15\6,$1F          ; III
        LCDOut $FE,$48,$1C,REP $14\6,$1C          ; II
        LCDOut $FE,$50,REP $10\8                  ; I
    RETURN
    
    ; --- blocks Style custom chars ----
    CharsetBlocks:
        LCDOut $FE,$40,REP $1F\8
        LCDOut $FE,$48,REP $1C\8
        LCDOut $FE,$50,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
        
        BARtemp = (BAR_value * BAR_width)/BAR_range    ; CHANGED
    
        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
    		
                    Limit1 = (BAR_range * 6)/10   ; CHANGED
    
    		if Remainder >= Limit1 then
                        LCDOUT TwoBARS            ; send 2 bars    ||
                    else
    ;;;;Limit1 = BAR_range * 3
    ;;;;Limit1 = DIV32 10
    		
    		Limit1 = (BAR_range * 3)/10   ; CHANGED
    
                        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:
    but there is a problem ; when i want to use different bar type on lcd for different rows bar types are mixing.

    example:

    row1 blocks
    row2 lines
    row3 boxed
    row4 blocks

    when use it like this all rows are one type bar.
    turkish mean
    özdemir dostum bu program nasıl çalışıyor uygulama şemasını ekleye bilirmisin banada resimdeki 2 butonlu bargraph uygulaması lazım yukarıda resimleri ekledim bu programı 2 butonlu şekilde düzenleyebilirmiyiz. şimdiden teşekkürler bide ingilizce yazmaya çalışım ayıp olmasın

    english mean ,maybe my errors, Im sorry
    özdemir my friend,how is run this program can you attach application circuit I need on picture bargraph application with two buttons How I can make this project can you helpme already thanks

  8. #8
    Join Date
    Sep 2008
    Location
    Stockholm
    Posts
    80


    Did you find this post helpful? Yes | No

    Default

    Great stuff

    Worked on the first try in my latest program, which I didn't really expected

    I started to write something own, until I remembered that I had a vague memory of seeing something like this on the forum, and here it was, ready to be used


    Would be really nice to have a logarithmic scale too, I didn't really understood everything people wrote about logarithmic, did anyone come up with a quick software-only solution ?

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 : 2

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