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

📄 an40.bas

📁 Distance meter for IR
💻 BAS
字号:
 '--------------------------------------
'By ehsan.
'---------------------------------------

''''$regfile = "89c2051.dat"
$regfile = "89s8252.dat"

' the micro controller's include file
$crystal = 6000000
'6 mhz crystal  used

Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = P0.4 , Db5 = P0.5 , Db6 = P0.6 , Db7 = P0.7
Config Lcdpin = Pin , E = P0.3 , Rs = P0.2

' define variables below
Dim Irrecd As Bit
Dim Ircount As Integer

Declare Sub Fn38k6()

Irrecd = 0
Ircount = 0

' another name for port pin p1.0
Irport Alias P1.0
' make all ports 0
P0 = 0
P2 = 0

P1 = 0
P3 = 0
P3.2 = 1
' make port-3.2 int0 high for interrupt to work

' on interrupt - call int0_int fuction
On Int0 Int0_int
Reset Tcon.0
' int enabled... NOT edge triggered
Enable Interrupts


Begin:
Ircount = 0
' show IR xmit mode on port-1
P1.1 = 1
' enable int0
Enable Int0

Call Fn38k6
' send out a beam for 1/10th of a second
' of IR at 38khz freq
' int would have taken place if ir was reflected recd

Disable Int0
' disable  int

' check if int occurred
If Irrecd = 0 Then
   ' no int occured
   P1.1 = 0
   ' flash standby led
   Waitms 100
   ' wait for ( 1/10th of a second)
   Goto Begin
End If

' here int recd
' show ir count..related to distance
Home
Lcd "ircount=" ; Ircount ; "   "

Irrecd = 0
P1.2 = 1
' confirm led ON
Waitms 255
P1.2 = 0
Goto Begin


' =-=-=-=-subroutines below =-=-=-=-=-=-=
Sub Fn38k6()
' function to oscillate IR port pin
' at 38,000 times a sec for 1/10th second
Dim Jj As Byte , Kk As Byte
Jj = 0
While Jj < 10
Incr Jj
Kk = 0
While Kk < 255
Incr Kk
Irport = 1
NOP
Irport = 0
NOP
NOP
Wend
Wend

End Sub
' = - = - = - = - = - = - = - = - = - = - = - = - = -
' The Interrupt Handler For The Int0 Interrupt
Int0_int:
   Irrecd = 1
   Incr Ircount
   ' set a flag , increment a counter and return
Return
' - - - - - - - - - -
' end    788 bytes
' -=-==-=-=-=-=-=-=-=

⌨️ 快捷键说明

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