Elektronik Puzzle

gara-gara assembly proyek usaha mandiri ku berantakan dan yang lebih parah lagi harus terlempar ke gelombang tiga..hiks..sSs (kaisan aku)..?//?/

ternyata setelah pake Bascom-AVR proyek ku haya membutuhkan waktu 5 hari... hehe..(sampe gak tidur.. :O)
kalo saja dari dolo pake Bascom-AVR,,, heeemmmm.. (mungkin gak ya...)
nitak kasi screen shot nya ya.... tentang proyek ku.. hi.. jadi malu..:D
programnya juga ya... hehe

$regfile = "m8535.dat" ' specify the used micro
$crystal = 12000000 ' used crystal frequency
$baud = 9600 ' use baud rate

'--------------------------------------------------------------
' Deklarasi konstanta dan varibel
'--------------------------------------------------------------
Dim A As Byte
Dim C As Byte
Dim I As Byte
Dim X0 As Byte
Dim X1 As Byte
Dim X2 As Byte
Dim X3 As Byte
Dim X4 As Byte
Dim X5 As Byte
Dim X6 As Byte
Dim X7 As Byte
Dim X8 As Byte
Dim X9 As Byte
Dim Z1 As Byte
Dim Z2 As Byte
Dim Z3 As Byte
Dim Z4 As Byte
Dim Z5 As Byte
Dim Z6 As Byte
Dim Z7 As Byte
Dim Z8 As Byte
Dim Z9 As Byte
Dim M1 As Byte
Dim M2 As Byte
Dim M3 As Byte
Dim M4 As Byte
Dim M5 As Byte
Dim M6 As Byte
Dim M7 As Byte
Dim M8 As Byte
Dim M9 As Byte
Dim B1 As Byte
Dim B2 As Byte
Dim B3 As Byte
Dim B4 As Byte
Dim B5 As Byte
Dim B6 As Byte
Dim B7 As Byte
Dim B8 As Byte
Dim B9 As Byte
Dim Y As Byte
Const Tombolatas = &B11111101
Const Tombolbawah = &B11111011
Const Tombolkanan = &B11110111
Const Tombolkiri = &B11101111
I = 0
'--------------------------------------------------------------
' konfigurasi fungsi port
'--------------------------------------------------------------
Config Portb = Output
Config Portd.2 = Output
Config Porta = Output
Config Pinc.0 = Input
Config Pinc.1 = Input
Config Pinc.2 = Input
Config Pinc.3 = Input
Config Pinc.4 = Input
Config Pinc.5 = Input
Config Pinc.6 = Input
Config Pinc.7 = Input
Ddrc = 0 ' mode input port c
Portc = &HFF ' pull up port c

'--------------------------------------------------------------
' alias port
'--------------------------------------------------------------
Tombol Alias Pinc
Segmen Alias Portb
Comon Alias Porta

'--------------------------------------------------------------
' main program
'--------------------------------------------------------------
Gosub Tekan
'--------------------------------------------------------------
' sub tekan (menentukan random)
'--------------------------------------------------------------
Tekan:
Do
If Tombol = &B11111110 Then
Waitms 200
I = I + 1
Elseif Tombol = &B11011111 Then
Waitms 200
Gosub Scanrandom
End If
Loop
Return
'--------------------------------------------------------------
' random
'--------------------------------------------------------------

Scanrandom:
Do
If I = 1 Then
Gosub C1
Elseif I = 2 Then
Gosub C2
Elseif I = 3 Then
Gosub C3
Elseif I = 4 Then
Gosub C4
Elseif I = 5 Then
Gosub C5
Elseif I = 6 Then
Gosub C6
Elseif I > 6 Then
Gosub Salah
End If
Gosub Tekan
Loop
Return

C1:
C = 1
Gosub Random
Return

C2:
C = 2
Gosub Random
Return

C3:
C = 4
Gosub Random
Return

C4:
C = 5
Gosub Random
Return

C5:
C = 7
Gosub Random
Return

C6:
C = 8
Gosub Random
Return

Random:
A = 1
X0 = 3

M1 = A * X0
B1 = M1 + C
X1 = B1 Mod 9

M2 = A * X1
B2 = M2 + C
X2 = B2 Mod 9

M3 = A * X2
B3 = M3 + C
X3 = B3 Mod 9

