AN #184 - Bascom
Oscilloscope
Digital Oscilloscope based on AVR and BASCOM-AVR.
by AVR64
This is a Digital Oscilloscope based on AVR. this Oscilloscope has professional settings such as
horizontal, vertical, Domain, Sweep, Refresh, Scan Speed, etc.
Click here for download archive with source code and schematic
Source code:
'---------------------------------------------------------------
'Digital Oscilloscope <Oscope2.bas>
'Programmer: Behnam Zakizadeh
'Compiler : BASCOM 2.0.4.0
'Creation Date: 04.Dec.2010
'Last Change: 23.Apr.2011
'Copyright: © 2011 By www.avr64.com
'License: This Is A Free Firmware, Ver: 2.01
'Suitable for Bascom Demo: Yes (less than 4KB)
'---------------------------------------------------------------
$regfile = "m16def.dat"
$crystal = 4000000
$hwstack = 64
$swstack = 64
$framesize = 64
'GLCD
$lib "glcdKS108.lbx"
Config Graphlcd = 128 * 64sed , Dataport = Portc , Controlport = Porta , Ce = _
6 , Ce2 = 7 , Cd = 2 , Rd = 3 , Reset = 5 , Enable = 4
Setfont My6_8
'A2D
Config Adc = Single , Prescaler = Auto , Reference = Internal
Enable Adc
Start Adc
'I/O
Config Pind.4 = Input 'K1
Config Pind.5 = Input 'K2
Config Pind.6 = Input 'K3
Config Pinb.0 = Input 'K4
Set Portd.4 'Set Pullup Res
Set Portd.5 '//
Set Portd.6 '//
Set Portb.0 '//
'Variables
Dim A As Word
Dim X As Byte , Speed As Word , Temp1 As Word
Speed = 1
Dim Refresh As Word
Refresh = 40
Cls
Lcdat 1 , 1 , "Digital Oscilloscope"
Wait 1
Cls
Showpic 0 , 0 , Pic1
Do
'Horizontal Set
If Pind.4 = 0 Then
If Speed < 1000 Then
Incr Speed
End If
End If
If Pinb.0 = 0 Then
If Speed > 0 Then
Decr Speed
End If
End If
'Refresh Speed Set
If Pind.6 = 0 Then
If Refresh < 4000 Then
Refresh = Refresh * 2
End If
End If
If Pind.5 = 0 Then
If Refresh > 2 Then
Refresh = Refresh / 2
End If
End If
For X = 0 To 127
A = Getadc(1)
A = A / 16
A = 64 - A
'Draw Line ---___---___---___
Pset X , A , 255
'Horizontal
For Temp1 = 1 To Speed
Waitus 1
Next Temp1
Next
Waitms Refresh
Cls
Showpic 0 , 0 , Pic1
Lcdat 1 , 1 , "Sweep: " ; Speed
Lcdat 2 , 1 , "Refresh: " ; Refresh
Loop
End
Pic1:
$bgf "Oscope.bgf"
$include "my6_8.font"
[ Back ]