Autor Tema: INTERRUPCION TIMER0 CON 16F870  (Leído 1994 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado ALSAMA

  • PIC10
  • *
  • Mensajes: 6
INTERRUPCION TIMER0 CON 16F870
« en: 23 de Junio de 2005, 18:43:00 »
HOLA

TENGO UN PROBLEMA CON LA INTERRUPCION DEL TIMER0, SE QUEDA PEGADA Y NO HE PODIDO HACERLO FUNCIONAR.

NECESITO MEDIR UN LAPSO DE TIEMPO Y DESPUES EJECUTAR UNA FUNCION, PARA REGRESAR AL PROGRAMA PRINCIPAL.

LA MEDIDA DE TIEMPO SE DEBE HACER MINETRAS EL PIC HACE OTRAS FUNCIONES

SI ALGUIEN SABE COMO PUEDO SOLUCIONAR ESTE PROBLEMA, POR FAVOR ENVIARME LA INFORMACION A albertoei@tutopia.com

GRACIAS POR LA AYUDA Y POR SU TIEMPO

Desconectado fenix_jn

  • PIC18
  • ****
  • Mensajes: 418
RE: INTERRUPCION TIMER0 CON 16F870
« Respuesta #1 en: 24 de Junio de 2005, 01:44:00 »
Se t ayudaria si postearas el programa q estas usando... de otra forma solo nos keda adivinar

Desconectado antoniof

  • Moderadores
  • PIC24F
  • *****
  • Mensajes: 729
RE: INTERRUPCION TIMER0 CON 16F870
« Respuesta #2 en: 24 de Junio de 2005, 03:30:00 »
Es cierto que sin el código fuente no te podemos ayudar ya que ay miles de aplicaciones para las que se puede utilizar el TMR0. Te dejo un ejemplo de cómo utilizarlo y configurarlo:

;Programa

   org   0x00      ;Vector de reset
   
   goto   inicio

   org   0x04      ;Vector de interrupción
   
   movwf   w_temp      ;Copy W to TEMP register
   swapf   status,w   ;Swap status to be saved into W
   clrf   status      ;bank 0, regardless of current bank, Clears IRP,RP1,RP0
   movwf   status_temp   ;Save status to bank zero STATUS_TEMP register
   movf   pclath,w   ;Only required if using pages 1, 2 and/or 3
   movwf   pclath_temp   ;Save PCLATH into W
   clrf   pclath      ;Page zero, regardless of current page
   goto   isr      ;Salta a la rutina de interrupción

;*****************************************************************
;
;      Subrrutina de tratamiento de interrupción
;
;*****************************************************************      
   
isr   btfsc   intcon,2   ;Comprueba si la interrupción ha sido el tmr0
   goto   tmr0_if
   goto   int_fin
   
tmr0_if   bcf   intcon,2   ;Borra el flag de interrupción T0IF
   movlw   d"216"
   movwf   tmr0_op      ;Vuelve a cargar el valor en el temporizador

;***********
;Aqui haces lo que tengas que hacer cada vez que la interrupción salte
;***********

int_fin   movf   pclath_temp,w   ;Restore PCLATH
   movwf   pclath      ;Move W into PCLATH
   swapf   status_temp,w   ;Swap STATUS_TEMP register into W (sets bank to original state)
   movwf   status      ;Move W into STATUS register
   swapf   w_temp,f   ;Swap W_TEMP
   swapf   w_temp,w   ;Swap W_TEMP into W
   retfie         ;Fin de interrupción   

;*****************************************************************
;
;      Programa principal
;
;*****************************************************************      

;Inicio de los puertos/registros del PIC

inicio   bsf   status,5   ;Banco 1
   movlw   b"00000111"   ;Configura el registro "option"
   movwf   tmr0_op      ;RBPU ON, Fosc/4, TMR0, 1:256 --> Cada unidad del TMR0 suponen 51.2us @ 20MHz   
   bcf   status,5
   movlw   d"216"
   movwf   tmr0_op      ;Valor a cargar para que se desborde a los 2048us   
   movlw   0x20
   movwf   intcon      ;Interrupción por desbordamiento del tmr0 activada
   bsf   intcon,gie   ;Permiso global de interrupciones activado

;Bucle principal

fin   goto   fin

;En vez del fin goto fin, pegas el programa principal de tu aplicación

   end