M4 = A * X3
B4 = M4 + C
X4 = B4 Mod 9

M5 = A * X4
B5 = M5 + C
X5 = B5 Mod 9

M6 = A * X5
B6 = M6 + C
X6 = B6 Mod 9

M7 = A * X6
B7 = M7 + C
X7 = B7 Mod 9

M8 = A * X7
B8 = M8 + C
X8 = B8 Mod 9

M9 = A * X8
B9 = M9 + C
X9 = B9 Mod 9

Gosub Simpanrandom
Return

'------------------------------------------------------------------------------
' sub backup data random
'------------------------------------------------------------------------------

Simpanrandom:
Z1 = X1
Z2 = X2
Z3 = X3
Z4 = X4
Z5 = X5
Z6 = X6
Z7 = X7
Z8 = X8
Z9 = X9
Gosub Tampil
Return

'------------------------------------------------------------------------------
' sub tampil seven segment
'------------------------------------------------------------------------------
Tampil:
Do
Segmen = Lookup(z1 , Segment)
Comon = &B00000001
Portd.2 = 0
Waitms 1
Segmen = Lookup(z2 , Segment)
Comon = &B00000010
Portd.2 = 0
Waitms 1
Segmen = Lookup(z3 , Segment)
Comon = &B00000100
Portd.2 = 0
Waitms 1
Segmen = Lookup(z4 , Segment)
Comon = &B00001000
Portd.2 = 0
Waitms 1
Segmen = Lookup(z5 , Segment)
Comon = &B00010000
Portd.2 = 0
Waitms 1
Segmen = Lookup(z6 , Segment)
Comon = &B00100000
Waitms 1
Segmen = Lookup(z7 , Segment)
Comon = &B01000000
Portd.2 = 0
Waitms 1
Segmen = Lookup(z8 , Segment)
Comon = &B10000000
Portd.2 = 0
Waitms 1
Segmen = Lookup(z9 , Segment)
Comon = &B00000000
Portd.2 = 1
Waitms 1
'------------------------------------------------------------------------------
' penekanan tombol
'------------------------------------------------------------------------------
If Z1 = 1 And Z2 = 2 And Z3 = 3 And Z4 = 4 And Z5 = 5 And Z6 = 6 And Z7 = 7 And Z8 = 8 And Z9 = 0 Then
Gosub Selesai
End If

If Tombol = Tombolkiri Then
Waitms 200
Gosub Geserkiri
Elseif Tombol = Tombolkanan Then
Waitms 200
Gosub Geserkanan
Elseif Tombol = Tombolatas Then
Waitms 200
Gosub Geseratas
Elseif Tombol = Tombolbawah Then
Waitms 200
Gosub Geserbawah
End If
Loop
Return

'------------------------------------------------------------------------------
' sub geser kanan
'------------------------------------------------------------------------------
Geserkanan:
If Z1 = 0 Then
Gosub Tampil
Elseif Z2 = 0 Then
Y = Z2
Z2 = Z1
Z1 = Y
Gosub Tampil
Elseif Z3 = 0 Then
Y = Z3
Z3 = Z2
Z2 = Y
Gosub Tampil
Elseif Z4 = 0 Then
Gosub Tampil
Elseif Z5 = 0 Then
Y = Z5
Z5 = Z4
Z4 = Y
Gosub Tampil
Elseif Z6 = 0 Then
Y = Z6
Z6 = Z5
Z5 = Y
Gosub Tampil
Elseif Z7 = 0 Then
Gosub Tampil
Elseif Z8 = 0 Then
Y = Z8
Z8 = Z7
Z7 = Y
Gosub Tampil
Elseif Z9 = 0 Then
Y = Z9
Z9 = Z8
Z8 = Y
Gosub Tampil
Else
Gosub Tampil
End If

Return
'------------------------------------------------------------------------------
' sub geser kiri
'------------------------------------------------------------------------------
Geserkiri:
If Z1 = 0 Then
Y = Z1
Z1 = Z2
Z2 = Y
Gosub Tampil
Elseif Z2 = 0 Then
Y = Z2
Z2 = Z3
Z3 = Y
Gosub Tampil
Elseif Z3 = 0 Then
Gosub Tampil
Elseif Z4 = 0 Then
Y = Z4
Z4 = Z5
Z5 = Y
Gosub Tampil
Elseif Z5 = 0 Then
Y = Z5
Z5 = Z6
Z6 = Y
Gosub Tampil
Elseif Z6 = 0 Then
Gosub Tampil
Elseif Z7 = 0 Then
Y = Z7
Z7 = Z8
Z8 = Y
Gosub Tampil
Elseif Z8 = 0 Then
Y = Z8
Z8 = Z9
Z9 = Y
Gosub Tampil
Elseif Z9 = 0 Then
Gosub Tampil
Else
Gosub Tampil
End If

