Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Bar Graphs/progress bars

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Tue Dec 05, 2023 7:24 am    Post subject: Bar Graphs/progress bars Reply with quote

I wanted to draw bar graphs and a battery level indicator on 128 x 64 and 240 x 64
displays but wanted a simple versatile code conservative way to do it I made some
bit map files converted them to bgf format for bascom and now can make a number
of bar type objects on the displays simply by stacking the the bit maps the demo code for
a 240 x 64 display is below the bgf bit maps in the zip

Note this was only a rompage of 1862
Regards Paul

Code:

$regfile = "m1284pdef.dat"                                  'Set the AVR to use.
$crystal = 20000000                                         'Set the AVR clock.
   '
$hwstack = 40                                               'Set the capacity of the hardware stack.
$swstack = 40                                               'Set the capacity of the software stack.
$framesize = 40                                             'Set the capacity of the frame area.
$baud = 115200



'First we define that we use a graphic LCD
'Config Graphlcd = 128x64sed , Dataport = Porta , Controlport = Portc , Ce = 2 , Ce2 = 3 , Cd = 7 , Rd = 6 , Reset = 4 , Enable = 5
Config Graphlcd = 240x64 , Dataport = Porta , Controlport = Portc , Ce = 5 , Cd = 6 , Wr = 3 , Rd = 4 , Reset = 7 , Fs = 2 , Mode = 6

'The dataport is the portname that is connected to the data lines of the LCD
'The controlport is the portname which pins are used to control the lcd
'CE =CS1  Chip select
'CE2=CS2  Chip select second chip
'CD=Data/instruction
'RD=Read
'RESET = reset
'ENABLE= Chip Enable







   Dim Bars As Word


Config Portd.6 = Output                                     'flashing led




      Cls                                                   'Erase the full screen of the graphic LCD.








   Do

     'flash led
     Reset Pind.6
    Wait 1
    Set Pind.6
    Cursor Off


     Cls

     For Bars = 0 To 60 Step 6
     Locate 1 , 1 : Lcd Bars
     Showpic Bars , 48 , Hsbar
     Wait 1
     Next


     For Bars = 64 To 0 Step -8
     Locate 1 , 1 : Lcd Bars
     Showpic 90 , Bars , Vsbar
     Wait 1
     Next


     Cls

     For Bars = 64 To 0 Step -8
     Locate 1 , 1 : Lcd Bars
     Showpic 90 , Bars , Vs8bar
     Wait 1
     Next

     For Bars = 0 To 60 Step 6
     Locate 1 , 1 : Lcd Bars
     Showpic Bars , 48 , Hs8bar
     Wait 1
     Next




   Loop
   '
   End                                                      'The end of the program.





     'horizontal bar
   Hsbar:
  $bgf "HSbar.bgf"
     'vertical bar
   Vsbar:
  $bgf "vSbar.bgf"

    'small  vertical bar  8 pixle
   Vs8bar:
  $bgf "VS8bar.bgf"

   'small  horizontal bar  8 pixle
   Hs8bar:
  $bgf "HS8bar.bgf"
 
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5881
Location: Holland

blank.gif
PostPosted: Fri Dec 08, 2023 10:43 am    Post subject: Reply with quote

hi Paul

thank you for sharing Very Happy
A clever way to make bars with little resources since the bgf files are very small.

would love to see a screen dump too.

_________________
Mark
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Fri Dec 08, 2023 2:00 pm    Post subject: Reply with quote

I am working on having a box around the bar like we see on battery meters
as soon as its working correctly so the size of the graph can be set then
just the number of steps is then told to be placed in the box I will post it

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Wed Dec 13, 2023 4:24 am    Post subject: Reply with quote

Now a sub that makes a battery/level graph in a box by providing 4 parameters
the line number the character number the size of bar in characters and the number
of blocks in the bar the last parameter is to turn the box on/off 0 = on , 1 = off



see previous post for VS8bar.bgf
Regards Paul





Code:







$regfile = "m1284pdef.dat"                                  'Set the AVR to use.
$crystal = 20000000                                         'Set the AVR clock.
   '
