'Global declarations for IOBUS

'We used the library BUS.DLL to address the I/O ports

'Needs to be declared as a module

Declare Function InByte Lib "BUS.DLL" (ByVal Number As Integer) As Integer

Declare Sub OutByte Lib "BUS.DLL" (ByVal Number As Integer, ByVal Number As Integer)

VISUAL BASIC VERSION 2.00



Begin Form form1

BackColor = &H00808080&

Caption = "fg"

ClientHeight = 6570

ClientLeft = 1560

ClientTop = 1815

ClientWidth = 9015

DrawMode = 15 'Merge Pen

FillColor = &H0000FFFF&

FillStyle = 4 'Upward Diagonal

ForeColor = &H00808080&

Height = 6975

Left = 1500

LinkTopic = "form1"

ScaleHeight = 6570

ScaleWidth = 9015

Top = 1470

Width = 9135

Begin SSRibbon GroupPush3D2

AutoSize = 0 'None

GroupNumber = 2

Height = 495

Left = 6960

PictureDn = FORM1.FRX:0000

PictureDnChange = 0 'Use 'PictureUp' Bitmap Unchanged

PictureUp = FORM1.FRX:016A

RoundedCorners = 0 'False

Top = 3480

Width = 495

End

Begin SSRibbon GroupPush3D1

AutoSize = 0 'None

Height = 495

Left = 6360

MousePointer = 1 'Arrow

PictureDn = FORM1.FRX:02D4

PictureDnChange = 0 'Use 'PictureUp' Bitmap Unchanged

PictureUp = FORM1.FRX:043E

RoundedCorners = 0 'False

Top = 3480

Width = 495

End

Begin TextBox Text1

BackColor = &H00000000&

Height = 495

Left = 4680

TabIndex = 8

Top = 4200

Width = 1095

End

Begin HScrollBar HScroll2

Height = 255

Left = 6360

TabIndex = 7

Top = 3000

Width = 1095

End

Begin Timer Timer1

Enabled = 0 'False

Left = 240

Top = 5880

End

Begin CommandButton Command7

BackColor = &H00808080&

Caption = " Reset 8255"

Height = 855

Left = 6360

TabIndex = 6

Top = 1920

Width = 1095

End

Begin CommandButton Command6

BackColor = &H00808080&

Caption = "8255"

Height = 375

Left = 6360

TabIndex = 5

Top = 1440

Width = 1095

End

Begin CommandButton Command1

BackColor = &H00808080&

Caption = "Random"

Height = 375

Left = 6360

TabIndex = 1

Top = 240

Width = 1095

End

Begin HScrollBar HScroll1

Height = 255

Left = 120

Max = 100

Min = 1

TabIndex = 4

Top = 4800

Value = 1

Width = 5655

End

Begin VScrollBar VScroll1

Height = 4455

Left = 5880

TabIndex = 3

Top = 240

Width = 255

End

Begin CommandButton Command2

BackColor = &H00808080&

Caption = "Cos(x)"

Height = 375

Left = 6360

TabIndex = 2

Top = 840

Width = 1095

End

Begin GRAPH Graph1

AsciiColor = "14~5~5~5~4~7~4~2~1~1"

AsciiSymbol = "4"

Background = 0 'Black

BorderStyle = 0 'None

DragMode = 1 'Automatic

DrawMode = 3 'Blit

Foreground = 10 'Light Green

GraphType = 6 'Line

GridStyle = 3 'Horizontal and Vertical

Height = 4455

IndexStyle = 1 'Enhanced

Labels = 0 'Off

Left = 120

NumPoints = 10

PrintStyle = 2 'Monochrome with Border

TabIndex = 0

TabStop = 0 'False

ThickLines = 0 'Off

TickEvery = 10

Ticks = 0 'Off

Top = 240

Width = 5655

YAxisTicks = 5

End

End

Dim vs, hs, hs2, k, d, mult, Vmax As Integer