Return
'------------------------------------------------------------------------------
' sub geser bawah
'------------------------------------------------------------------------------
Geserbawah:
If Z1 = 0 Then
Gosub Tampil
Elseif Z2 = 0 Then
Gosub Tampil
Elseif Z3 = 0 Then
Gosub Tampil
Elseif Z4 = 0 Then
Y = Z4
Z4 = Z1
Z1 = Y
Gosub Tampil
Elseif Z5 = 0 Then
Y = Z5
Z5 = Z2
Z2 = Y
Gosub Tampil
Elseif Z6 = 0 Then
Y = Z6
Z6 = Z3
Z3 = Y
Gosub Tampil
Elseif Z7 = 0 Then
Y = Z7
Z7 = Z4
Z4 = Y
Gosub Tampil
Elseif Z8 = 0 Then
Y = Z8
Z8 = Z5
Z5 = Y
Gosub Tampil
Elseif Z9 = 0 Then
Y = Z9
Z9 = Z6
Z6 = Y
Gosub Tampil
Else
Gosub Tampil
End If

Return
'------------------------------------------------------------------------------
' sub geser atas
'------------------------------------------------------------------------------
Geseratas:
If Z1 = 0 Then
Y = Z1
Z1 = Z4
Z4 = Y
Gosub Tampil
Elseif Z2 = 0 Then
Y = Z2
Z2 = Z5
Z5 = Y
Gosub Tampil
Elseif Z3 = 0 Then
Y = Z3
Z3 = Z6
Z6 = Y
Gosub Tampil
Elseif Z4 = 0 Then
Y = Z4
Z4 = Z7
Z7 = Y
Gosub Tampil
Elseif Z5 = 0 Then
Y = Z5
Z5 = Z8
Z8 = Y
Gosub Tampil
Elseif Z6 = 0 Then
Y = Z6
Z6 = Z9
Z9 = Y
Gosub Tampil
Elseif Z7 = 0 Then
Gosub Tampil
Elseif Z8 = 0 Then
Gosub Tampil
Elseif Z9 = 0 Then
Gosub Tampil
Else
Gosub Tampil
End If

Return
'------------------------------------------------------------------------------
' sub salah pilih random
'------------------------------------------------------------------------------

Salah:
Do
Segmen = Lookup(0 , Slh)
Comon = &B00000001
Portd.2 = 0
Waitus 200
Segmen = Lookup(1 , Slh)
Comon = &B00000010
Portd.2 = 0
Waitus 200
Segmen = Lookup(2 , Slh)
Comon = &B00000100
Portd.2 = 0
Waitus 200
Loop
Return

Selesai:
Do
Segmen = Lookup(0 , Game)
Comon = &B00000001
Portd.2 = 0
Waitms 50
Segmen = Lookup(1 , Game)
Comon = &B00000010
Portd.2 = 0
Waitms 50
Segmen = Lookup(2 , Game)
Comon = &B00000100
Portd.2 = 0
Waitms 50
Segmen = Lookup(1 , Game)
Comon = &B00001000
Portd.2 = 0
Waitms 50
Segmen = Lookup(0 , Game)
Comon = &B00010000
Portd.2 = 0
Waitms 50
Segmen = Lookup(3 , Game)
Comon = &B00100000
Portd.2 = 0
Waitms 50
Segmen = Lookup(4 , Game)
Comon = &B01000000
Portd.2 = 0
Waitms 50
Loop
Return

'------------------------------------------------------------------------------
'Data seven segment
'------------------------------------------------------------------------------
Segment:
Data &B11111111 , &B11111001 , &B10100100 , &B10110000 , &B10011001 , &B10010010 , &B00000010 , &B11111000 , &B10000000
Slh:
Data &B10010010 , &B11000111 , &B10001011
Game:
Data &B10010010 , &B10000110 , &B11000111 , &B10001000 , &B11111001

0 komentar: