DESIGN NOTE
AUTHOR: ALONZO TRUELAND
KEYWORDS: LCD, BASCOM, INSTRUMENTATION, GRAPHICAL #036
This document is originally distributed by [Link], and may be distributed, reproduced, and modified
without restrictions. Updates and additional design notes can be found at: [Link]
Virtual Instrumentation
The following design note is an example of a method used to display measurement
information that has the “look” of instrumentation. This program is taken from a larger
program that was developed using Bascom-Avr. The design monitors wind speed/direc-
tion. This design note will only focus on the display portion, so the code for the wind
instruments has been replaced with a user input from a terminal. The wind direction
information is displayed in the form of a virtual compass. The dial is a circle with the
compass directions displayed. The indicator is an arrow in the center of the dial that
points in the direction of the wind. The wind-speed indicator is displayed using a vertical
level bar that has a range between 0 and 100 mph. In addition to the graphical depiction,
text information is also displayed. The following code can easily be modified to produce
different gauges to display other types of measurement info.
Figure 1. Windmeter
[Link] 1
Design Note #036 – Date: 01/03
Figure 2. Schematics
Code ***partial code for a wind meter(graphical part)
$crystal = 4000000
Dim Arrow As Single
Dim T As Single
Dim H As Single
Dim V As Single
Dim Z As Single
Dim K As Single
Dim L As Single
Dim B As Byte
Dim R As Byte
Dim S As Byte
Dim C As Byte
Dim D As Byte
Dim Q As Byte
Dim W As Byte
Dim J As Byte
Dim M As Byte
Dim Color As Byte
Dim Newspe As Byte
Dim Oldspe As Byte
Dim Ff As Byte
Dim Rr As Byte
Dim Cross As Word
2 [Link] Design Note #036 – Date: 01/03
Dim Newdir As Word
Dim Olddir As Word
Dim F As String * 5
Config Graphlcd = 240 * 128 , Dataport = Portb , Controlport = Portc , Ce = 2
, Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 8
Cls
Cursor Off
Wait 1
'***************draw compass and wind speed bar********************
Showpic 0 , 0 , Dial
Showpic 120 , 7 , Bar
'**********************declare sub's *******************************
Declare Sub Draw_dial(cross As Word , Byval Color As Byte)
Declare Sub Draw_speed(speed As Byte , Byval Rr As Byte)
'*********************program loop ********************************
Do
Input “ENTER DIRECTION” , Newdir 'enter wind direction in degrees
Input “ ENTER SPEED” , Newspe 'enter speed in mph
Call Draw_dial(olddir , 0) 'erase old pointer
Call Draw_dial(newdir , 255) 'draw new pointer
Olddir = Newdir 'save current direction
Call Draw_speed(oldspe , 0) 'erase old wind speed bar
Call Draw_speed(newspe , 255) 'draw new wind speed bar
Oldspe = Newspe 'save current wind speed
Loop
End 'end program
'*************************sub used to draw the pointer***************
Sub Draw_dial(cross As Word , Color As Byte) 'cross is the degree position
and byte is the line color
'this code is used to move the "0" degree mark from a 3:00 position to a
'12:00 position
Arrow = Cross
Arrow = Arrow + 90
Arrow = Arrow * 3.14
Arrow = Arrow / 180
'*************************get x position long arm********************
K = Arrow + 3.142
K = Cos(k)
K = K * 55
K = K + 55
R = K
'*************************get y position long arm********************
L = Arrow + 3.142
L = Sin(l)
L = L * 55
L = 55 + L
S = L
Design Note #036 – Date: 01/03 [Link] 3
'************************draw long arrow arm**********************
Showpic 0 , 0 , Dial
Line(55 , 55) -(r , S) , Color
'************************get x position short arm********************
V = Cos(arrow)
V = V * 35
V = V + 55
W = V
'************************get y position short arm********************
Z = Sin(arrow)
Z = Z * 35
Z = Z + 55
Q = Z
'****************************draw short arm***********************
Line(55 , 55) -(w , Q) , Color
'********************** get x position arrow half*********************
T = Arrow + 3
T = Cos(t)
T = T * 44
T = T + 55
D = T
'********************get y position arrow half************************
H = Arrow + 3
H = Sin(h)
H = H * 44
H = H + 55
J = H
'**********************draw arrow half*****************************
Line(r , S) -(d , J) , Color
'********************get x position other arrow half*******************
T = Arrow + 3.28
T = Cos(t)
T = T * 44
T = T + 55
D = T
'******************get y position other arrow half*********************
H = Arrow + 3.28
H = Sin(h)
H = H * 44
H = H + 55
J = H
'*********************draw other arrow half************************
Line(r , S) -(d , J) , Color
'*********************get wind direction****************************
Select Case Cross
Case Is < 13 : F = “N”
Case Is < 35 : F = “N-NE”
Case Is < 57 : F = “NE”
4 [Link] Design Note #036 – Date: 01/03
Case Is < 79 : F = “E-NE”
Case Is < 103 : F = “E”
Case Is < 126 : F = “E-SE”
Case Is < 146 : F = “SE”
Case Is < 169 : F = “S-SE”
Case Is < 192 : F = “S”
Case Is < 213 : F = “S-SW”
Case Is < 238 : F = “SW”
Case Is < 258 : F = “W-SW”
Case Is < 283 : F = “W”
Case Is < 306 : F = “W-NW”
Case Is < 327 : F = “NW”
Case Is < 348 : F = “N-NW”
Case Is < 361 : F = “N”
End Select
'**********display wind direction***********************************
Locate 16 , 2
Lcd " "
Showpic 0 , 120 , Degclr
Locate 16 , 2
Lcd Cross ; “ “ ; F
Select Case Cross
Case Is < 10 : Showpic 16 , 120 , Deg 'used to dispaly the degree symbol
Case Is < 100 : Showpic 24 , 120 , Deg
Case Is < 361 : Showpic 32 , 120 , Deg
End Select
End Sub
'*************sub used to display a vertical level indicator*************
Sub Draw_speed(speed As Byte , Rr As Byte)
Showpic 120 , 7 , Bar
Locate 16 , 10
Lcd " "
Locate 16 , 10
Lcd Speed ; “mph”
Speed = 110 - speed
For Ff = 110 To Speed Step -1 'each line is = to 1mph
Line(120 , Ff ) -(127 , Ff ) , Rr
Next Ff
End Sub
'************************graphic files*****************************
Dial:
$bgf “[Link]”
Deg:
$bgf “[Link]”
Degclr:
$bgf “[Link]”
Bar:
$bgf “[Link]”
Design Note #036 – Date: 01/03 [Link] 5