Hier ein Beispiel mit noch feinerer Auflösung:

Es werden 5 Benutzerdefinierte Zeichen benötigt,

Die Auflösung von einer Pixelspalte ist nun möglich (Zeichen = 5 Pixel Breit)

Bei Wert = 0 wird kein Balken angezeigt,
ab Wert = 1 wird bereits ein Balken angezeigt.


Code:
'-----------------------------------------------------------------------------------------
'name                     : LCD-Interface Messwert Darstellung.bas
'purpose                  : TEST: LCD 16 Chars, 2 Lines  / Bargraph Output
'micro                    : Mega32
'suited for demo          : yes
'commercial addon needed  : no
'programmer               : darwin.nuernberg (www.roboternetz.de)
'-----------------------------------------------------------------------------------------

$regfile = "m32def.dat"                                     ' specify the used micro
$crystal = 8000000                                          ' used crystal frequency
$baud = 9600                                                ' use baud rate
$hwstack = 32                                               ' default use 32 for the hardware stack
$swstack = 10                                               ' default use 10 for the SW stack
$framesize = 40                                             ' default use 40 for the frame space




' Die folgende Zeile entfernen wenn das Programm NICHT im Simulator laufen soll
$sim                                                        ' entfernen wenn keine Bascom Simulation
' ==============================================================================




Definitionen:
Declare Function Finebargraph(byval Messwert As Word , Byval Verbose As Byte) As String       ' Messwert = eine 10-Bit-Variable


' LCD einrichten
Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7 , E = Portc.7 , Rs = Portc.6                                                            ' $sim is used for faster simulation
Deflcdchar 7 , 31 , 31 , 31 , 31 , 31 , 31 , 31 , 31                            ' Volles Segment
Deflcdchar 6 , 30 , 30 , 30 , 30 , 30 , 30 , 30 , 30                            ' 4 Spalten
Deflcdchar 5 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28                            ' 3 Spalten
Deflcdchar 4 , 24 , 24 , 24 , 24 , 24 , 24 , 24 , 24                            ' 2 Spalten
Deflcdchar 3 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16                            ' 1 Spalte

Config Lcd = 16 * 2
Initlcd

' ==============================================================================


Hauptprogramm:

Dim Mw As Word                                                                  ' Messwert
Dim X As Word

Cls                                                                             ' LCD löschen

   For X = 0 To 1024 Step 12
      Locate 1 , 1
      Lcd " WERT " ; X
      Locate 2 , 1
      Lcd Finebargraph(x , 0)
      Lcd "<"

   Next X
   Waitms 500

Do

   Input " Messwert eingeben : " , Mw                                           ' Eingabe zum Testen
   Cls                                                                          ' LCD löschen
   Locate 1 , 1                                                                 ' Pos. in 1. Zeile an 1. Stelle
   Lcd "BARGRAPH"                                                               ' Text auf das LCD Schreiben

   Locate 2 , 1
   Lcd Finebargraph(mw , 1)                                                     ' 2. Parameter = 0 keine Printausgaben
     Lcd "<"

Loop
End                                                                             'end program

' ==============================================================================

Function Finebargraph(byval Messwert As Word , Byval Verbose As Byte) As String * 17       ' Messwert = eine 10-Bit-Variable

   Const Rows_in_bargraphline = 16                                              ' Zeichenlänge des Ausgabe - Strings (Chars)
   Const Rows_per_bargraphchar = 5                                              ' Pixelspalten pro Zeichen (Sonderzeichen)
   Const Bargraphmaxvalue = 1024                                                ' Maximaler Wert

   Local Finebargraphresolution As Word                                         ' feinste Auflösung
   Local Roughbargraphresolution As Word                                        ' Auflösung 1 Volles Zeichen
   Local Countbargraphfullchar As Word                                          ' Anzahl Vollzeichen
   Local Bargraphrest As Word                                                   ' Rest welcher nicht als Vollzeichen dargestellt wird
   Local Bargraphfinechar As String * 1                                         ' Char -  für feinauflösung
   Finebargraphresolution = Rows_in_bargraphline * Rows_per_bargraphchar
   Finebargraphresolution = Bargraphmaxvalue / Finebargraphresolution

   Roughbargraphresolution = Bargraphmaxvalue / Rows_in_bargraphline


   Countbargraphfullchar = Messwert / Roughbargraphresolution                   ' Anzahl ganzer Segmente
   Bargraphrest = Messwert Mod Roughbargraphresolution                          ' Restwert



   Select Case Bargraphrest
      Case 0 : Bargraphfinechar = Chr(32)                                       ' Zur Darstellung des Restwertes
      Case Is <= 12 : Bargraphfinechar = Chr(3)
      Case Is <= 24 : Bargraphfinechar = Chr(4)
      Case Is <= 36 : Bargraphfinechar = Chr(5)
      Case Is <= 48 : Bargraphfinechar = Chr(6)
      Case Is <= 60 : Bargraphfinechar = Chr(7)
      Case Else : Bargraphfinechar = ""                                         ' nichts weiter
   End Select


   If Verbose > 0 Then
      Print " Maximalwert        = " ; Bargraphmaxvalue                         ' Maximal darstellbarer Wert
      Print " grobe Aufloesung   = " ; Roughbargraphresolution                  ' grobe Auflösung (1-Zeichen)
      Print " feinste Aufloesung = " ; Finebargraphresolution                   ' feine Auflösung (1 Pixelspalte)
      Print " Anzahl ganzer Seg. = " ; Countbargraphfullchar                    ' Anzahl der "Vollzeichen"
      Print " Rest des Wertes    = " ; Bargraphrest                             ' verbleibender Wert für Feindarstellung
      Print
   End If


   If Countbargraphfullchar > 0 Then
    Finebargraph = String(countbargraphfullchar , 7) + Bargraphfinechar
   Else
    Finebargraph = Bargraphfinechar
   End If
   Finebargraph = Trim(finebargraph)

End Function

End                                                                             'end program