Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk mengukur jarak atau tinggi badan seseorang dengan menggunakan sensor jarak PING))) dan output suara ISD1420. jadi alat ini dilengkapi dengan dua buah interface pemberitahuan, yaitu pada tampilan lcd dan output suara. sehinga jika orang yang tuna netra dia akan mengetahui berapa tinggi badannya tanpa harus melihat di layar LCD. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Minimum System ATMega32 + Skema
b. Modul ISD1420
c. Sensor Jarak PING)))
d. LCD 16x2
e. Program Bascom AVR
$regfile = "m32def.dat"
$crystal = 16000000
Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2
Config Timer1 = Timer , Prescale = 64
Declare Sub Regratusan
Declare Sub Regpuluhan
Declare Sub Regsatuan
Declare Sub Belakang
Sigout Alias Portb.0
Sigin Alias Pinb.0
Dirsig Alias Ddrb.0
Dim Data_timer As Integer
Dim Tinggi As Integer
Dim Ratusan As Integer
Dim Puluhan As Integer
Dim Satuan As Integer
Dim Temp As Integer
Dim A As Integer
Dim X As Integer
A = 0
X = 350
Ddrb.3 = 1
Ddrb.1 = 0
Portb.1 = 1
Ddra = &B11111111
Cls
Cursor Off
Do
Gosub Ambil_datatimer
Data_timer = Data_timer / 10
Tinggi = 200 - Data_timer
If Tinggi > 200 Then
Tinggi = 200
End If
If Tinggi < 1 Then
Tinggi = 0
End If
Locate 1 , 1
Lcd "Tinggi = " ; Tinggi ; " cm "
Waitms 100
Temp = Tinggi
'Mencari angka Ratusan
Ratusan = Temp / 100
'Mencari angka Puluhan
Temp = Temp Mod 100
Puluhan = Temp / 10
'Mencari angka Satuan
Satuan = Temp Mod 10
'Locate 2 , 1
'Lcd Ratusan
'Locate 2 , 4
'Lcd Puluhan
'Locate 2 , 7
'Lcd Satuan
If Pinb.1 = 0 Then
Wait 1
Porta = 130
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
If Ratusan = 1 Then
A = 0
Call Regratusan
Elseif Ratusan = 2 Then
A = 160
Call Regratusan
Elseif Ratusan = 3 Then
A = 170
Call Regratusan
Elseif Ratusan = 4 Then
A = 40
Call Regratusan
Elseif Ratusan = 5 Then
A = 50
Call Regratusan
Elseif Ratusan = 6 Then
A = 60
Call Regratusan
Elseif Ratusan = 7 Then
A = 70
Call Regratusan
Elseif Ratusan = 8 Then
A = 80
Call Regratusan
Elseif Ratusan = 9 Then
A = 90
Call Regratusan
End If
If Puluhan = 1 And Satuan = 1 Then
Porta = 0
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
Porta = 120
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
Elseif Puluhan = 1 And Satuan = 0 Then
Porta = 0
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
Porta = 110
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
Elseif Puluhan = 2 Then
A = 160
Call Regpuluhan
Elseif Puluhan = 3 Then
A = 170
Call Regpuluhan
Elseif Puluhan = 4 Then
A = 40
Call Regpuluhan
Elseif Puluhan = 5 Then
A = 50
Call Regpuluhan
Elseif Puluhan = 6 Then
A = 60
Call Regpuluhan
Elseif Puluhan = 7 Then
A = 70
Call Regpuluhan
Elseif Puluhan = 8 Then
A = 80
Call Regpuluhan
Elseif Puluhan = 9 Then
A = 90
Call Regpuluhan
End If
If Satuan = 1 And Puluhan <> 1 Then
A = 10
Call Regsatuan
Elseif Satuan = 2 Then
A = 160
Call Regsatuan
Elseif Satuan = 3 Then
A = 170
Call Regsatuan
Elseif Satuan = 4 Then
A = 40
Call Regsatuan
Elseif Satuan = 5 Then
A = 50
Call Regsatuan
Elseif Satuan = 6 Then
A = 60
Call Regsatuan
Elseif Satuan = 7 Then
A = 70
Call Regsatuan
Elseif Satuan = 8 Then
A = 80
Call Regsatuan
Elseif Satuan = 9 Then
A = 90
Call Regsatuan
End If
If Puluhan = 1 And Satuan <> 0 And Satuan <> 1 Then
Porta = 120
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
End If
Porta = 150
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
Waitms 500
End If
Loop
Ambil_datatimer:
Dirsig = 1
Set Sigout
Waitus 10
Reset Sigout
Dirsig = 0
Set Sigout
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
Stop Timer1
Tifr.2 = 1
Data_timer = 0
Exit Do
End If
Loop
Stop Timer1
Return
Sub Regratusan:
Portb.3 = 1
Porta = A
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
Porta = 100
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
End Sub
Return
Sub Regpuluhan:
Porta = A
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
Porta = 110
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
End Sub
Return
Sub Regsatuan:
Porta = A
Portb.3 = 0
Waitms X
Portb.3 = 1
Waitms X
End Sub
Return
f. VIDEO HASILNYA
No comments:
Post a Comment