Translate

Membuat Rangkaian Komunikasi 2 Mikrokontroller Master - Slave Menggunakan INPUT / OUTPUT Bascom AVR

Membuat Rangkaian Komunikasi 2 Mikrokontroller Master - Slave Menggunakan INPUT / OUTPUT Bascom AVR


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara untuk membuat sebuah rangkaian dengan 3 master sebagai transmitter dan 1 buah slave sebagai receiver, jadi data yang akan dikirimkan master ke slave maksimal 8 bit atau 256 data. pada simulasi kali ini hanya menggunakan push button sebagai sensornya pada tiap-tiap master kemudian pada bagian slave akan ditampilkan nilainya di LCD display. untuk skema dan rangkaiannya seperti berikut ini.




a. Skema Proteus





b. Program Bascom AVR

//master1
$regfile = "m128def.dat"
$crystal = 12000000

Config Porte = Output
Porte = 0

Dim X1 As Integer
Dim X2 As Integer
Dim X3 As Integer
Dim X4 As Integer
Dim X5 As Integer
Dim Z1 As Integer
Dim Z2 As Integer
Dim Z3 As Integer
Dim Z4 As Integer


Ddrc.0 = 0
Ddrc.1 = 0
Ddrc.2 = 0
Ddrc.3 = 0
Ddrc.4 = 0

Ddrf.0 = 1
Ddrf.1 = 1
Ddrf.2 = 1
Ddrf.3 = 1
Ddrf.4 = 1
Ddrf.5 = 1
Ddrf.6 = 1
Ddrf.7 = 1


Do

'000
If Pinc.0 = 0 And Pinc.1 = 0 And Pinc.2 = 0 Then
Portf = 1
End If

'100
If Pinc.0 = 1 And Pinc.1 = 0 And Pinc.2 = 0 Then
Portf = 2
End If


'010
If Pinc.0 = 0 And Pinc.1 = 1 And Pinc.2 = 0 Then
Portf = 3
End If


'001
If Pinc.0 = 0 And Pinc.1 = 0 And Pinc.2 = 1 Then
Portf = 4
End If


'110
If Pinc.0 = 1 And Pinc.1 = 1 And Pinc.2 = 0 Then
Portf = 5
End If


'101
If Pinc.0 = 1 And Pinc.1 = 0 And Pinc.2 = 1 Then
Portf = 6
End If


'011
If Pinc.0 = 0 And Pinc.1 = 1 And Pinc.2 = 1 Then
Portf = 7
End If


'111
If Pinc.0 = 1 And Pinc.1 = 1 And Pinc.2 = 1 Then
Portf = 8
End If


Loop





//master2
$regfile = "m128def.dat"
$crystal = 12000000

Config Porte = Output
Porte = 0

Dim X1 As Integer
Dim X2 As Integer
Dim X3 As Integer
Dim X4 As Integer
Dim X5 As Integer
Dim Z1 As Integer
Dim Z2 As Integer
Dim Z3 As Integer
Dim Z4 As Integer


Ddrc.0 = 0
Ddrc.1 = 0
Ddrc.2 = 0
Ddrc.3 = 0
Ddrc.4 = 0

Ddre.0 = 1
Ddre.1 = 1
Ddre.2 = 1
Ddre.3 = 1
Ddre.4 = 1
Ddre.5 = 1
Ddre.6 = 1
Ddre.7 = 1


Do


'000
If Pinc.0 = 0 And Pinc.1 = 0 And Pinc.2 = 0 Then
Porte = 1
End If

'100
If Pinc.0 = 1 And Pinc.1 = 0 And Pinc.2 = 0 Then
Porte = 2
End If


'010
If Pinc.0 = 0 And Pinc.1 = 1 And Pinc.2 = 0 Then
Porte = 3
End If


'001
If Pinc.0 = 0 And Pinc.1 = 0 And Pinc.2 = 1 Then
Porte = 4
End If


'110
If Pinc.0 = 1 And Pinc.1 = 1 And Pinc.2 = 0 Then
Porte = 5
End If


'101
If Pinc.0 = 1 And Pinc.1 = 0 And Pinc.2 = 1 Then
Porte = 6
End If


'011
If Pinc.0 = 0 And Pinc.1 = 1 And Pinc.2 = 1 Then
Porte = 7
End If


'111
If Pinc.0 = 1 And Pinc.1 = 1 And Pinc.2 = 1 Then
Porte = 8
End If

Loop


 


//master3
$regfile = "m128def.dat"
$crystal = 12000000

Config Porte = Output
Porte = 0

Dim X1 As Integer
Dim X2 As Integer
Dim X3 As Integer
Dim X4 As Integer
Dim X5 As Integer
Dim Z1 As Integer
Dim Z2 As Integer
Dim Z3 As Integer
Dim Z4 As Integer


Ddrc.0 = 0
Ddrc.1 = 0
Ddrc.2 = 0
Ddrc.3 = 0
Ddrc.4 = 0