$hwstack = 40                                               'Set the capacity of the hardware stack.
$swstack = 40                                               'Set the capacity of the software stack.
$framesize = 40                                             'Set the capacity of the frame area.
$baud = 115200



'First we define that we use a graphic LCD
'Config Graphlcd = 128x64sed , Dataport = Porta , Controlport = Portc , Ce = 2 , Ce2 = 3 , Cd = 7 , Rd = 6 , Reset = 4 , Enable = 5
Config Graphlcd = 240x64 , Dataport = Porta , Controlport = Portc , Ce = 5 , Cd = 6 , Wr = 3 , Rd = 4 , Reset = 7 , Fs = 2 , Mode = 6

'The dataport is the portname that is connected to the data lines of the LCD
'The controlport is the portname which pins are used to control the lcd
'CE =CS1  Chip select
'CE2=CS2  Chip select second chip
'CD=Data/instruction
'RD=Read
'RESET = reset
'ENABLE= Chip Enable





  Const Black = &B00000000

   Dim Bars As Word

   Dim Xpos As Byte                                         '0 at left  122/234 the far right  for 6 pixel setting 120/232 8 pixel
   Dim Ypos As Byte                                         '0 at top 56 the bottom  8 pixel only vertical
   Dim Barhigh As Byte                                      'number of characters high
   Dim Maxsteps As Byte
   Dim X As Byte
   Dim Y As Byte

Declare Sub Battbar(byval L As Byte , Byval C As Byte , Byval S As Byte , Byval N As Byte , Byval B As Byte)

Config Portd.6 = Output                                     'flashing led

  Do
       'Note you need to clear the screen at each update and rewrite it again
      Cls

   Battbar 6 , 9 , 7 , 2 , 0                                'line 6  , character 9  , 7 high , number of bars   2

   Wait 1
    Cls
   Battbar 6 , 9 , 7 , 4 , 0                                'line 6  , character 9  , 7 high , number of bars   4

   Wait 1
   Cls
   Battbar 6 , 9 , 7 , 3 , 0                                'line 6  , character 9  , 7 high , number of bars     3

   Wait 1
   Cls

 Battbar 6 , 9 , 7 , 5 , 0                                  'line 6  , character 9  , 7 high , number of bars      5

 Wait 3

    Cls

   Battbar 7 , 3 , 7 , 4 , 0                                'line 7  , character 3  , 7 high , number of bars   4

   Battbar 6 , 9 , 6 , 4 , 0                                'line 6  , character 9  , 6 high , number of bars   4

   Battbar 6 , 14 , 5 , 3 , 0                               'line 6  , character 14  , 5 high , number of bars   3

 Wait 5

   'now a bar graph chart mixer display

Cls

     Battbar 7 , 2 , 7 , 4 , 1
     Battbar 7 , 4 , 7 , 6 , 1
     Battbar 7 , 6 , 7 , 3 , 1
     Battbar 7 , 8 , 7 , 2 , 1
     Battbar 7 , 10 , 7 , 6 , 1
     Battbar 7 , 12 , 7 , 1 , 1
     Battbar 7 , 14 , 7 , 5 , 1
     Battbar 7 , 16 , 7 , 3 , 1
     Battbar 7 , 18 , 7 , 4 , 1

  Wait 5



Loop

End

  Sub Battbar(byval L As Byte , Byval C As Byte , Byval S As Byte , Byval N As Byte , Byval B As Byte)

  Local W As Byte
          '6 pixel setting
    Xpos = C * 6                                            '15 characters
    Ypos = L * 8                                            'bottom of display
    Maxsteps = S + 1

    Barhigh = Maxsteps * 8
    Barhigh = 64 - Barhigh

     Y = Ypos + 8
             For W = 1 To N
           Showpic Xpos , Ypos , Vs8bar
                             Ypos = Ypos - 8
                             If B = 0 Then
                              Box(xpos -2 , Y) -(xpos + 9 , Barhigh ) , 255
                             End If
           Next

   End Sub



      Vs8bar:
  $bgf "VS8bar.bgf"

 
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum