Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana membuat sebuah ETU (Engine Telegraph Unit) yang biasanya difungsikan pada kapal untuk memerintahkan kepada abk kapal untuk melakukan sesuatu yang jaraknya jauh atau beda ruangan, jadi dari control room dapat memerintahkan abk yang berada pada posisinya untuk mengerjakan sesuatu sesuai dengan perintah pada ETU. disini yang dipakai hanya 3 buah push button, 3 buah led dan satu buzzer pada master, kemudian pada slave menggunakan 3 buah led, 2 push button dan satu buzzer. untuk lebih jelasnya berikut adalah komponen dan programnya.
a. Minimum Sistem ATMega
b. LED
c. Buzzer
d. Push Button
e. Program Bascom AVR Master
$regfile = "m16def.dat"
$crystal = 11059200
$baud = 9600
Ddra.0 = 1
Ddra.1 = 1
Ddra.2 = 1
Ddrc.4 = 1
Ddrb.0 = 0
Ddrb.1 = 0
Ddrb.2 = 0
On Urxc Getchar
Dim Inchar As Word
Dim Tanda As Integer
Dim X As Integer
Dim Y As Integer
Dim Aa As Byte
Dim Bb As Byte
Dim Cc As Byte
Dim Dd As Byte
Aa = 1
Bb = 2
Cc = 3
Dd = 4
Enable Interrupts
Enable Urxc
Tanda = 0
X = 0
Y = 0
Goto Blinking
Blinking:
Do
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
Loop Until Tanda = 1
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Utama:
Do
If Pinb.0 = 0 Then
Waitms 200
Printbin Aa
X = 1
Y = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If Pinb.1 = 0 Then
Waitms 200
Printbin Bb
X = 2
Y = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If Pinb.2 = 0 Then
Waitms 200
Printbin Cc
X = 3
Y = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If X = 1 Then
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If X = 2 Then
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If X = 3 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If Y = 1 Then
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If Y = 2 Then
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
Portc.4 = 0
End If
If Y = 3 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
Portc.4 = 0
End If
Waitms 200
Loop
Getchar:
Inchar = Waitkey()
Select Case Inchar
Case 4:
Tanda = 1
Case 1:
X = 0
Y = 1
Case 2:
X = 0
Y = 2
Case 3:
X = 0
Y = 3
End Select
Return
End
$crystal = 11059200
$baud = 9600
Ddra.0 = 1
Ddra.1 = 1
Ddra.2 = 1
Ddrc.4 = 1
Ddrb.0 = 0
Ddrb.1 = 0
Ddrb.2 = 0
On Urxc Getchar
Dim Inchar As Word
Dim Tanda As Integer
Dim X As Integer
Dim Y As Integer
Dim Aa As Byte
Dim Bb As Byte
Dim Cc As Byte
Dim Dd As Byte
Aa = 1
Bb = 2
Cc = 3
Dd = 4
Enable Interrupts
Enable Urxc
Tanda = 0
X = 0
Y = 0
Goto Blinking
Blinking:
Do
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
Loop Until Tanda = 1
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Utama:
Do
If Pinb.0 = 0 Then
Waitms 200
Printbin Aa
X = 1
Y = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If Pinb.1 = 0 Then
Waitms 200
Printbin Bb
X = 2
Y = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If Pinb.2 = 0 Then
Waitms 200
Printbin Cc
X = 3
Y = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If X = 1 Then
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If X = 2 Then
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If X = 3 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If Y = 1 Then
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If Y = 2 Then
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
Portc.4 = 0
End If
If Y = 3 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
Portc.4 = 0
End If
Waitms 200
Loop
Getchar:
Inchar = Waitkey()
Select Case Inchar
Case 4:
Tanda = 1
Case 1:
X = 0
Y = 1
Case 2:
X = 0
Y = 2
Case 3:
X = 0
Y = 3
End Select
Return
End
f. Program Bascom AVR Slave
$regfile = "m16def.dat"
$crystal = 11059200
$baud = 9600
Ddra.0 = 1
Ddra.1 = 1
Ddra.2 = 1
Ddrc.4 = 1
'reset
Ddrb.0 = 0
'ack
Ddrb.1 = 0
On Urxc Getchar
Dim Inchar As Word
Dim Tanda As Integer
Enable Interrupts
Enable Urxc
Cls
Cursor Off
Dim Z As Integer
Dim N As Integer
Dim Aa As Byte
Dim Bb As Byte
Dim Cc As Byte
Dim Dd As Byte
Aa = 1
Bb = 2
Cc = 3
Dd = 4
Z = 0
N = 0
Tanda = 0
Goto Blinking
Blinking:
Do
'reset
If Pinb.0 = 0 Then
Waitms 200
Printbin Dd
Tanda = 1
End If
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
Loop Until Tanda = 1
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Utama:
Do
'ack
If Pinb.1 = 0 And Z = 1 Then
Waitms 200
Z = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Printbin Aa
N = 1
End If
'ack
If Pinb.1 = 0 And Z = 2 Then
Waitms 200
Z = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Printbin Bb
N = 2
End If
'ack
If Pinb.1 = 0 And Z = 3 Then
Waitms 200
Z = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Printbin Cc
N = 3
End If
If Z = 0 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If N = 1 Then
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If N = 2 Then
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
Portc.4 = 0
End If
If N = 3 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
Portc.4 = 0
End If
If Z = 1 Then
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If Z = 2 Then
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If Z = 3 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
Loop
Getchar:
Inchar = Waitkey()
Select Case Inchar
Case 1:
Z = 1
Case 2:
Z = 2
Case 3:
Z = 3
End Select
Return
End
$crystal = 11059200
$baud = 9600
Ddra.0 = 1
Ddra.1 = 1
Ddra.2 = 1
Ddrc.4 = 1
'reset
Ddrb.0 = 0
'ack
Ddrb.1 = 0
On Urxc Getchar
Dim Inchar As Word
Dim Tanda As Integer
Enable Interrupts
Enable Urxc
Cls
Cursor Off
Dim Z As Integer
Dim N As Integer
Dim Aa As Byte
Dim Bb As Byte
Dim Cc As Byte
Dim Dd As Byte
Aa = 1
Bb = 2
Cc = 3
Dd = 4
Z = 0
N = 0
Tanda = 0
Goto Blinking
Blinking:
Do
'reset
If Pinb.0 = 0 Then
Waitms 200
Printbin Dd
Tanda = 1
End If
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
Loop Until Tanda = 1
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Utama:
Do
'ack
If Pinb.1 = 0 And Z = 1 Then
Waitms 200
Z = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Printbin Aa
N = 1
End If
'ack
If Pinb.1 = 0 And Z = 2 Then
Waitms 200
Z = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Printbin Bb
N = 2
End If
'ack
If Pinb.1 = 0 And Z = 3 Then
Waitms 200
Z = 0
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Printbin Cc
N = 3
End If
If Z = 0 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If N = 1 Then
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
End If
If N = 2 Then
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
Portc.4 = 0
End If
If N = 3 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
Portc.4 = 0
End If
If Z = 1 Then
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If Z = 2 Then
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
If Z = 3 Then
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
Portc.4 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Portc.4 = 0
Waitms 500
End If
Loop
Getchar:
Inchar = Waitkey()
Select Case Inchar
Case 1:
Z = 1
Case 2:
Z = 2
Case 3:
Z = 3
End Select
Return
End
g. VIDEO HASILNYA
No comments:
Post a Comment