⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex05 - led graph.bs2

📁 proteus得一些经典例子
💻 BS2
字号:
' {$STAMP BS2}
' ==============================================================================
'
' File...... Ex05 - LED Graph.BS2
' Purpose... LED Bar Graph
' Author.... Parallax
' E-mail.... stamptech@parallaxinc.com
' Started...
' Updated...
'
'
' ==============================================================================
' ------------------------------------------------------------------------------
' Program Description
' ------------------------------------------------------------------------------
' Displays a linear (bar) or dot graph using 8 LEDs
' ------------------------------------------------------------------------------
' I/O Definitions
' ------------------------------------------------------------------------------
LEDs VAR OutL ' LED outputs
PotPin CON 15 ' pot wiper connects to pin 15
' ------------------------------------------------------------------------------
' Constants
' ------------------------------------------------------------------------------
DotGraf CON 0 ' define graph types
BarGraf CON 1
GraphMode CON BarGraf ' define current graph mode
On CON 1
Off CON 0
Scale CON $005F ' scale value to make 0 .. 255
' Scale CON $0028 ' scale for BS2sx
' Scale CON $0027 ' sclae for BS2p
' ------------------------------------------------------------------------------
' Variables
' ------------------------------------------------------------------------------
rawValue VAR Word ' raw value from pot
grafValue VAR Byte ' graph value
bits VAR Byte ' highest lighted bit
newBar VAR Byte ' workspace for bar graph
' ------------------------------------------------------------------------------
' Initialization
' ------------------------------------------------------------------------------
Initialize:
DirL = %11111111 ' make low pints outputs
' ------------------------------------------------------------------------------
' Program Code
' ------------------------------------------------------------------------------
Main:
HIGH PotPin ' discharge cap
PAUSE 1 ' for 1 millisecond
RCTIME PotPin, 1, rawValue ' read the Pot
grafValue = rawValue */ Scale ' scale grafVal (0 - 255)
GOSUB Show_Graph ' show it
PAUSE 50
GOTO Main ' do it again
END
' ------------------------------------------------------------------------------
' Subroutines
' ------------------------------------------------------------------------------
Show_Graph:
IF (GraphMode = BarGraf) THEN Show_Bar ' jump to graph mode code
Show_Dot:
LEDs = DCD (grafValue / 32) ' show dot value
RETURN
Show_Bar:
bits = DCD (grafValue / 32) ' get highest bit
newBar = 0
Build_Bar:
IF (bits = 0) THEN Bar_Done ' all bar LEDs lit?
newBar = newBar << 1 ' no - shift left
newBar.Bit0 = On ' light low end
bits = bits >> 1 ' mark bit lit
GOTO Build_Bar ' continue
Bar_Done:
LEDs = newBar ' output new level
RETURN

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -