Selasa, 24 April 2012
Algoritma dan Program Sensor Jarak
$regfile = “m8535.dat”
$crystal = 8000000
Config Lcd = 16 * 2
Config Lcdbus = 4
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.1 , Rs = Portc.0
Config Timer1 = Timer , Prescale = 64
Sigout Alias Portb.0
Sigin Alias Pinb.0
Dirsig Alias Ddrb.0
Dim Data_timer As Integer
‘==================================================
Inisialisasi:
Waitms 100
Initlcd
Locate 1 , 1
Lcd “demo ping”
Wait 1
Cls
Utama:
Gosub Ambil_datatimer
Locate 1 , 1
Lcd Data_timer
Wait 1
Cls
Goto Utama
‘==================================================
Ambil_datatimer:
Dirsig = 1
Set Sigout ‘bankitkan pulsa
Waitus 10
Reset Sigout
‘terima pulsa ubah dulu jadi input
Dirsig = 0 ‘jadi input
Set Sigout ‘pull up internal diaktifkan
Bitwait Sigin , Set
Data_timer = 0
Timer1 = 0
Start Timer1
Do
If Sigin = 0 Then
Data_timer = Timer1
Stop Timer1
Exit Do
End If
If Tifr.2 = 1 Then ‘cek register timer1 overflow?
Stop Timer1
Tifr.2 = 1
Data_timer = 0
Exit Do
End If
Loop
Stop Timer1
Return
Langganan:
Postingan (Atom)