ex21 - analogin.bs2

来自「proteus得一些经典例子」· BS2 代码 · 共 43 行

BS2
43
字号
' {$STAMP BS2}
' ==============================================================================
'
' File...... Ex21 - AnalogIn.BS2
' Purpose... Analog input using PULSIN
' Author.... Parallax
' E-mail.... stamptech@parallaxinc.com
' Started...
' Updated... 01 MAY 2002
'
'
' ==============================================================================
' ------------------------------------------------------------------------------
' Program Description
' ------------------------------------------------------------------------------
' This program "reads" an analog value by using that component to control the
' output frequency of a 555-based oscillator. PULSIN is used to measure the
' high portion of the signal as it is controlled by the varialbe resistance.
' ------------------------------------------------------------------------------
' I/O Definitions
' ------------------------------------------------------------------------------
PulseInput CON 0
' ------------------------------------------------------------------------------
' Constants
' ------------------------------------------------------------------------------
P75 CON $00C0 ' 0.75
P50 CON $0080 ' 0.50
P25 CON $0040 ' 0.25
' ------------------------------------------------------------------------------
' Variables
' ------------------------------------------------------------------------------
rValue VAR Word ' raw value
sValue VAR Word ' smoothed value
' ------------------------------------------------------------------------------
' Program Code
' ------------------------------------------------------------------------------
Main:
PULSIN PulseInput, 1, rValue ' get high portion of input
sValue = (rValue */ P25) + (sValue */ P75)
DEBUG Home
DEBUG "Raw value... ", DEC rValue, " ", CR
DEBUG "Filtered.... ", DEC sValue, " ", CR
GOTO Main ' do it again

⌨️ 快捷键说明

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