忍不住,有把车门改为及其变态的形式

弊人老了,汽车钥匙也懒得带着,麻烦s了。搞了一个汽车电码开门锁的功能,和中控锁连起来使用,效果很佳,很省事。

输对了密码大门打开。输错了密码就不与理会。车子外面只暴露一个隐蔽的防水开关当做输密码电件使用,下一步要改为红外感应的,连电键也省了。


$regfile = "2313DEF.dat"

$crystal = 1000000 ' 定义单片机时钟周期是1000000Hz
Config Watchdog = 2048 '看门狗
Start Watchdog '启动看门狗

Config Portb = Input
Config Portd = Output
Dim A As Integer
Dim Count As Integer
Dim Count_key As Integer
Dim Key As Long

Portd.5 = 1 '指示灯随着看门狗闪烁
Waitms 30
Portd.5 = 0
Key = 0
Reset Watchdog '喂狗
Loop2:
If Pinb.0 = 1 Then Reset Watchdog
Gosub Getkey '去读键盘
If Count_key = 2 Then '键盘得到 划
Key = Key * 10 '密码左移一位
Key = Key + 1 '密码赴值
Reset Watchdog
End If
If Count_key = 1 Then '键盘得到 点
Key = Key * 10
Reset Watchdog
End If

If Key = 11110000 Then '锁车门的电码
Portd.2 = 1 '启动电磁阀开门
Waitms 400 '延时
Portd.2 = 0
Waitms 400
Portd.2 = 1 '保险起见再锁一次
Waitms 400
Portd.2 = 0
Key = 0
End If


If Key = 11110001 Then '开门的电码
Portd.3 = 1 '启动电磁阀开门
Waitms 400 '延时
Portd.3 = 0
Waitms 400
Portd.3 = 1 '保险起见再开一次
Waitms 400
Portd.3 = 0
Key = 0
End If


Goto Loop2

End




Getkey:
Count = 0
Count_key = 0
Portd.6 = 0

Do
If Pinb.0 = 1 Then Reset Watchdog
Count = Count + 1
Waitms 1
Loop Until Pinb.0 = 0

If Count > 30 Then '如果按建时间超过30小于100算点
If Count < 100 Then
Reset Watchdog
Rem Portd.6 = 1
Rem Waitms 100
Rem Portd.6 = 0
Count_key = 1
Reset Watchdog
End If
End If

If Count > 200 Then '按建时间超过200算划
Reset Watchdog
Rem Portd.6 = 1
Rem Waitms 100
Rem Portd.6 = 0
Count_key = 2
Reset Watchdog
End If

Return