dado_electronico

Es un dado electronico, controlado con un uControlador PIC 16F628A y una matriz de leds de 7×5 como display. fue un proyecto improvisado para la materia de arquitectura de dispositivos programables.

Dejo un video del funcionamiento, simulacion en proteus y archivo hex listo para cargarlo al pic.

Define CONF_WORD = 0x3f50

AllDigital

TRISA = %00000100
TRISB = %00000000

Dim numero As Byte
Dim fila As Byte
Dim datos As Byte
Dim x As Byte
Dim velocidad As Byte

velocidad = 40
datos = 0
numero = 0

Symbol boton = RA2

Symbol col1 = RA1
Symbol col2 = RA0
Symbol col3 = RA7
Symbol col4 = RA6
Symbol col5 = RA3

Symbol fila1 = RB1
Symbol fila2 = RB2
Symbol fila3 = RB3
Symbol fila4 = RB4
Symbol fila5 = RB5
Symbol fila6 = RB6
Symbol fila7 = RB7

inicio:

If boton = 1 Then

Gosub lanzar_dado

Endif

Gosub mostrar_numero

Goto inicio

End                                               

lanzar_dado:

While boton = 1

datos = %00001

'-------------------------animacion hacia la izkierda
While datos < %100000 And boton = 1
Gosub escribir_dato
Gosub sumar
For x = 1 To velocidad
fila = 1
Gosub encender_fila
Next x
datos = ShiftLeft(datos, 1)
Wend

'-------------------------animacion hacia abajoo
For fila = 1 To 7
datos = %10000
If datos = %10000 And boton = 1 Then
Gosub escribir_dato
For x = 1 To velocidad
Gosub encender_fila
Next x
Gosub sumar
Endif
Next fila

'-------------------------animacion hacia derecha
While datos > %00000 And boton = 1
Gosub escribir_dato
Gosub sumar
For x = 1 To velocidad
fila = 7
Gosub encender_fila
Next x
datos = ShiftRight(datos, 1)
Wend

'-------------------------animacion hacia arriba
For fila = 7 To 1 Step -1
datos = %00001
If datos = %00001 And boton = 1 Then
Gosub escribir_dato
For x = 1 To velocidad
Gosub encender_fila
Next x
Gosub sumar
Endif
Next fila

Wend

Return                                            

sumar:

numero = numero + 1
If numero > 6 Then
numero = 1
Endif

Return                                            

mostrar_numero:

Select Case numero

Case 0

datos = %00000000
Gosub escribir_dato
fila = 1
Gosub encender_fila
datos = %00000000
Gosub escribir_dato
fila = 2
Gosub encender_fila
datos = %00000000
Gosub escribir_dato
fila = 3
Gosub encender_fila
datos = %00000000
Gosub escribir_dato
fila = 4
Gosub encender_fila
datos = %00000000
Gosub escribir_dato
fila = 5
Gosub encender_fila
datos = %00000000
Gosub escribir_dato
fila = 6
Gosub encender_fila
datos = %00000000
Gosub escribir_dato
fila = 7
Gosub encender_fila

Case 1

datos = %00100
Gosub escribir_dato
fila = 1
Gosub encender_fila
datos = %01100
Gosub escribir_dato
fila = 2
Gosub encender_fila
datos = %10100
Gosub escribir_dato
fila = 3
Gosub encender_fila
datos = %00100
Gosub escribir_dato
fila = 4
Gosub encender_fila
datos = %00100
Gosub escribir_dato
fila = 5
Gosub encender_fila
datos = %00100
Gosub escribir_dato
fila = 6
Gosub encender_fila
datos = %11111
Gosub escribir_dato
fila = 7
Gosub encender_fila

Case 2

datos = %01110
Gosub escribir_dato
fila = 1
Gosub encender_fila
datos = %10001
Gosub escribir_dato
fila = 2
Gosub encender_fila
datos = %10001
Gosub escribir_dato
fila = 3
Gosub encender_fila
datos = %00010
Gosub escribir_dato
fila = 4
Gosub encender_fila
datos = %00100
Gosub escribir_dato
fila = 5
Gosub encender_fila
datos = %01000
Gosub escribir_dato
fila = 6
Gosub encender_fila
datos = %11111
Gosub escribir_dato
fila = 7
Gosub encender_fila

Case 3

datos = %11111
Gosub escribir_dato
fila = 1
Gosub encender_fila
datos = %00001
Gosub escribir_dato
fila = 2
Gosub encender_fila
datos = %00010
Gosub escribir_dato
fila = 3
Gosub encender_fila
datos = %00110
Gosub escribir_dato
fila = 4
Gosub encender_fila
datos = %00001
Gosub escribir_dato
fila = 5
Gosub encender_fila
datos = %00001
Gosub escribir_dato
fila = 6
Gosub encender_fila
datos = %11110
Gosub escribir_dato
fila = 7
Gosub encender_fila

Case 4

datos = %00010
Gosub escribir_dato
fila = 1
Gosub encender_fila
datos = %00110
Gosub escribir_dato
fila = 2
Gosub encender_fila
datos = %01010
Gosub escribir_dato
fila = 3
Gosub encender_fila
datos = %11111
Gosub escribir_dato
fila = 4
Gosub encender_fila
datos = %00010
Gosub escribir_dato
fila = 5
Gosub encender_fila
datos = %00010
Gosub escribir_dato
fila = 6
Gosub encender_fila
datos = %00010
Gosub escribir_dato
fila = 7
Gosub encender_fila

Case 5

datos = %11111
Gosub escribir_dato
fila = 1
Gosub encender_fila
datos = %10000
Gosub escribir_dato
fila = 2
Gosub encender_fila
datos = %10000
Gosub escribir_dato
fila = 3
Gosub encender_fila
datos = %01110
Gosub escribir_dato
fila = 4
Gosub encender_fila
datos = %00001
Gosub escribir_dato
fila = 5
Gosub encender_fila
datos = %00001
Gosub escribir_dato
fila = 6
Gosub encender_fila
datos = %11110
Gosub escribir_dato
fila = 7
Gosub encender_fila

Case 6

datos = %01110
Gosub escribir_dato
fila = 1
Gosub encender_fila
datos = %10001
Gosub escribir_dato
fila = 2
Gosub encender_fila
datos = %10000
Gosub escribir_dato
fila = 3
Gosub encender_fila
datos = %11110
Gosub escribir_dato
fila = 4
Gosub encender_fila
datos = %10001
Gosub escribir_dato
fila = 5
Gosub encender_fila
datos = %10001
Gosub escribir_dato
fila = 6
Gosub encender_fila
datos = %01110
Gosub escribir_dato
fila = 7
Gosub encender_fila

EndSelect

Return                                            

escribir_dato:

col1 = datos.4
col2 = datos.3
col3 = datos.2
col4 = datos.1
col5 = datos.0

Return                                            

encender_fila:

Select Case fila

Case 1
fila1 = 0
WaitUs 500
fila1 = 1

Case 2
fila2 = 0
WaitUs 500
fila2 = 1

Case 3
fila3 = 0
WaitUs 500
fila3 = 1

Case 4
fila4 = 0
WaitUs 500
fila4 = 1

Case 5
fila5 = 0
WaitUs 500
fila5 = 1

Case 6
fila6 = 0
WaitUs 500
fila6 = 1

Case 7
fila7 = 0
WaitUs 500
fila7 = 1

EndSelect

Return

Popularity: 100%