2. Counter display 7 segment
3. Led merah, kuning dan hijau
Controler pada trafic ini menggunakan atmega16
keterangan
garis hijau = lama nyala lampu hijau
garis kuning = lama nyala lampu kuning
garis merah = lama nyala lampu merah
Souce Code :
$regfile = "m16def.dat" $crystal = 12000000 Config Portb.0 = Output Config Portb.1 = Output Config Portb.2 = Output Config Portb.5 = Output Config Portb.6 = Output Config Portb.7 = Output Config Portd.0 = Output Config Portd.1 = Output Config Portd.2 = Output Config Portd.5 = Output Config Portd.6 = Output Config Portd.7 = Output Config Porta.0 = Output Config Porta.1 = Output Config Porta.2 = Output Config Porta.5 = Output Config Porta.6 = Output Config Porta.7 = Output Config Portc.0 = Output Config Portc.1 = Output Config Portc.2 = Output Config Portc.5 = Output Config Portc.6 = Output Config Portc.7 = Output 'trafic 1 Data1 Alias Portb.0 Clock1 Alias Portb.1 Oe1 Alias Portb.2 Merah1 Alias Portb.5 Kuning1 Alias Portb.6 Hijau1 Alias Portb.7 'trafic 2 Data2 Alias Portd.7 Clock2 Alias Portd.6 Oe2 Alias Portd.5 Merah2 Alias Portd.0 Kuning2 Alias Portd.1 Hijau2 Alias Portd.2 'trafic3 Data3 Alias Porta.2 Clock3 Alias Porta.1 Oe3 Alias Porta.0 Merah3 Alias Porta.7 Kuning3 Alias Porta.6 Hijau3 Alias Porta.5 'trafic4 Data4 Alias Portc.0 Clock4 Alias Portc.1 Oe4 Alias Portc.2 Merah4 Alias Portc.5 Kuning4 Alias Portc.6 Hijau4 Alias Portc.7 Dim Kodesat1 As Byte , Npul1 As Integer , Nsat1 As Integer , Kodepul1 As Byte Dim Sat1 As Byte , Pul1 As Byte , Flaghijau1 As Bit , Flagkuning1 As Bit , Flag1put As Bit Dim A1 As Bit , B1 As Bit Dim Kodesat2 As Byte , Npul2 As Integer , Nsat2 As Integer , Kodepul2 As Byte Dim Sat2 As Byte , Pul2 As Byte , Flaghijau2 As Bit , Flagkuning2 As Bit Dim A2 As Bit , B2 As Bit Dim Kodesat3 As Byte , Npul3 As Integer , Nsat3 As Integer , Kodepul3 As Byte Dim Sat3 As Byte , Pul3 As Byte , Flaghijau3 As Bit , Flagkuning3 As Bit Dim A3 As Bit , B3 As Bit Dim Kodesat4 As Byte , Npul4 As Integer , Nsat4 As Integer , Kodepul4 As Byte Dim Sat4 As Byte , Pul4 As Byte , Flaghijau4 As Bit , Flagkuning4 As Bit Dim A4 As Bit , B4 As Bit Mulai: A1 = 0 B1 = 0 A2 = 0 B2 = 0 A3 = 0 B3 = 0 A4 = 0 B4 = 0 Flaghijau1 = 0 Flagkuning1 = 0 Flaghijau2 = 0 Flagkuning2 = 0 Flaghijau3 = 0 Flagkuning3 = 0 Flaghijau4 = 0 Flagkuning4 = 0 Sat1 = 8 Pul1 = 0 Sat2 = 1 Pul2 = 1 Sat3 = 3 Pul3 = 2 Sat4 = 5 Pul4 = 3 Do Gosub Tampil1 Gosub Tampil2 Gosub Tampil3 Gosub Tampil4 Gosub Trafic1 Gosub Trafic2 Gosub Trafic3 Gosub Trafic4 Decr Sat1 Decr Sat2 Decr Sat3 Decr Sat4 Loop Trafic1: 'lampu If A1 = 0 And B1 = 0 Then Merah1 = 0 Kuning1 = 0 Hijau1 = 1 End If If A1 = 0 And B1 = 1 Then Merah1 = 1 Kuning1 = 0 Hijau1 = 0 End If If A1 = 1 And B1 = 0 Then Merah1 = 0 Kuning1 = 1 Hijau1 = 0 End If 'counter If Sat1 = 0 And Pul1 = 0 And Flaghijau1 = 0 And Flagkuning1 = 0 Then Sat1 = 3 Pul1 = 0 Flaghijau1 = 1 A1 = 1 B1 = 0 End If If Sat1 = 0 And Pul1 = 0 And Flaghijau1 = 1 And Flagkuning1 = 0 Then Sat1 = 6 Pul1 = 3 Flagkuning1 = 1 A1 = 0 B1 = 1 End If If Sat1 = 0 And Pul1 = 0 And Flaghijau1 = 1 And Flagkuning1 = 1 Then A1 = 0 B1 = 0 Flaghijau1 = 0 Flagkuning1 = 0 End If If Sat1 = 0 And Pul1 = 3 Then Decr Pul1 Sat1 = 10 End If If Sat1 = 0 And Pul1 = 2 Then Decr Pul1 Sat1 = 10 End If If Sat1 = 0 And Pul1 = 1 Then Decr Pul1 Sat1 = 10 End If Return Tampil1: Reset Oe1 Kodesat1 = Lookup(sat1 , Kode) Kodepul1 = Lookup(pul1 , Kode) Shiftout Data1 , Clock1 , Kodesat1 , 1 Shiftout Data1 , Clock1 , Kodepul1 , 1 Waitms 200 Set Oe1 Return Trafic2: 'lampu If A2 = 0 And B2 = 1 Then Merah2 = 0 Kuning2 = 0 Hijau2 = 1 End If If A2 = 1 And B2 = 0 Then Merah2 = 0 Kuning2 = 1 Hijau2 = 0 End If If A2 = 0 And B2 = 0 Then Merah2 = 1 Kuning2 = 0 Hijau2 = 0 End If 'counter If Sat2 = 0 And Pul2 = 0 And Flaghijau2 = 0 And Flagkuning2 = 0 Then Sat2 = 9 Pul2 = 0 Flaghijau2 = 1 A2 = 0 B2 = 1 End If If Sat2 = 0 And Pul2 = 0 And Flaghijau2 = 1 Then Sat2 = 3 Pul2 = 0 Flagkuning2 = 1 Flaghijau2 = 0 A2 = 1 B2 = 0 End If If Sat2 = 0 And Pul2 = 0 And Flagkuning2 = 1 Then Sat2 = 6 Pul2 = 3 Flagkuning2 = 0 Flaghijau2 = 1 A2 = 0 B2 = 0 End If If Sat2 = 0 And Pul2 = 3 Then Decr Pul2 Sat2 = 10 End If If Sat2 = 0 And Pul2 = 2 Then Decr Pul2 Sat2 = 10 End If If Sat2 = 0 And Pul2 = 1 Then Decr Pul2 Sat2 = 10 End If Return Tampil2: Reset Oe2 Kodesat2 = Lookup(sat2 , Kode) Kodepul2 = Lookup(pul2 , Kode) Shiftout Data2 , Clock2 , Kodesat2 , 1 Shiftout Data2 , Clock2 , Kodepul2 , 1 Waitms 200 Set Oe2 Return Trafic3: 'lampu If A3 = 0 And B3 = 1 Then Merah3 = 0 Kuning3 = 0 Hijau3 = 1 End If If A3 = 1 And B3 = 0 Then Merah3 = 0 Kuning3 = 1 Hijau3 = 0 End If If A3 = 0 And B3 = 0 Then Merah3 = 1 Kuning3 = 0 Hijau3 = 0 End If 'counter If Sat3 = 0 And Pul3 = 0 And Flaghijau3 = 0 And Flagkuning3 = 0 Then Sat3 = 9 Pul3 = 0 Flaghijau3 = 1 A3 = 0 B3 = 1 End If If Sat3 = 0 And Pul3 = 0 And Flaghijau3 = 1 And Flagkuning3 = 0 Then Sat3 = 3 Pul3 = 0 Flaghijau3 = 0 Flagkuning3 = 1 A3 = 1 B3 = 0 End If If Sat3 = 0 And Pul3 = 0 And Flagkuning3 = 1 And Flagkuning3 = 1 Then Sat3 = 6 Pul3 = 3 Flagkuning3 = 0 A3 = 0 B3 = 0 End If If Sat3 = 0 And Pul3 = 3 Then Decr Pul3 Sat3 = 10 End If If Sat3 = 0 And Pul3 = 2 Then Decr Pul3 Sat3 = 10 End If If Sat3 = 0 And Pul3 = 1 Then Decr Pul3 Sat3 = 10 End If Return Tampil3: Reset Oe3 Kodesat3 = Lookup(sat3 , Kode) Kodepul3 = Lookup(pul3 , Kode) Shiftout Data3 , Clock3 , Kodesat3 , 1 Shiftout Data3 , Clock3 , Kodepul3 , 1 Waitms 200 Set Oe3 Return Trafic4: 'lampu 'If Flag1put = 1 Then ' Goto Mulai 'End If If A4 = 0 And B4 = 1 Then Merah4 = 0 Kuning4 = 0 Hijau4 = 1 End If If A4 = 1 And B4 = 0 Then Merah4 = 0 Kuning4 = 1 Hijau4 = 0 End If If A4 = 0 And B4 = 0 Then Merah4 = 1 Kuning4 = 0 Hijau4 = 0 End If 'counter If Sat4 = 0 And Pul4 = 0 And Flaghijau4 = 0 And Flagkuning4 = 0 Then Sat4 = 9 Pul4 = 0 Flaghijau4 = 1 A4 = 0 B4 = 1 End If If Sat4 = 0 And Pul4 = 0 And Flaghijau4 = 1 And Flagkuning4 = 0 Then Sat4 = 3 Pul4 = 0 Flagkuning4 = 1 A4 = 1 B4 = 0 End If If Sat4 = 0 And Pul4 = 0 And Flaghijau4 = 1 And Flagkuning4 = 1 Then 'Flag1put = 1 Goto Mulai End If If Sat4 = 0 And Pul4 = 3 Then Decr Pul4 Sat4 = 10 End If If Sat4 = 0 And Pul4 = 2 Then Decr Pul4 Sat4 = 10 End If If Sat4 = 0 And Pul4 = 1 Then Decr Pul4 Sat4 = 10 End If Return Tampil4: Reset Oe4 Kodesat4 = Lookup(sat4 , Kode) Kodepul4 = Lookup(pul4 , Kode) Shiftout Data4 , Clock4 , Kodesat4 , 1 Shiftout Data4 , Clock4 , Kodepul4 , 1 Waitms 200 Set Oe4 Return Kode: Data &HC0 , &HF9 , &HA4 , &HB0 , &H99 , &H92 , &H82 , &HF8 , &H80 , &H90