Ddre.0 = 1
Ddre.1 = 1
Ddre.2 = 1
Ddre.3 = 1
Ddre.4 = 1
Ddre.5 = 1
Ddre.6 = 1
Ddre.7 = 1


Do


'000
If Pinc.0 = 0 And Pinc.1 = 0 And Pinc.2 = 0 Then
Porte = 1
End If

'100
If Pinc.0 = 1 And Pinc.1 = 0 And Pinc.2 = 0 Then
Porte = 2
End If


'010
If Pinc.0 = 0 And Pinc.1 = 1 And Pinc.2 = 0 Then
Porte = 3
End If


'001
If Pinc.0 = 0 And Pinc.1 = 0 And Pinc.2 = 1 Then
Porte = 4
End If


'110
If Pinc.0 = 1 And Pinc.1 = 1 And Pinc.2 = 0 Then
Porte = 5
End If


'101
If Pinc.0 = 1 And Pinc.1 = 0 And Pinc.2 = 1 Then
Porte = 6
End If


'011
If Pinc.0 = 0 And Pinc.1 = 1 And Pinc.2 = 1 Then
Porte = 7
End If


'111
If Pinc.0 = 1 And Pinc.1 = 1 And Pinc.2 = 1 Then
Porte = 8
End If


Loop





//slave
$regfile = "m128def.dat"
$crystal = 12000000

Config Lcdpin = Pin , Rs = Portf.0 , E = Portf.1 , Db4 = Portf.2 , Db5 = Portf.3 , Db6 = Portf.4 , Db7 = Portf.5
Config Lcd = 16 * 2

Cls
Cursor Off

Ddra.0 = 0
Ddra.1 = 0
Ddra.2 = 0
Ddra.3 = 0
Ddra.4 = 0
Ddra.5 = 0
Ddra.6 = 0
Ddra.7 = 0

'buzzer
Ddrf.7 = 1

Dim X As Integer
Dim Y As Integer
Dim Z As Integer


Do

X = Pina
Y = Pinb
Z = Pinc

If X = 8 And Y = 8 And Z = 8 Then
Locate 1 , 1
Lcd "ALL GOOD"
Portf.7 = 0
Else
Portf.7 = 1
End If

If X = 1 Then
Locate 1 , 1
Lcd "1 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "2 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "3 OPEN"
Waitms 100
Cls


Elseif X = 2 Then
Locate 1 , 1
Lcd "2 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "3 OPEN"
Waitms 100
Cls

Elseif X = 3 Then
Locate 1 , 1
Lcd "1 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "3 OPEN"
Waitms 100
Cls


Elseif X = 4 Then
Locate 1 , 1
Lcd "1 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "2 OPEN"
Waitms 100
Cls

Elseif X = 5 Then
Locate 1 , 1
Lcd "3 OPEN"
Waitms 100
Cls

Elseif X = 6 Then
Locate 1 , 1
Lcd "2 OPEN"
Waitms 100
Cls

Elseif X = 7 Then
Locate 1 , 1
Lcd "! OPEN"
Waitms 100
Cls

End If



If Y = 1 Then
Locate 1 , 1
Lcd "4 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "5 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "6 OPEN"
Waitms 100
Cls


Elseif Y = 2 Then
Locate 1 , 1
Lcd "5 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "6 OPEN"
Waitms 100
Cls

Elseif Y = 3 Then
Locate 1 , 1
Lcd "4 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "6 OPEN"
Waitms 100
Cls


Elseif Y = 4 Then
Locate 1 , 1
Lcd "4 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "5 OPEN"
Waitms 100
Cls

Elseif Y = 5 Then
Locate 1 , 1
Lcd "6 OPEN"
Waitms 100
Cls

Elseif Y = 6 Then
Locate 1 , 1
Lcd "5 OPEN"
Waitms 100
Cls

Elseif Y = 7 Then
Locate 1 , 1
Lcd "4 OPEN"
Waitms 100
Cls

End If


If Z = 1 Then
Locate 1 , 1
Lcd "7 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "8 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "9 OPEN"
Waitms 100
Cls


Elseif Z = 2 Then
Locate 1 , 1
Lcd "8 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "9 OPEN"
Waitms 100
Cls

Elseif Z = 3 Then
Locate 1 , 1
Lcd "7 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "9 OPEN"
Waitms 100
Cls


Elseif Z = 4 Then
Locate 1 , 1
Lcd "7 OPEN"
Waitms 100
Cls
Locate 1 , 1
Lcd "8 OPEN"
Waitms 100
Cls

Elseif Z = 5 Then
Locate 1 , 1
Lcd "9 OPEN"
Waitms 100
Cls

Elseif Z = 6 Then
Locate 1 , 1
Lcd "8 OPEN"
Waitms 100
Cls

Elseif Z = 7 Then
Locate 1 , 1
Lcd "7 OPEN"
Waitms 100
Cls

End If


'Locate 1 , 1
'Lcd X
'Locate 2 , 1
'Lcd Y
'Locate 3 , 1
'Lcd Z

'Waitms 100
'Cls


Loop



 



c. VIDEO HASILNYA












No comments:

Post a Comment