Translate

Membuat Simulasi Traffic Light Mikrokontroller Tampilan 7-segment Display

Membuat Simulasi Traffic Light Mikrokontroller Tampilan 7-segment Display


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi untuk simulasi traffic light dengan penampil 7-segment, jadi pada alat ini terdapat 9 buah 7-segment yang akan menampilkan tiap-tiap angka secara count-down atau hitungan mundur. tidak hanya itu alat ini dilengkapi 3 buah led untuk traffic light yaitu merah, kuning dan hijau. kemudian 2 led lagi untuk penyebrang jalan yaitu merah dan hijau. dua angka diatas diperuntukkan bagi kendaraan, kemudian satu digit dibawah diperuntukkan bagi pejalan kaki yang ingin menyebrang. alat ini menggunakan mikrokontroller ATMega16 dan IC decoder 74138 sebanyak 2 buah. untuk skema dan program berikut adalah penjelasannya.




a. Minimum System ATMega16





b. 7-segment dan LED 







c. IC 74138 Decoder






d. Program Bascom AVR

$regfile = "m16def.dat"
$crystal = 12000000

Ddra.0 = 1
Ddra.1 = 1
Ddra.2 = 1
Ddra.3 = 1
Ddra.4 = 1

Ddrb.0 = 1
Ddrb.1 = 1
Ddrb.2 = 1
Ddrb.3 = 1
Ddrb.4 = 1

Ddrb.5 = 1
Ddrb.6 = 1
Ddrb.7 = 1



Ddrd.0 = 1
Ddrd.1 = 1
Ddrd.2 = 1
Ddrd.3 = 1
Ddrd.4 = 1

Ddrd.5 = 1
Ddrd.6 = 1
Ddrd.7 = 1



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

Dim Datas As Byte
Dim Count As Integer

Dim X1 As Integer
Dim X2 As Integer
Dim X3 As Integer
X1 = 0
X2 = 3
X3 = 1


Dim Y1 As Integer
Dim Y2 As Integer
Dim Y3 As Integer
Y1 = 0
Y2 = 7
Y3 = 5


Dim Z1 As Integer
Dim Z2 As Integer
Dim Z3 As Integer
Z1 = 1
Z2 = 1
Z3 = 9


Dim X As Integer
Dim Y As Integer
Dim Z As Integer
X = 1
Y = 1
Z = 1

Dim Kondisi As Integer
Kondisi = 1

Porta = &B00111111
Portb = &B00111111
Portd = &B00111111

Portc = &B11111111
Waitms 2



Do


Do


If X1 = 1 And X2 >= 0 Then
Porta = &B00001110                                          'merah
Elseif X1 = 0 And X2 > 3 Then
Porta = &B00001110
Elseif X1 = 0 And X2 <= 3 Then
Porta = &B00011001                                          'hijau
End If

If X1 = 0 And X2 = 0 Then
Porta.4 = 1
Porta.3 = 0
Porta.2 = 1
End If

If Y1 = 1 And Y2 >= 0 Then
Portb = &B00001110                                          'merah
Elseif Y1 = 0 And Y2 > 3 Then
Portb = &B00001110
Elseif Y1 = 0 And Y2 <= 3 Then
Portb = &B00010011                                          'hijau
End If

If Y1 = 0 And Y2 = 0 Then
Portb.0 = 1
Portb.1 = 0
Portb.2 = 1
End If


If Z1 = 1 And Z2 >= 0 Then
Portd = &B00001110                                          'merah
Elseif Z1 = 0 And Z2 > 3 Then
Portd = &B00001110
Elseif Z1 = 0 And Z2 <= 3 Then
Portd = &B00010011                                          'hijau
End If

If Z1 = 0 And Z2 = 0 Then
Portd.0 = 1
Portd.1 = 0
Portd.2 = 1
End If


Datas = Lookup(x1 , Data7seg)
Portc = Datas

Portd.5 = 0
Portd.6 = 0
Portd.7 = 0
Waitms 2

Datas = Lookup(x2 , Data7seg)
Portc = Datas

