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

📄 getrc.bas

📁 82 sample programs written in BASCOM-8051 for 8051 developement
💻 BAS
字号:
'-----------------------------------------------------------------------
'                            GETRC.BAS
'  Retrieve resistor value
'  Connect 10KOhm variable resistor from +5V to P1.7 for this example
'  Connect 10nF capacitor from P1.7 to ground
'  The GETRC(pin) function measures the time needed to charge the capacitor
'-----------------------------------------------------------------------
Config Timer0 = Timer , Gate = Internal , Mode = 1       'the GETRC() functions needs timer 0
Config Getrc = 10                                             '10mS wait for charging the capacitor. This is the default so for 10 the CONFIG is not needed
$baud = 9600                              'just my settings
$crystal = 11059200
Dim W As Word                             'allocate space for variable

Do                                        'forever
  W = Getrc(p1.7)                         'get RC value
  Print W                                 'print it
  Wait 1                                  'wait a moment
Loop


'return values for cap=10nF .The resistor values where measured with a DVM
'             250 for 10K9
'             198 for  9K02
'             182 for  8K04
'             166 for  7K
'             154 for  6K02
'             138 for  5K04
'             122 for  4K04
'             106 for  3K06
'              86 for  2K16
'              54 for  1K00
'              22 for   198 ohm
'              18 for   150 ohm
'              10 for   104 ohm
'               6 for     1 ohm (minimum)

'As you can see there is a reasonable linearity
'So you can do some math to get the resistor value
'But the function is intended to serve as a rough indication for resistor values
'You can also change the capacitor to get larger values.
'With 10nF, the return value fits into a byte

⌨️ 快捷键说明

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