''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''
''Pic 16F628A @ 4Mhz ''
''Programa para controlar cubo led de 3x3x3 ''
''Autor: Daniel Arturo Fernandez Raygoza ''
''Fecha: 2 de abril de 2012 ''
''Version 1.0 ''
''DAFR Electronics ''
''Todos los derechos reservados ''
''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''
AllDigital
TRISA = %00111000
TRISB = %00000000
Dim secuencia As Byte
Dim rep As Byte
Dim ran As Byte
Dim boto As Byte
Dim other As Byte
PORTA = %00000000
PORTB = %00000000
PORTA.2 = 1
WaitMs 500
Read 0, secuencia
WaitMs 500
PORTA.2 = 0
inicio:
Select Case secuencia
Gosub botones
Case 0
Gosub secuencia0
Case 1
Gosub secuencia1
Case 2
Gosub secuencia2
Case 3
Gosub secuencia3
Case 4
Gosub secuencia4
Case 5
Gosub secuencia5
Case 6
Gosub secuencia6
Case 7
Gosub secuencia7
Case 8
Gosub secuencia8
Case 9
Gosub secuencia9
Case 10
Gosub secuencia10
Case 11
Gosub secuencia11
Case 12
Gosub secuencia12
Case 13
Gosub secuencia13
Case 14
Gosub secuencia14
Case 15
Gosub secuencia15
Case 16
Gosub secuencia16
Case 17
Gosub secuencia17
Case 18
Gosub secuencia18
Case 19
Gosub secuencia19
Case 20
Gosub secuencia20
Case 21
Gosub secuencia21
Case 22
Gosub secuencia22
EndSelect
Goto inicio
End
secuencia0: 'stanby
PORTA = %00000100
PORTB = %00000000
WaitMs 100
PORTA = %00000000
PORTB = %00000000
WaitMs 1500
Return
secuencia1: 'parpadeando
PORTA = %11000011
PORTB = %11111111
WaitMs 300
Gosub botones
PORTB = %00000000
PORTA = %00000000
WaitMs 300
Return
secuencia2: 'centro a superior e inferior
PORTA = %01000001
PORTB = %11111111
WaitMs 350
Gosub botones
PORTA = %11000010
PORTB = %11111111
WaitMs 350
Return
secuencia3: 'centro a izquierda y derecha
PORTA = %10000011
PORTB = %00111000
WaitMs 350
Gosub botones
PORTA = %11000011
PORTB = %11000111
WaitMs 350
Return
secuencia4: 'mezcla del 2 y 3
Gosub secuencia2
Gosub secuencia3
Return
secuencia5: 'niveles ascendentes
PORTA = %01000010
PORTB = %11111111
WaitMs 250
Gosub botones
PORTA = %01000001
PORTB = %11111111
WaitMs 250
Gosub botones
PORTA = %11000000
PORTB = %11111111
WaitMs 250
Return
secuencia6: 'niveles descendentes
PORTA = %11000000
PORTB = %11111111
WaitMs 250
Gosub botones
PORTA = %01000001
PORTB = %11111111
WaitMs 250
Gosub botones
PORTA = %01000010
PORTB = %11111111
WaitMs 250
Return
secuencia7: 'arriba a abajo
PORTA = %01000010
PORTB = %11111111
WaitMs 150
Gosub botones
PORTA = %01000001
PORTB = %11111111
WaitMs 150
Gosub botones
PORTA = %11000000
PORTB = %11111111
WaitMs 150
Gosub botones
PORTA = %01000001
PORTB = %11111111
WaitMs 150
Gosub botones
Return
secuencia8: 'izquierda a derecha
PORTA = %11000011
PORTB = %11000000
WaitMs 250
Gosub botones
PORTA = %10000011
PORTB = %00111000
WaitMs 250
Gosub botones
PORTA = %10000011
PORTB = %00000111
WaitMs 250
Return
secuencia9: 'derecha a izquierda
PORTA = %10000011
PORTB = %00000111
WaitMs 250
Gosub botones
PORTA = %10000011
PORTB = %00111000
WaitMs 250
Gosub botones
PORTA = %11000011
PORTB = %11000000
WaitMs 250
Return
secuencia10: 'mezcla del 8 y 9
PORTA = %11000011
PORTB = %11000000
WaitMs 150
Gosub botones
PORTA = %10000011
PORTB = %00111000
WaitMs 150
Gosub botones
PORTA = %10000011
PORTB = %00000111
WaitMs 150
Gosub botones
PORTA = %10000011
PORTB = %00111000
WaitMs 150
Return
secuencia11: 'mezcla del 4,8,5,9
Gosub secuencia5
Gosub diagonal
Gosub secuencia8
Gosub diagonal
Gosub secuencia6
Gosub diagonal
Gosub secuencia9
Gosub diagonal
Return
diagonal:
For other = 1 To 42
PORTA = %00000010
PORTB = %00000111
WaitMs 2
PORTA = %00000001
PORTB = %00111000
WaitMs 2
PORTA = %11000000
PORTB = %11000000
WaitMs 2
Next other
Return
secuencia12: 'led individual corriendo
PORTA = %00000010
PORTB = %00000001
WaitMs 100
Gosub botones
PORTA = %00000010
PORTB = %00000010
WaitMs 100
Gosub botones
PORTA = %00000010
PORTB = %00000100
WaitMs 100
Gosub botones
PORTA = %00000010
PORTB = %00001000
WaitMs 100
Gosub botones
PORTA = %00000010
PORTB = %00010000
WaitMs 100
Gosub botones
PORTA = %00000010
PORTB = %00100000
WaitMs 100
Gosub botones
PORTA = %00000010
PORTB = %01000000
WaitMs 100
Gosub botones
PORTA = %00000010
PORTB = %10000000
WaitMs 100
Gosub botones
PORTA = %01000010
PORTB = %00000000
WaitMs 100
Gosub botones
PORTA = %00000001
PORTB = %00000001
WaitMs 100
Gosub botones
PORTA = %00000001
PORTB = %00000010
WaitMs 100
Gosub botones
PORTA = %00000001
PORTB = %00000100
WaitMs 100
Gosub botones
PORTA = %00000001
PORTB = %00001000
WaitMs 100
Gosub botones
PORTA = %00000001
PORTB = %00010000
WaitMs 100
Gosub botones
PORTA = %00000001
PORTB = %00100000
WaitMs 100
Gosub botones
PORTA = %00000001
PORTB = %01000000
WaitMs 100
Gosub botones
PORTA = %00000001
PORTB = %10000000
WaitMs 100
Gosub botones
PORTA = %01000001
PORTB = %00000000
WaitMs 100
Gosub botones
PORTA = %10000000
PORTB = %00000001
WaitMs 100
Gosub botones
PORTA = %10000000
PORTB = %00000010
WaitMs 100
Gosub botones
PORTA = %10000000
PORTB = %00000100
WaitMs 100
Gosub botones
PORTA = %10000000
PORTB = %00001000
WaitMs 100
Gosub botones
PORTA = %10000000
PORTB = %00010000
WaitMs 100
Gosub botones
PORTA = %10000000
PORTB = %00100000
WaitMs 100
Gosub botones
PORTA = %10000000
PORTB = %01000000
WaitMs 100
Gosub botones
PORTA = %10000000
PORTB = %10000000
WaitMs 100
Gosub botones
PORTA = %11000000
PORTB = %00000000
WaitMs 100
Return
secuencia13: 'columna corriendo
PORTA = %10000011
PORTB = %00000001
WaitMs 125
Gosub botones
PORTA = %10000011
PORTB = %00000010
WaitMs 125
Gosub botones
PORTA = %10000011
PORTB = %00000100
WaitMs 125
Gosub botones
PORTA = %10000011
PORTB = %00001000
WaitMs 125
Gosub botones
PORTA = %10000011
PORTB = %00010000
WaitMs 125
Gosub botones
PORTA = %10000011
PORTB = %00100000
WaitMs 125
Gosub botones
PORTA = %10000011
PORTB = %01000000
WaitMs 125
Gosub botones
PORTA = %10000011
PORTB = %10000000
WaitMs 125
Gosub botones
PORTA = %11000011
PORTB = %00000000
WaitMs 125
Return
secuencia14: 'giro anti-reloj
PORTA = %11000011
PORTB = %00010001
WaitMs 150
Gosub botones
PORTA = %10000011
PORTB = %00111000
WaitMs 150
Gosub botones
PORTA = %10000011
PORTB = %01010100
WaitMs 150
Gosub botones
PORTA = %10000011
PORTB = %10010010
WaitMs 150
Return
secuencia15: 'giro reloj
PORTA = %11000011
PORTB = %00010001
WaitMs 150
Gosub botones
PORTA = %10000011
PORTB = %10010010
WaitMs 150
Gosub botones
PORTA = %10000011
PORTB = %01010100
WaitMs 150
Gosub botones
PORTA = %10000011
PORTB = %00111000
WaitMs 150
Return
secuencia16: 'giros alternados
For rep = 1 To 4
Gosub secuencia14
Next rep
For rep = 1 To 4
Gosub secuencia15
Next rep
Return
secuencia17: 'snake
PORTA = %00000011
PORTB = %00000100
WaitMs 150
Gosub botones
PORTA = %00000001
PORTB = %00100100
WaitMs 150
Gosub botones
PORTA = %00000001
PORTB = %00110000
WaitMs 150
Gosub botones
PORTA = %00000001
PORTB = %00010010
WaitMs 150
Gosub botones
PORTA = %10000001
PORTB = %00000010
WaitMs 150
Gosub botones
PORTA = %10000000
PORTB = %00000110
WaitMs 150
Gosub botones
PORTA = %10000000
PORTB = %00100100
WaitMs 150
Gosub botones
PORTA = %10000000
PORTB = %00110000
WaitMs 150
Gosub botones
PORTA = %10000000
PORTB = %00011000
WaitMs 150
Gosub botones
PORTA = %10000000
PORTB = %00001001
WaitMs 150
Gosub botones
PORTA = %10000001
PORTB = %00000001
WaitMs 150
Gosub botones
PORTA = %00000001
PORTB = %00001001
WaitMs 150
Gosub botones
PORTA = %00000011
PORTB = %00001000
WaitMs 150
Gosub botones
PORTA = %00000010
PORTB = %00001001
WaitMs 150
Gosub botones
PORTA = %00000010
PORTB = %00000011
WaitMs 150
Gosub botones
PORTA = %00000010
PORTB = %00010010
WaitMs 150
Gosub botones
PORTA = %00000010
PORTB = %10010000
WaitMs 150
Gosub botones
PORTA = %00000010
PORTB = %11000000
WaitMs 150
Gosub botones
PORTA = %00000011
PORTB = %01000000
WaitMs 150
Gosub botones
PORTA = %10000001
PORTB = %01000000
WaitMs 150
Gosub botones
PORTA = %10000000
PORTB = %11000000
WaitMs 150
Gosub botones
PORTA = %11000000
PORTB = %10000000
WaitMs 150
Gosub botones
PORTA = %11000001
PORTB = %00000000
WaitMs 150
Gosub botones
PORTA = %01000001
PORTB = %10000000
WaitMs 150
Gosub botones
PORTA = %00000011
PORTB = %10000000
WaitMs 150
Gosub botones
PORTA = %01000010
PORTB = %10000000
WaitMs 150
Gosub botones
PORTA = %01000010
PORTB = %00100000
WaitMs 150
Gosub botones
PORTA = %00000010
PORTB = %00100100
WaitMs 150
Return
secuencia18: 'cubo moviendose
PORTA = %01000011
PORTB = %10110000
WaitMs 250
Gosub botones
PORTA = %00000011
PORTB = %00110110
WaitMs 250
Gosub botones
PORTA = %10000001
PORTB = %00110110
WaitMs 250
Gosub botones
PORTA = %10000001
PORTB = %00011011
WaitMs 250
Gosub botones
PORTA = %00000011
PORTB = %00011011
WaitMs 250
Gosub botones
PORTA = %00000011
PORTB = %11011000
WaitMs 250
Gosub botones
PORTA = %10000001
PORTB = %11011000
WaitMs 250
Gosub botones
PORTA = %11000001
PORTB = %10110000
WaitMs 250
Return
secuencia19: 'cubo progresivo
PORTA = %00000000
PORTB = %00000000
WaitMs 500
Gosub botones
PORTA = %00000001
PORTB = %00010000
WaitMs 500
Gosub botones
For rep = 1 To 125
PORTA = %00000001
PORTB = %00010000
WaitMs 2
Gosub botones
PORTA = %11000010
PORTB = %01000101
WaitMs 2
Next rep
Gosub botones
For rep = 1 To 125
PORTA = %01000001
PORTB = %01010101
WaitMs 2
Gosub botones
PORTA = %11000010
PORTB = %11101111
WaitMs 2
Next rep
PORTA = %11000011
PORTB = %11111111
WaitMs 600
Gosub botones
For rep = 1 To 125
PORTA = %01000001
PORTB = %01010101
WaitMs 2
Gosub botones
PORTA = %11000010
PORTB = %11101111
WaitMs 2
Next rep
For rep = 1 To 125
PORTA = %00000001
PORTB = %00010000
WaitMs 2
Gosub botones
PORTA = %11000010
PORTB = %01000101
WaitMs 2
Next rep
PORTA = %00000001
PORTB = %00010000
WaitMs 500
Return
secuencia20: 'fuegos artificiales
PORTA = %00000010
PORTB = %00010000
WaitMs 150
Gosub botones
PORTA = %00000001
PORTB = %00010000
WaitMs 150
Gosub botones
PORTA = %10000000
PORTB = %00010000
WaitMs 150
Gosub botones
PORTA = %11000000
PORTB = %01000101
WaitMs 150
Gosub botones
PORTA = %01000001
PORTB = %01000101
WaitMs 150
Gosub botones
PORTA = %01000010
PORTB = %01000101
WaitMs 150
Gosub botones
PORTA = %00000000
PORTB = %00000000
WaitMs 150
Return
secuencia21: 'cubo de esquina a esquina
PORTA = %00000010
PORTB = %00000100
WaitMs 250
Gosub botones
PORTA = %00000011
PORTB = %00110110
WaitMs 250
Gosub botones
PORTA = %11000011
PORTB = %11111111
WaitMs 250
Gosub botones
PORTA = %10000001
PORTB = %11011000
WaitMs 250
Gosub botones
PORTA = %10000000
PORTB = %01000000
WaitMs 250
Gosub botones
PORTA = %10000001
PORTB = %11011000
WaitMs 250
Gosub botones
PORTA = %11000011
PORTB = %11111111
WaitMs 250
Gosub botones
PORTA = %00000011
PORTB = %00110110
WaitMs 250
Return
secuencia22: 'pseudo-aleatorio
Gosub secuencia5
For ran = 1 To 6
Gosub secuencia1
Next ran
For ran = 1 To 5
Gosub secuencia2
Next ran
For ran = 1 To 5
Gosub secuencia3
Next ran
For ran = 1 To 5
Gosub secuencia4
Next ran
For ran = 1 To 5
Gosub secuencia7
Next ran
Gosub diagonal
For ran = 1 To 5
Gosub secuencia10
Next ran
For ran = 1 To 5
Gosub secuencia11
Next ran
Gosub secuencia6
For ran = 1 To 8
Gosub secuencia12
Next ran
For ran = 1 To 9
Gosub secuencia13
Next ran
Gosub secuencia20
For ran = 1 To 4
Gosub secuencia16
Next ran
For ran = 1 To 6
Gosub secuencia17
Next ran
For ran = 1 To 6
Gosub secuencia18
Next ran
For ran = 1 To 3
Gosub secuencia19
Next ran
Gosub secuencia6
For ran = 1 To 6
Gosub secuencia20
Next ran
Gosub secuencia5
For ran = 1 To 8
Gosub secuencia21
Next ran
PORTA = %00000000
PORTB = %00000000
WaitMs 1000
Return
End
botones:
If PORTA.3 = 1 Then
PORTA = %00000000
PORTB = %00000000
PORTA.2 = 1
WaitMs 1000
secuencia = 0
Write 0, secuencia
PORTA.2 = 0
Endif
If PORTA.4 = 1 And PORTA.5 = 1 Then
PORTA = %00000000
PORTB = %00000000
secuencia = 22
Write 0, secuencia
PORTA.2 = 1
WaitMs 600
PORTA.2 = 0
Endif
If PORTA.5 = 1 Then
PORTA = %00000000
PORTB = %00000000
secuencia = secuencia + 1
If secuencia = 23 Then secuencia = 0
Write 0, secuencia
For boto = 1 To secuencia
PORTA.2 = 1
WaitMs 200
PORTA.2 = 0
WaitMs 300
Next boto
Endif
If PORTA.4 = 1 Then
PORTA = %00000000
PORTB = %00000000
secuencia = secuencia - 1
If secuencia = 255 Then secuencia = 22
Write 0, secuencia
For boto = 1 To secuencia
PORTA.2 = 1
WaitMs 200
PORTA.2 = 0
WaitMs 300
Next boto
Endif
Return
End