Portd.5 = 1
Portd.6 = 0
Portd.7 = 0
Waitms 2

Datas = Lookup(x3 , Data7seg)
Portc = Datas

Portd.5 = 0
Portd.6 = 1
Portd.7 = 0
Waitms 2

Datas = Lookup(y1 , Data7seg)
Portc = Datas

Portd.5 = 1
Portd.6 = 1
Portd.7 = 0
Waitms 2

Datas = Lookup(y2 , Data7seg)
Portc = Datas

Portd.5 = 0
Portd.6 = 0
Portd.7 = 1
Waitms 2

Datas = Lookup(y3 , Data7seg)
Portc = Datas

Portd.5 = 1
Portd.6 = 0
Portd.7 = 1
Waitms 2


Datas = Lookup(z1 , Data7seg)
Portc = Datas

Portb.5 = 0
Portb.6 = 0
Portb.7 = 0
Waitms 2


Datas = Lookup(z2 , Data7seg)
Portc = Datas

Portb.5 = 1
Portb.6 = 0
Portb.7 = 0
Waitms 2

Datas = Lookup(z3 , Data7seg)
Portc = Datas

Portb.5 = 0
Portb.6 = 1
Portb.7 = 0
Waitms 2


Incr Count


Loop Until Count > 100



Decr X2
Decr Y2
Decr Z2

Decr X3
Decr Y3
Decr Z3


If X3 < 0 Then
X3 = 0
End If

If Y3 < 0 Then
Y3 = 0
End If

If Z3 < 0 Then
Z3 = 0
End If


If X1 = 1 And X2 >= 0 Then
Porta = &B00001110                                          'merah
Elseif X1 = 0 And X2 > 3 Then
Porta = &B00001110
Elseif X1 = 0 And X2 <= 3 Then
Porta = &B00011001                                          'hijau
End If


If Y1 = 1 And Y2 >= 0 Then
Portb = &B00001110                                          'merah
Elseif Y1 = 0 And Y2 > 3 Then
Portb = &B00001110
Elseif Y1 = 0 And Y2 <= 3 Then
Portb = &B00010011                                          'hijau
End If


If Z1 = 1 And Z2 >= 0 Then
Portd = &B00001110                                          'merah
Elseif Z1 = 0 And Z2 > 3 Then
Portd = &B00001110
Elseif Z1 = 0 And Z2 <= 3 Then
Portd = &B00010011                                          'hijau
End If




'==================================================

If X2 < 0 And X = 1 And X1 <> 0 Then
X1 = 0
X2 = 9
X = 2
End If

If X2 < 0 And X = 1 And X1 = 0 Then
X1 = 1
X2 = 1
X3 = 9
X = 1
End If

If X2 < 0 And X = 2 Then
X1 = 1
X2 = 1
X3 = 9
X = 1
End If


'====================================================

If Y2 < 0 And Y = 1 And Y1 <> 0 Then
Y1 = 0
Y2 = 9
Y = 2
End If


If Y2 < 0 And Y = 1 And Y1 = 0 Then
Y1 = 1
Y2 = 1
Y3 = 9
Y = 1
End If


If Y2 < 0 And Y = 2 Then
Y1 = 1
Y2 = 1
Y3 = 5
Y = 1
End If


'====================================================

If Z2 < 0 And Z = 1 And Z <> 0 Then
Z1 = 0
Z2 = 9
Z = 2
End If


If Z2 < 0 And Z = 1 And Z1 = 0 Then
Z1 = 1
Z2 = 1
Z3 = 9
Z = 1
End If


If Z2 < 0 And Z = 2 Then
Z1 = 1
Z2 = 1
Z3 = 9
Z = 1
End If


Count = 0

Loop


Data7seg:
Data &B11000000                                             '0
Data &B11111001                                             '1
Data &B10100100                                             '2
Data &B10110000                                             '3
Data &B10011001                                             '4
Data &B10010010                                             '5
Data &B10000010                                             '6
Data &B11111000                                             '7
Data &B10000000                                             '8
Data &B10010000                                             '9






e. VIDEO HASILNYA










No comments:

Post a Comment