Sub ali ()

'Function to check the alias bit.

InVal = InByte(Val("&H302"))

InVal = InVal And &H1

If InVal = 1 Then

Text1.Text = "Alias" 'Display Msg.

Else

Text1.Text = "Good" 'Display Msg.

End If

End Sub

Sub Command1_Click ()

repeat:

Graph1.RandomData = 1 'Generate some random data

Graph1.DrawMode = 3 'to use during testing

DoEvents

GoTo repeat

End Sub

Sub Command2_Click ()

wave vs, hs 'Run a cos(x) wave to use during

'testing.

End Sub

Sub Command6_Click ()

timer1.Enabled = 1 'Start running the actual scope

End Sub

Sub Command7_Click ()

OutByte Val("&H303"), Val("&H91") 'Configure 8255 for mode 0, (A & CL = input)

'and (B & CU = output)

End Sub

Sub Form_Load ()

'Initialize Variables

Graph1.ColorData = 14 'Initialize color

HScroll1.Min = 10 ' Initialize scroll bar.

HScroll1.Max = 1000

HScroll2.Min = 1 ' Initialize scroll bar.

HScroll2.Max = 650

VScroll1.Max = 255

VScroll1.Min = 1

VScroll1.Value = 128

Graph1.NumPoints = HScroll1.Value

HScroll1.Value = 500 'Initialize Time Base

GroupPush3D2.Enabled = False 'Initialze push buttons

OutByte Val("&H303"), Val("&H91") 'Configure 8255 for mode 0, (A & CL = input)

'and (B & CU = output)

d = 1 'd is the graph divisior factor (d)

mult = 1 'mult is the factor we multiply the graph by

End Sub

Sub Form_Resize ()

'Next, we have the code for the sizes of all

'buttons as a function of the size of the form.

'This way everything is resizeable

Graph1.Width = Form1.Width * .8 ' Set width of form.

Graph1.Height = Form1.Height * .8 ' Set height of form.

Graph1.Left = Form1.Width * .02 ' Center form horizontally.

Graph1.Top = Form1.Height * .04 ' Center form vertically.

command1.Height = 375

command1.Left = Graph1.Left + Graph1.Width + .04 * Form1.Width

command1.Top = 240

command1.Width = Form1.Width - command1.Left - (.01 * Form1.Width)

command2.Width = command1.Width

command2.Height = 375

command2.Left = command1.Left

command2.Top = 840

command6.Width = command1.Width

command6.Height = 375

command6.Left = command1.Left

command6.Top = 1440

command7.Width = command1.Width

command7.Height = 855

command7.Left = command1.Left

command7.Top = 2040

HScroll1.Width = Graph1.Width

HScroll1.Height = 255

HScroll1.Left = Graph1.Left

HScroll1.Top = Graph1.Top + Graph1.Height + 30

HScroll2.Width = command1.Width

HScroll2.Height = 255

HScroll2.Left = command1.Left

HScroll2.Top = 3100

VScroll1.Width = 255

VScroll1.Height = Graph1.Height

VScroll1.Left = Graph1.Left + Graph1.Width + 30

VScroll1.Top = Graph1.Top

GroupPush3D1.Width = (command1.Width) * .4

GroupPush3D1.Height = (command1.Height) * 1.5

GroupPush3D1.Left = command1.Left + 50

GroupPush3D1.Top = 3600

GroupPush3D2.Width = (command1.Width) * .4

GroupPush3D2.Height = (command1.Height) * 1.5

GroupPush3D2.Left = GroupPush3D1.Left + GroupPush3D1.Width + 120

GroupPush3D2.Top = 3600

Text1.Width = command1.Width

Text1.Height = (command1.Height)

Text1.Left = Graph1.Left + Graph1.Width - command1.Width

Text1.Top = Graph1.Top + Graph1.Height - Text1.Height

End Sub

Sub GroupPush3D1_Click (Value As Integer)

If Value = False Then

GroupPush3D2.Enabled = False 'Configure so that

timer1.Enabled = 1 'one can't print unless

Else 'we are not running.

GroupPush3D2.Enabled = True

timer1.Enabled = 0 'Freze the image

End If

End Sub

Sub GroupPush3D2_Click (Value As Integer)

If Value = True Then

GroupPush3D2.Enabled = False 'Disable Buttons

GroupPush3D1.Enabled = False

Graph1.DrawMode = 5

GroupPush3D2.Enabled = True 'enable buttons

GroupPush3D1.Enabled = True

GroupPush3D2.Value = False 'set correct value

End If

End Sub

Sub HScroll1_Change ()

HScroll1.LargeChange = 100

HScroll1.SmallChange = 10

hs = HScroll1.Value

Graph1.NumPoints = HScroll1.Value 'Adjust time scale

Graph1.TickEvery = HScroll1.Value

End Sub

Sub HScroll2_Change ()

'This scroll bar is to adjust triggering.

HScroll2.LargeChange = 10

HScroll2.SmallChange = 1

hs2 = HScroll2.Value

timer1.Interval = hs2

End Sub

Sub scal ()

'd is scaling factor

If Vmax > 2 And Vmax < 4 Then 'Vmax between 2 and 4

GoTo 20 'do nothing

End If

If Vmax < 4 Then 'Vmax greater than 4

timer1.Enabled = 0 'Stop sampling to adjust hardware

OutByte Val("&H301"), Val("&Hff") 'output divided by 256

For t = 1 To 10000 'delay to alow hardware response

For s = 1 To 1

Next s

Next t

timer1.Enabled = 1 'wait for data to be updated

GoTo 30

End If

If Vmax < 2 Then 'Vmax less than 2. 2 is our threshold

timer1.Enabled = 0 'Disable old data processing

If d * 2 > 250 Then 'This IF statement protects us

d = 255 'from overflowing the value of

Else 'd when a very, very small

d = d * 2 'signal is at the input.

End If

OutByte Val("&H301"), d 'Output scale factor

timer1.Enabled = 1 'Enable new data processing

mult = d

GoTo 30

End If

20 d = 1 'reset multiplier

30

End Sub

Sub scope55 ()

'The function scope55 is executed as long as timer1 is enabled.

DoEvents

'hi = 128

'lo = 128

For j = 1 To hs Step 1

InVal = InByte(Val("&H300")) 'Get data Register A.

If InVal > hi Then 'Find min and max for graph.

hi = InVal 'I believe this is not the best

GoTo finish 'idea of doing this, since it

ElseIf InVal < lo Then 'slows down the sampling rate.

lo = InVal

End If

finish:

Graph1.GraphData = InVal * mult 'Store Data to be graphed

Next j

Graph1.DrawMode = 3 'Graph Data

' Next, find Vmax which will be used in our decision box (see flow-chart)

'(ideally we should be looking for a median value in order to eliminate

' errors caused by noise spikes in the signal)

'

' (*) In this part we also calibrate the output of the A/D such that a FF means 4.2

' and 7F = 0.

If Abs(hi - 128) > Abs(lo - 128) Then 'we substract 128 to achieve (*)

Vmax = hi

Else

Vmax = lo

End If

Vmax = Vmax * .032813 '0.0328 = 4.2/128. So FF -> 4.2

scal 'Call the decision function (decision box)

ali 'Call the function ali to check alias

End Sub

Sub Timer1_Timer ()

scope55

End Sub

Sub VScroll1_Change ()

VScroll1.LargeChange = 10

VScroll1.SmallChange = 1

vs = VScroll1.Value

End Sub

Private Sub wave (j, i)

recos:

For k = 0 To 1000 Step 1

Graph1.GraphData = j * Cos(k / 40)

Next k

Graph1.DrawMode = 3

DoEvents

GoTo recos

End Sub