Documentos de Académico
Documentos de Profesional
Documentos de Cultura
LABORATORIO 2
Profesor: Alumno:
Jose Luis Rodriguez Andreilys Urbina
C.I 27.0.777.63
Figura 9. Comparación.
El registro 0x20 es el contador que nos indica la sincronización del registro
PORTD.
T1OSI
VDD T1OSI
VDD
AM/PM
RN1
RA0
1 16
A D1
2 15 LED-GREEN
RA1 B
3 14
RA2 C
4 13
RA3 D
5 12
RA4 E
6 11
RA5 F
7 10
RA6 G
8 9
G
RC7 AM/PM
D1
D2
D3
D4
D5
D6
A
B
C
D
E
F
1k
U1
2 15
RA0 RA0 RC0 T1OSO
3 16
RA1 RA1 RC1 T1OSI
4 17
RB0 RA2
5
RA2 RC2
18
BUZZER U2
RA3 RA3 RC3 LEDHora
6 23 2 3
RA4 RA4 RC4 LEDMinutos RD0 A1 Y1 D1
7 24 4 5
RA5 RA5 RC5 LedHoraAlarma RD1 A2 Y2 D2
14 25 6 7
RB1 RA6 RA6 RC6 LedMinutosAlarma RD2 A3 Y3 D3
13 26 10 9
RA7 RC7 RC7 RD3 A4 Y4 D4
12 11
RD4 A5 Y5 D5
33 19 14 13
RB0 RB0 RD0 RD0 RD5 A6 Y6 D6
34 20
RB2 RB1 RB1 RD1 RD1
35 21 1
RB2 RB2 RD2 RD2 OE1
36 22 15
RB3 RD3 RD3 OE2
37 27
RB4 RD4 RD4
38 28 74LS365
RB5 RD5 RD5
39 29
RB6/ICSPCLK RD6
40 30
D2 RB7/ICSPDAT RD7
8
LEDHORA RE0
9
RE1
LED-GREEN 10
RE2
1
RE3/MCLR/Vpp VDD U3 LS1
D3 PIC16F1787 2 3
BUZZER A1 Y1
4 5
LEDMINUTOS A2 Y2
6 7
A3 Y3
LED-GREEN 10 9
A4 Y4
12 11 SOUNDER
A5 Y5
14 13
D4 A6 Y6
1
LEDHORAALARMA OE1
15
OE2
LED-GREEN
74LS365
D5
LEDMINUTOSALARMA
LED-GREEN
bsf PORTC,RC7
goto PRINCIPAL
;programa principal
PRINCIPAL
banksel PORTB
btfss PORTB,RB0
goto AjusFlag ;Ajuste de la Bandera de entrada al Ajuste
del Reloj
btfss PORTB,RB1
goto AlarmFlag ;Ajuste de la Bandera de entrada al Ajuste
de la Alarma
btfss PORTB,RB2
goto Formato24h ;Hora Militar
btfsc 0x40,7
goto PCon ;Revision de la alarma si ya ha sido
configurada
movf 0x71,0
xorlw .2
btfsc STATUS,Z
goto AMPM ;Revision de la hora para activar el
Mañana/Tarde
bcf PORTC,RC3
bcf PORTC,RC4
bcf PORTC,RC5
bcf PORTC,RC6
goto PRINCIPAL
AMPM ;Revision de la hora para activar el Mañana/Tarde**
banksel PORTC
movf 0x70,0
xorlw .1
btfsc STATUS,Z
bsf PORTC,RC7
goto PRINCIPAL
;Rutinas de Interrupciones
Interrupciones
;Encuesta a la Interrupcion
btfsc INTCON,TMR0IF ;TMR0IF=?
call Barrido ;TMR0IF=1 el Timer0 se desbordo
banksel PIR1
btfsc PIR1,TMR1IF ;TRM1IF=?
call Segundos ;TMR1IF=1 ha pasado 1 seg
retfie
Barrido ;Barrido de los Displays**
banksel PORTA
call IniCompPD
btfsc 0x23,0
call MostrarA
btfss 0x23,0
call Mostrar
call ResTMR0
banksel 0x20
incf 0x20,1
movf 0x20,0
xorlw .6
btfsc STATUS,Z
clrf 0x20
return
Inibar ;Inicio del Barrido de displays
banksel PORTD
movlw .1
movwf PORTD
return
Rotacion ;Mueve un bit en Alto por todo el registro
bcf STATUS,C
call Finbar
rlf PORTD,1
return
Finbar ;Comprobacion de llegada al valor final del barrido
movf PORTD,0
xorlw 0x20
btfsc STATUS,Z
call Inibar
return
Mostrar ;Muestra los valores del reloj
banksel PORTA
movf 0x20,0
call Vertabla
movwf FSR0L
movf INDF0,0
call Tabla7seg
movwf PORTA
return
ResTMR0 ;Reinicia el retardo del Timer0
banksel TMR0
movlw .6
movwf TMR0
bcf INTCON,TMR0IF
return
IniCompPD ;Comparacion de la bandera 0x20 para la rotacion del registro
PORTD
banksel PORTD
movf 0x20,0
xorlw .0 ; Si 0x20=0 primera entrada de la Int por
TMR0
btfsc STATUS,Z
call Inibar ;0000|0001 -> RD0
movf 0x20,0
xorlw .1 ; Si 0x20=1
btfsc STATUS,Z
call Rotacion ;0000|0010 -> RD1
movf 0x20,0
xorlw .2 ; Si 0x20=2
btfsc STATUS,Z
call Rotacion ;0000|0100 -> RD2
movf 0x20,0
xorlw .3 ; Si 0x20=3
btfsc STATUS,Z
call Rotacion ;0000|1000 -> RD3
movf 0x20,0
xorlw .4 ; Si 0x20=4
btfsc STATUS,Z
call Rotacion ;0001|0000 -> RD4
movf 0x20,0
xorlw .5 ; Si 0x20=5
btfsc STATUS,Z
call Rotacion ;0010|0000 -> RD5 -> Final
return
Vertabla ;Tabla de los Registros asignados a los Displays
brw
retlw 0x70 ;D6 1 Digito de la Hora 0x20=0
retlw 0x71 ;D5 2 Digito de la Hora 0x20=1
retlw 0x72 ;D4 1 Digito de los Minutos 0x20=2
retlw 0x73 ;D3 2 Digito de los Minutos 0x20=3
retlw 0x74 ;D2 1 Digito de los Segundos 0x20=4
retlw 0x75 ;D1 2 Digito de los Segundos 0x20=5
Tabla7seg ;Anodo Comun
brw
retlw 0xC0 ;Cero
retlw 0xF9 ;Uno
retlw 0xA4 ;Dos
retlw 0xB0 ;Tres
retlw 0x99 ;Cuatro
retlw 0x92 ;Cinco
retlw 0x82 ;Seis
retlw 0xF8 ;Siete
retlw 0x80 ;Ocho
retlw 0x90 ;Nueve
;Reloj TMR1 y SUB-RUTINAS PARA LAS INTERRUPCIONES DEL
TIMER1**
Segundos ;Reloj y Contador
incf 0x75,1
call TruncarD1
call ResTMR1
banksel PIR1
bcf PIR1,TMR1IF
return
TruncarD1
movf 0x75,0
xorlw .10
btfsc STATUS,Z
call borrarD1
return
borrarD1
clrf 0x75
incf 0x74,1
call TruncarD2
return
TruncarD2
movf 0x74,0
xorlw .6
btfsc STATUS,Z
call borrarD2
return
borrarD2
clrf 0x74
incf 0x73,1
call TruncarD3
return
TruncarD3
movf 0x73,0
xorlw .10
btfsc STATUS,Z
call borrarD3
return
borrarD3
clrf 0x73
incf 0x72,1
call TruncarD4
return
TruncarD4
movf 0x72,0
xorlw .6
btfsc STATUS,Z
call borrarD4
return
borrarD4
clrf 0x72
incf 0x71,1
call TruncarD5
return
TruncarD5
movf 0x71,0
xorlw .10
btfsc STATUS,Z
call borrarD5
return
borrarD5
clrf 0x71
incf 0x70,1
call TruncarD6
return
TruncarD6
movf 0x70,0
xorlw .3
btfsc STATUS,Z
clrf 0x70
return
ResTMR1 ;Reinicio del TIMER1
banksel TMR1L
clrf TMR1L
movlw 0x80
movwf TMR1H
return
;SUB-RUTINAS DE LA ALARMA PARA LAS INTERRUPCIONES
MostrarA ;Muestra los valores de la alarma
call CambioA
banksel PORTA
movf 0x20,0
call VerTablaA
movwf FSR1L
movf INDF1,0
call Tabla7seg
movwf PORTA
return
CambioA ;Muestra el cambio en los segundos mientras se
configura la alarma
movf 0x75,0
movwf 0x35
movf 0x74,0
movwf 0x34
return
VerTablaA ;Registros que Mantendran la alarma
brw
retlw 0x30 ;D6
retlw 0x31 ;D5
retlw 0x32 ;D4
retlw 0x33 ;D3
retlw 0x34 ;D2
retlw 0x35 ;D1
;ajuste del reloj
AjusFlag ;Bandera de Ajuste del reloj
banksel PORTB
btfss PORTB,RB0
goto Retardo3S
goto PRINCIPAL
Retardo3S ;Retardo de 1s llamada 3 veces si se mantiene presionado el
boton
btfsc PORTB,RB0
goto PRINCIPAL
call Retardo1S
btfsc PORTB,RB0
goto PRINCIPAL
call Retardo1S
btfsc PORTB,RB0
goto PRINCIPAL
call Retardo1S
goto Hora ;Ajuste del Reloj
Hora ;Ciclo hasta que se cumpla la condicion
bsf PORTC,RC3
btfss PORTB,RB0
goto $-1
goto AjusteHora
AjusteHora ;Ajuste de la Hora
banksel PORTB
btfss PORTB,RB1
incf 0x71,1
call Hmax
btfss PORTB,RB0
goto Minutos
goto AjusteHora
Hmax
movf 0x71,0
xorlw .10
btfsc STATUS,Z
call Hmax0
return
Hmax0
clrf 0x71
incf 0x70,1
call Hmax1
return
Hmax1
movf 0x70,0
xorlw .2
btfsc STATUS,Z
clrf 0x70
return
Minutos ;Ciclo hasta que se cumpla la condicion
bcf PORTC,RC3
bsf PORTC,RC4
btfss PORTB,RB0
goto $-1
goto AjusteMinutos
AjusteMinutos ;Ajuste de los Minutos
btfss PORTB,RB1
incf 0x73,1
call Mmax
btfss PORTB,RB0
goto PRINCIPAL
goto AjusteMinutos
Mmax
movf 0x73,0
xorlw .10
btfsc STATUS,Z
call Mmax0
return
Mmax0
clrf 0x73
incf 0x72,1
call Mmax1
return
Mmax1
movf 0x72,0
xorlw .6
btfsc STATUS,Z
clrf 0x72
return
;AJUSTE DE LA ALARMA
AlarmFlag ;Bandera de ajuste de la alarma del reloj
banksel PORTB
btfss PORTB,RB1
goto Retardo2S
goto PRINCIPAL
Retardo2S ;Retardo de 1s llamada 2 veces si se mantiene presionado el
boton
btfsc PORTB,RB1
goto PRINCIPAL
call Retardo1S
btfsc PORTB,RB1
goto PRINCIPAL
call Retardo1S
goto HAlarma ;Ajuste de la Alarma
HAlarma
bsf 0x23,0
bsf PORTC,RC5
btfss PORTB,RB1
goto $-1
goto AjusteAlarma
AjusteAlarma;Ajuste de la Alarma
banksel PORTB
call VAHS
goto HAMinutos
VAHS ;Ajuste de la hora en la alarma
btfss PORTB,RB2
incf 0x31,1
call LimiteH
btfss PORTB,RB1
return
goto VAHS
LimiteH
movf 0x31,0
xorlw .10
btfsc STATUS,Z
call cleanH
return
cleanH
clrf 0x31
incf 0x30,1
call cleanH1
return
cleanH1
movf 0x30,0
xorlw .3
btfsc STATUS,Z
clrf 0x30
return
HAMinutos
bcf PORTC,RC5
bsf PORTC,RC6
btfss PORTB,RB1
goto $-1
goto Aminutos
Aminutos
call VAMIN
bsf 0x40,7
bcf 0x23,0
bcf PORTC,RC6
call AlarmaAMPM
goto PRINCIPAL
VAMIN ;Ajuste de los minutos en la alarma
btfss PORTB,RB2
incf 0x33,1
call LimiteM
btfss PORTB,RB1
return
goto VAMIN
LimiteM
movf 0x33,0
xorlw .10
btfsc STATUS,Z
call cleanM
return
cleanM
clrf 0x33
incf 0x32,1
call cleanM1
return
cleanM1
movf 0x32,0
xorlw .6
btfsc STATUS,Z
clrf 0x32
return
AlarmaAMPM
movf 0x31,0
xorlw .2
btfsc STATUS,Z
call MT
return
MT
movf 0x30,0
xorlw .1
btfsc STATUS,Z
bsf 0x36,0
return
PCon ;Revision de los registros de la hora y la alarma
banksel 0x30
movf 0x30,0
xorwf 0x70,0
btfsc STATUS,Z
bsf 0x40,0
movf 0x31,0
xorwf 0x71,0
btfsc STATUS,Z
bsf 0x40,1
movf 0x32,0
xorwf 0x72,0
btfsc STATUS,Z
bsf 0x40,2
movf 0x33,0
xorwf 0x73,0
btfsc STATUS,Z
bsf 0x40,3
movf 0x36,0
xorlw .1
btfsc STATUS,Z
bsf 0x40,4
movf 0x40,0
xorlw 0x9F
btfsc STATUS,Z
goto Alarma
goto PRINCIPAL
Alarma
movlw .10
movwf 0x41
bsf PORTC,RC2
call Retardo10S
bcf PORTC,RC2
goto PRINCIPAL
Retardo10S
btfss PORTB,RB0
return
btfss PORTB,RB1
return
btfss PORTB,RB2
return
call Retardo1S
decfsz 0x41,1
goto Retardo10S
return
;RETARDO DE 1 SEGUNDO**
Retardo1S ;Sub-rutina de retardo de 1 Segundo
movlw .5 ; 1cm --> Valor de N
movwf 0x7D ; 1cm
Empiezo
movlw .255 ; 1cm*N --> Valor de M
movwf 0x7E ; 1cm*N
Bucle
movlw .255 ; --> 1cm*N*M -->Valor de P
movwf 0x7F ; --> 1cm*N*M
Repite
decfsz 0x7F,1; -->(P-1)*M*N + 2M*N
goto Repite ; -->(P-1)*M*N*2
decfsz 0x7E,1 ;-->(M-1)*N+ 2N
goto Bucle ; --> (M-1)*2*N
decfsz 0x7D,1 ;--> (N-1) + 2cm
goto Empiezo ;--> (N-1)*2
return
;HORA MILITAR**
Formato24h ;Hora Militar
banksel PORTC
bsf 0x22,0
btfss PORTC,RC7
goto PRINCIPAL
movf 0x71,0
xorlw .0
btfsc STATUS,Z
call Zero
call Num
movf 0x21,0
andlw 0x0F
movwf 0x77
movf 0x21,0
andlw 0xF0
movwf 0x76
swapf 0x76,1
call Cambio
call ciclo
call RetCambio
clrf 0x22
goto PRINCIPAL
Cambio ;Cambio de los valores para Muestreo
movf 0x70,0
movwf 0x7A
movf 0x71,0
movwf 0x7B
movf 0x76,0
movwf 0x70
movf 0x77,0
movwf 0x71
return
RetCambio ;Registro auxiliares de Guardados
movf 0x7A,0
movwf 0x70
movf 0x7B,0
movwf 0x71
return
ciclo ;Boton RB2 sigue Presionado
banksel PORTA
btfsc PORTB,RB2
return
goto ciclo
Zero ;Si D5=0x75=0 al pasar a hora militar
incf 0x7C,1
movf 0x70,0
movwf 0x76
xorlw .1
btfsc STATUS,Z
call Dos
return
Num ;Si D5=es un numero cualquiera
movf 0x7C,0
xorlw .1
btfsc STATUS,Z
return
movf 0x71,0
decf WREG,1
call TablaHoraria
movwf 0x21
return
Dos ;Se asigna 2 a los registros auxiliares para la hora militar
movlw 0x22
movwf 0x21
return
TablaHoraria ;Tabla que Contiene los valores de la hora en Formato
Digital
brw ; D6 | D5
retlw 0x13 ; W=0 -> 0001|0011 -> 01
retlw 0x14 ; W=1 -> 0001|0100 -> 02
retlw 0x15 ; W=2 -> 0001|0101 -> 03
retlw 0x16 ; W=3 -> 0001|0110 -> 04
retlw 0x17 ; W=4 -> 0001|0111 -> 05
retlw 0x18 ; W=5 -> 0001|1000 -> 06
retlw 0x19 ; W=6 -> 0001|1001 -> 07
retlw 0x20 ; W=7 -> 0010|0000 -> 08
retlw 0x21 ; W=8 -> 0010|0001 -> 09
retlw 0x22 ; W=9 -> 0010|0010 -> 10
retlw 0x23 ; W=10 -> 0010|0011 -> 11
;
end