El contador es un instrumento basado en tecnología de microprocesador con lectura y programación digital orientado a la automatización de procesos industriales que requieran labores de conteo. El instrumento está diseñado para ser configurado según las necesidades particulares.
Especificaciones técnicas.
Desde el siguiente enlace se puede descargar el diagrama esquemático en formato PDF junto a la lista completa de materiales y el código fuente en lenguaje BASIC.
El compilador utilizado para escribir el firmware es PIC Simulator IDE. Desde el mismo IDE es posible realizar una simulación para chequear el funcionamiento de la rutina y realizar modificaciones si fuera necesario adaptar el funcionamiento a un caso particular.
'-----------------------------------------------------------------------
'--- CONTADOR 4 DIGITOS PROGRAMABLE
'--- AUTOMATISMOS MAR DEL PLATA - 06/10/2008
'-----------------------------------------------------------------------
Define CONF_WORD = 0x3f30
'-----------------------------------------------------------------------
'-- CONFIGURACION DE PUERTOS
'-----------------------------------------------------------------------
AllDigital 'Desactivo comparadores
TRISA = %11100000 'Configuro entradas y salidas PORTA
TRISB = %00000001 'Configuro entradas y salidas PORTB
'-----------------------------------------------------------------------
'-- DECLARACION DE VARIABLES
'-----------------------------------------------------------------------
Dim unidad As Byte 'Variables de conteo
Dim decena As Byte
Dim centena As Byte
Dim miles As Byte
Dim unidad_fin As Byte 'Variables de limite
Dim decena_fin As Byte
Dim centena_fin As Byte
Dim miles_fin As Byte
Dim mascara As Byte
Dim demora As Word
Dim a As Byte
Dim b As Byte
'-----------------------------------------------------------------------
'-- LIMPIEZA DE PUERTOS
'-----------------------------------------------------------------------
PORTA = %00000000 'Limpio PORTA
PORTB = %00000000 'Limpio PORTB
main:
a = 0
b = 0
mascara = 0
unidad_fin = 10
decena_fin = 10
centena_fin = 10
miles_fin = 10
unidad = 0
decena = 0
centena = 0
miles = 0
'-----------------------------------------------------------------------
'-- CONFIGURACION INTERRUPCION POR TIMER0
'-----------------------------------------------------------------------
OPTION_REG.T0CS = 0 'selecciona reloj interno
OPTION_REG.PSA = 0 'asigna el prescaler al timer0
OPTION_REG.PS0 = 1 'bits de la seleccion del factor de division,prescaler 16
OPTION_REG.PS1 = 0 'bits de la seleccion del factor de division,prescaler 16
OPTION_REG.PS2 = 1 'bits de la seleccion del factor de division,prescaler 16
INTCON.GIE = 1 'habilita todas las interrupciones globales
INTCON.T0IF = 0 'borra el flag de desbordamiento del timer0
TMR0 = 254 'cargo el registro del tmr0 para que desborde cada 1mS
INTCON.T0IE = 1
'-----------------------------------------------------------------------
'-- BLOQUE DE CONTEO
'-----------------------------------------------------------------------
seteo_bloque_conteo:
a = 0 'variable de modo de visualización
RA.4 = 1
'-----------------------------------------------------------------------
'-- RECUPERACION DE DATOS DESDE EEPROM
'-----------------------------------------------------------------------
Read 1, unidad_fin
Read 2, decena_fin
Read 3, centena_fin
Read 4, miles_fin
bloque_conteo:
'-----------------------------------------------------------------------
'-- MUESTRO CUENTA PREFIJADA
'-----------------------------------------------------------------------
If RA.6 = 1 Then Goto antirrebote_100
Goto check_prog
antirrebote_100:
If RA.6 = 1 Then Goto antirrebote_100
If a = 0 Then
a = 1
Else
a = 0
Endif
check_prog:
'-----------------------------------------------------------------------
'-- ENTRO EN MODO PROGRAMACION
'-----------------------------------------------------------------------
If RA.7 = 1 Then Goto antirrebote_200
Goto comienza_conteo
antirrebote_200:
If RA.7 = 1 Then Goto antirrebote_200
Goto bloque_prog
comienza_conteo:
'-----------------------------------------------------------------------
'-- CHEQUEO ENTRADA DE CONTEO
'-----------------------------------------------------------------------
If RB.0 = 1 Then Goto antirrebote_2
Goto bloque_conteo
antirrebote_2:
If RB.0 = 1 Then Goto antirrebote_2
'-----------------------------------------------------------------------
'-- EMPIEZO A CONTAR
'-----------------------------------------------------------------------
If unidad = 9 Then
unidad = 0
Goto et_decena
Endif
unidad = unidad + 1
Goto comparacion
et_decena:
If decena = 9 Then
decena = 0
Goto et_centena
Endif
decena = decena + 1
Goto comparacion
et_centena:
If centena = 9 Then
centena = 0
Goto et_miles
Endif
centena = centena + 1
Goto comparacion
et_miles:
If miles = 9 Then Goto bloque_conteo
miles = miles + 1
'-----------------------------------------------------------------------
'-- BLOQUE FINAL DE CUENTA
'-----------------------------------------------------------------------
comparacion:
If unidad = unidad_fin Then Goto final_decena
Goto bloque_conteo
final_decena:
If decena = decena_fin Then Goto final_centena
Goto bloque_conteo
final_centena:
If centena = centena_fin Then Goto final_miles
Goto bloque_conteo
final_miles:
If miles = miles_fin Then Goto accion_final
Goto bloque_conteo
accion_final:
b = 1 'variable de visualización
RA.4 = 0
Goto accion_final
'-----------------------------------------------------------------------
'-- BLOQUE DE PROGRAMACION
'-----------------------------------------------------------------------
bloque_prog:
unidad_fin = 10
decena_fin = 10
centena_fin = 10
miles_fin = 10
a = 1 'variable de modo de visualización
'-----------------------------------------------------------------------
'-- INICIO DE PROGRAMACION
'-----------------------------------------------------------------------
If RA.6 = 1 Then Goto antirrebote_44
Goto bloque_prog
antirrebote_44:
If RA.6 = 1 Then Goto antirrebote_44
unidad_fin = 0
'-----------------------------------------------------------------------
'-- SETEO DE UNIDADES
'-----------------------------------------------------------------------
set_unidades:
If RA.7 = 1 Then Goto antirrebote_3
If RA.6 = 1 Then Goto antirrebote_4
Goto set_unidades
antirrebote_3:
If RA.7 = 1 Then Goto antirrebote_3
If unidad_fin = 9 Then
unidad_fin = 0
Goto set_unidades
Endif
unidad_fin = unidad_fin + 1
Goto set_unidades
antirrebote_4:
If RA.6 = 1 Then Goto antirrebote_4
decena_fin = 0
'-----------------------------------------------------------------------
'-- SETEO DECENAS
'-----------------------------------------------------------------------
set_decenas:
If RA.7 = 1 Then Goto antirrebote_5
If RA.6 = 1 Then Goto antirrebote_6
Goto set_decenas
antirrebote_5:
If RA.7 = 1 Then Goto antirrebote_5
If decena_fin = 9 Then
decena_fin = 0
Goto set_decenas
Endif
decena_fin = decena_fin + 1
Goto set_decenas
antirrebote_6:
If RA.6 = 1 Then Goto antirrebote_6
centena_fin = 0
'-----------------------------------------------------------------------
'-- SETEO DE CENTENAS
'-----------------------------------------------------------------------
set_centenas:
If RA.7 = 1 Then Goto antirrebote_7
If RA.6 = 1 Then Goto antirrebote_8
Goto set_centenas
antirrebote_7:
If RA.7 = 1 Then Goto antirrebote_7
If centena_fin = 9 Then
centena_fin = 0
Goto set_centenas
Endif
centena_fin = centena_fin + 1
Goto set_centenas
antirrebote_8:
If RA.6 = 1 Then Goto antirrebote_8
miles_fin = 0
'-----------------------------------------------------------------------
'-- SETEO DE UNIDADES DE MIL
'-----------------------------------------------------------------------
set_miles:
If RA.7 = 1 Then Goto antirrebote_9
If RA.6 = 1 Then Goto antirrebote_10
Goto set_miles
antirrebote_9:
If RA.7 = 1 Then Goto antirrebote_9
If miles_fin = 9 Then
miles_fin = 0
Goto set_miles
Endif
miles_fin = miles_fin + 1
Goto set_miles
antirrebote_10:
If RA.6 = 1 Then Goto antirrebote_10
'-----------------------------------------------------------------------
'-- GUARDAR DATOS EN EEPROM
'-----------------------------------------------------------------------
Write 1, unidad_fin 'escritura en EEPROM valor de unidad_fin
Write 2, decena_fin 'escritura en EEPROM valor de decena_fin
Write 3, centena_fin 'escritura en EEPROM valor de centena_fin
Write 4, miles_fin 'escritura en EEPROM valor de miles_fin
Goto main
End
'-----------------------------------------------------------------------
'-- RUTINA DE VISUALIZACIÓN POR INTERRUPCIÓN
'-----------------------------------------------------------------------
On Interrupt
If b = 1 Then Goto visualizar_b
If a = 1 Then Goto visualizar_a
'-----------------------------------------------------------------------
'-- MUESTRO CONTEO
'-----------------------------------------------------------------------
'Muestro unidades
mascara = LookUp(0x7e, 0xc, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0xe, 0xfe, 0xde), unidad
PORTB = mascara
RA.0 = 1
WaitMs 6 'Experimentar con este valor.
RA.0 = 0
'Muestro decenas
mascara = LookUp(0x7e, 0xc, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0xe, 0xfe, 0xde), decena
PORTB = mascara
RA.1 = 1
WaitMs 6 'Experimentar con este valor.
RA.1 = 0
'Muestro centenas
mascara = LookUp(0x7e, 0xc, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0xe, 0xfe, 0xde), centena
PORTB = mascara
RA.2 = 1
WaitMs 6 'Experimentar con este valor.
RA.2 = 0
'Muestro unidades de mil
mascara = LookUp(0x7e, 0xc, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0xe, 0xfe, 0xde), miles
PORTB = mascara
RA.3 = 1
WaitMs 6 'Experimentar con este valor.
RA.3 = 0
Goto fin_visualizar
'-----------------------------------------------------------------------
'-- MUESTRO FINAL DE CUENTA
'-----------------------------------------------------------------------
visualizar_a:
'muestro unidades_fin
mascara = LookUp(0x7e, 0xc, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0xe, 0xfe, 0xde, 0x80), unidad_fin
PORTB = mascara
RA.0 = 1
WaitMs 6 'Experimentar con este valor.
RA.0 = 0
'muestro decenas_fin
mascara = LookUp(0x7e, 0xc, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0xe, 0xfe, 0xde, 0x80), decena_fin
PORTB = mascara
RA.1 = 1
WaitMs 6 'Experimentar con este valor.
RA.1 = 0
'muestro centenas_fin
mascara = LookUp(0x7e, 0xc, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0xe, 0xfe, 0xde, 0x80), centena_fin
PORTB = mascara
RA.2 = 1
WaitMs 6 'Experimentar con este valor.
RA.2 = 0
'muestro miles_fin
mascara = LookUp(0x7e, 0xc, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0xe, 0xfe, 0xde, 0x80), miles_fin
PORTB = mascara
RA.3 = 1
WaitMs 6 'Experimentar con este valor.
RA.3 = 0
Goto fin_visualizar
'-----------------------------------------------------------------------
'-- MUESTRO "STOP"
'-----------------------------------------------------------------------
visualizar_b:
PORTB = 0xe6
RA.0 = 1
WaitMs 6 'Experimentar con este valor.
RA.0 = 0
PORTB = 0x7e
RA.1 = 1
WaitMs 6 'Experimentar con este valor.
RA.1 = 0
PORTB = 0xf0
RA.2 = 1
WaitMs 6 'Experimentar con este valor.
RA.2 = 0
PORTB = 0xda
RA.3 = 1
WaitMs 6 'Experimentar con este valor.
RA.3 = 0
fin_visualizar:
TMR0 = 254 'cargo TMR0 nuevamente
INTCON.T0IF = 0 'habilita nuevamente la interrupción
Resume