WizStefan
Newbie level 3
pic18f4550
Hi everybody!
I'm working on a clock for a university practice. I'm using two interruptions on the pic; one by timer0, that happens every 1 second and is used as my base time, and another one by timer1, that happens every 10ms and is used to multiplex between my 4 seven segment displays. The problem is that only the first interruption is happening (at 10ms) then it gets out of the interruption, and continue with the program and doesn't care about any other interruption anymore... I'm clearing the interrupt flag bit on every timer once the interruption ends, and even re-setting the enable bits for every interruption at the end too (although it's not even necessary)... I'm stuck on this, and don't know what else to do, the simulation on Proteus works perfect, i don't get any error there =S
Can anyone give me any advice? Sorry for the bad english =)
Added after 23 minutes:
This is the code that's giving me problems, the name of the functions and the comments are on spanish, sorry for that =)
This is the initial configuration:
And this is the code for the interruptions, there's two types of multiplexation because you can set the pic to show you 'Minutes-Seconds' or 'Hours-Minutes':
Hi everybody!
I'm working on a clock for a university practice. I'm using two interruptions on the pic; one by timer0, that happens every 1 second and is used as my base time, and another one by timer1, that happens every 10ms and is used to multiplex between my 4 seven segment displays. The problem is that only the first interruption is happening (at 10ms) then it gets out of the interruption, and continue with the program and doesn't care about any other interruption anymore... I'm clearing the interrupt flag bit on every timer once the interruption ends, and even re-setting the enable bits for every interruption at the end too (although it's not even necessary)... I'm stuck on this, and don't know what else to do, the simulation on Proteus works perfect, i don't get any error there =S
Can anyone give me any advice? Sorry for the bad english =)
Added after 23 minutes:
This is the code that's giving me problems, the name of the functions and the comments are on spanish, sorry for that =)
This is the initial configuration:
Code:
; Directivas de inicio
LIST P=PIC18F4550
#include <P18F4550.INC>
;---------------------------------------------------
; Configuracion
CONFIG WDT = OFF ; Guardián desactivado
CONFIG FOSC = HS ; Operación con Oscilador de alta velocidad externo.
CONFIG BOR = OFF
CONFIG MCLRE = OFF ; Pin 1 como Master reset, RE3 desabilitada
CONFIG LVP = OFF ; Programación de bajo voltaje desactivada
;---------------------------------------------------
; Declaracion de variables
j equ 0x8A ;
k equ 0x8E ; Constantes usadas en la
l equ 0x8F ; funcion de demora
m equ 0x90 ;
seg1 equ 0x92 ;
seg2 equ 0x93 ;
min1 equ 0x94 ;
min2 equ 0x95 ;
hor1 equ 0x96 ;
hor2 equ 0x97 ;
modomux equ 0x98 ;
aux equ 0x9D ;
aux2 equ 0x99 ;
;---------------------------------------------------
; Vectores de inicio e interrupciones
ORG 0x00 ; Vector de inicio
goto INICIO ;
ORG 0x08 ;
movwf aux2 ;
btfsc INTCON,TMR0IF ; Vector de interrupcion
goto Reloj ;
btfsc PIR1,TMR1IF ;
goto Multiplexacion ;
goto fin_interrupcion ;
;---------------------------------------------------
INICIO:
clrf LATA ;
clrf LATB ; Limpieza de latch de todos
clrf LATC ; los puertos
clrf LATD ;
clrf LATE ;
clrf PORTA ;
clrf PORTB ;
clrf PORTC ; Limpieza de los puertos
clrf PORTE ;
clrf PORTD ;
movlw b'00000000' ;
movwf TRISB ;
movlw b'00000000' ; Configuracion de los puertos
movwf TRISC ; B, C y D como salida, y RA0
movlw b'00000000' ; RA1 y RA2 como entradas
movwf TRISD ;
movlw b'00001111' ;
movwf TRISA ;
movlw b'00000000'
movwf TRISE ;
movlw b'00001111' ; Configuracion de RA0, RA1 y
movwf ADCON1 ; RA2 como entradas digitalesoo
movlw b'11100000' ; interrupciones, de la prioridad
movwf INTCON ; de las interrupciones y de la
movlw 0xf0 ; Carga el numero de 16 bits
movwf TMR0H ; 61629 en hexadecimal al registro
movlw 0xbd ; de timer0
movwf TMR0L ;
movlw b'10000111' ; Carga el preescalar del timer0
movwf T0CON ; a 256 y activa el timer0
movlw 0xfd ; Carga el numero de 16 bits
movwf TMR1H ; en hexadecimal al registro
movlw 0x8f ; de timer1
movwf TMR1L ;
movlw b'10110001' ; Carga el preescalar del timer1
movwf T1CON ; a 1 y activa el timer1
bsf PIE1,.0
bsf PORTE,.0 ;
movlw .0 ;
movwf seg1 ;
movwf seg2 ;
movwf min1 ;
movwf min2 ;
movlw .1 ;
movwf hor2 ;
movlw .2 ;
movwf hor1 ;
And this is the code for the interruptions, there's two types of multiplexation because you can set the pic to show you 'Minutes-Seconds' or 'Hours-Minutes':
Code:
;-------------------------------------------------------------------------
; Interrupciones
Multiplexacion:
bcf PIR1,TMR1IF ; Pone a cero la bandera timer1
movlw 0xfd ;
movwf TMR1H ; Vuelve a cargar el valor
movlw 0x8f ; 55536 en el timer1
movwf TMR1L ;
btfss modomux,.0 ;
goto min_seg0 ; Para modomux = 0
goto hor_min0 ; Para modomux = 1
min_seg0:
btfsc PORTE,.0
goto min_seg1
btfsc PORTE,.1
goto min_seg2
btfsc PORTE,.2
goto min_seg3
btfsc PORTC,.2
goto min_seg4
min_seg1:
bcf PORTE,.0
bsf PORTE,.2
movff seg2,aux ;
rlncf aux,0 ;
call Tabla ;
movwf PORTD ;
goto fin_interrupcion
min_seg2:
bcf PORTE,.1
bsf PORTE,.2
movff min1,aux ;
rlncf aux,0 ;
call Tabla ;
movwf PORTD ;
goto fin_interrupcion
min_seg3:
bcf PORTE,.2
bsf PORTC,.2
movff min2,aux ;
rlncf aux,0 ;
call Tabla ;
movwf PORTD ;
goto fin_interrupcion
min_seg4:
bcf PORTC,.2
bsf PORTE,.0
movff seg1,aux ;
rlncf aux,0 ;
call Tabla ;
movwf PORTD ;
goto fin_interrupcion
hor_min0
btfsc PORTE,.0
goto hor_min1
btfsc PORTE,.1
goto hor_min2
btfsc PORTE,.2
goto hor_min3
btfsc PORTC,.2
goto hor_min4
hor_min1:
bcf PORTE,.0
bsf PORTE,.2
movff min2,aux ;
rlncf aux,0 ;
call Tabla ;
movwf PORTD ;
goto fin_interrupcion
hor_min2:
bcf PORTE,.1
bsf PORTE,.2
movff hor1,aux ;
rlncf aux,0 ;
call Tabla ;
movwf PORTD ;
goto fin_interrupcion
hor_min3:
bcf PORTE,.2
bsf PORTC,.2
movff hor2,aux ;
rlncf aux,0 ;
call Tabla ;
movwf PORTD ;
goto fin_interrupcion
hor_min4:
bcf PORTC,.2
bsf PORTE,.0
movff min1,aux ;
rlncf aux,0 ;
call Tabla ;
movwf PORTD ;
goto fin_interrupcion
Reloj:
bcf INTCON,TMR0IF ; Pone a cero la bandera timer0
movlw 0xf0 ;
movwf TMR0H ; Vuelve a cargar el valor
movlw 0xbd ; 61629 en el timer0
movwf TMR0L ;
movlw .9 ;
cpfseq seg1 ;
goto SumarSeg1 ;
clrf seg1 ;
movlw .5 ;
cpfseq seg2 ;
goto SumarSeg2 ;
clrf seg2 ;
movlw .9 ;
cpfseq min1 ;
goto SumarMin1 ;
clrf min1 ;
movlw .5 ;
cpfseq min2 ;
goto SumarMin2 ;
clrf min2 ;
movlw .1 ;
cpfseq hor2 ;
goto SumarHor1_01 ; Cuando hor2 = 0
goto SumarHor1_11 ; Cuando hor2 = 1
SumarSeg1:
movlw .1 ;
addwf seg1 ;
goto fin_interrupcion
SumarSeg2:
movlw .1 ;
addwf seg2 ;
goto fin_interrupcion
SumarMin1:
movlw .1 ;
addwf min1 ;
goto fin_interrupcion
SumarMin2:
movlw .1 ;
addwf min2 ;
goto fin_interrupcion
SumarHor1_01:
movlw .9 ;
cpfseq hor1 ;
goto SumarHor1_02 ;
clrf hor1 ;
movlw .1 ;
movwf hor2 ;
goto fin_interrupcion
SumarHor1_02:
movlw .1 ;
addwf hor1 ;
goto fin_interrupcion
SumarHor1_11:
movlw .2 ;
cpfseq hor1 ;
goto SumarHor2 ;
movlw .1 ;
movwf hor1 ;
clrf hor2 ;
goto fin_interrupcion
SumarHor2:
movlw .1 ;
addwf hor1 ;
goto fin_interrupcion
;-------------------------------------------------------------------------
; Otros
Cambio:
movlw .15
call Demora
btfss PORTA,.3
goto Cambio
btg modomux,0
return
fin_interrupcion:
bsf PORTC,.6
bcf PIR1,TMR1IF ; Pone a cero la bandera timer1
bsf INTCON,TMR0IE
bsf PIE1,TMR1IE
movf aux2,0
retfie
fin_call:
return
;-------------------------------------------------------------------------
; Tabla
Tabla:
addwf PCL,1
retlw b'11000000'
retlw b'11111001'
retlw b'10100100'
retlw b'10110000'
retlw b'10011001'
retlw b'10010010'
retlw b'10000011'
retlw b'10111000'
retlw b'10000000'
retlw b'10011000'