TODOPIC
Microcontroladores PIC => Almacén del Assembler => Mensaje iniciado por: Andres71 en 26 de Febrero de 2013, 11:33:26
-
Tengo este codigo que lo hice en Mplab Vr 6 hace años y ahora lo necesito lo compile nuevamente en el Mplab Vr 8 y no funciona no me entra el programa a las INTs, solo tengo activa la INT de cambio de estado en RB4-RB7, pensando que fuera el MPLAB, instale nuevamente la vieja version y tampoco funciona, la verdad ya no se que mas buscarle, me ayudan? uso solo las entradas RB4 y RB5 y tengo varias salidas, la idea es una secuencia especial dependiendo de los 4 posibles estados de RB4-RB5, y un led monitor de estado, gracias
;**********************************************************************
list p=16F628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_ON & _DATA_CP_ON & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF
;********REG USO GENERAL********************************************
ON EQU 0
STAR EQU 1
GUN EQU 3
OK EQU 4
CHANGE EQU 20
PDel0 EQU 21
PDel1 EQU 22
w_temp EQU 23
status_temp EQU 24
TEMPO EQU 25
TEMPO_INTEN EQU 26
;**********************************************************************
RESET ORG 0x00 ; processor reset vector
goto MAIN ; go to beginning of program
;********************ATENCION A LAS INTERRUPCIONES*****************************
ORG 0x04 ; interrupt vector location
GOTO INT
INT movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
BTFSC INTCON,0 ; SE ACTIVO POR CAMBIO EN ENTRADAS?
GOTO CAMBIO
GOTO SAL_INT ;NINGUNO DE LOS DOS
CAMBIO BSF CHANGE,0
GOTO SAL_INT
SAL_INT movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
BCF INTCON,0 ;BORRO LA BANDERA
RETFIE ; return from interrupt
;*********************************************************************************
MAIN CLRF INTCON ;DESHABILITO TODAS LAS INTs
BSF STATUS,5
BCF STATUS,6 ;BANCO 1
MOVLW 0XFF
MOVWF TRISB ;PORTB RB4-RB7 =ENTRADAS
CLRF TRISA ;PORTA SALIDAS
CLRF PIE1
BSF OPTION_REG,7 ;DESHAB PULLUP
BSF OPTION_REG,6
BCF STATUS,5 ;BANCO 0
CLRF PIR1
MOVLW 0X07
MOVWF CMCON ;DESCONECTO LOS COMPARADORES DE TENSION DEL PORTA
CLRF PORTA ;BORRO TODAS LAS SALIDAS
CLRF CHANGE
CALL DEMORA
CALL DEMORA
CALL DEMORA
CALL DEMORA
CALL DEMORA ;ESPERO 1 SEGUNDO A NORMALIZAR TODO
CALL ACCIONAR
MOVLW 0X88
MOVWF INTCON ;ACTIVO LAS INTs RB4-RB7 Y RB0
LOOP BCF PORTA,OK
CALL DEMORA ;LED ESTADO OK PARAPADEANDO
CALL DEMORA
CALL DEMORA
CALL DEMORA
BSF PORTA,OK
BTFSC CHANGE,0
GOTO ACCIONAR
CALL DEMORA
CALL DEMORA
CALL DEMORA
CALL DEMORA
CALL DEMORA
CALL DEMORA
BTFSC CHANGE,0
GOTO ACCIONAR
GOTO LOOP
;*************************************************************************************************
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%SUBRUTINA ACCIONAR %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ACCIONAR BCF CHANGE,0
SWAPF PORTB,0 ;CARGO ENTRADAS Y COLOCO EN BITS DE MENOR PESO
ANDLW 0X03 ;BORRO LOS 6 BITS DE MAYOR PESO
ADDWF PCL,1
GOTO OFF_TOTAL
GOTO ARRANCAR
GOTO LOOP
GOTO ON_REPOSO
;*****************************************
OFF_TOTAL CLRF PORTA ;APAGO TODO FIN DE TODO
GOTO LOOP
;*****************************************
ARRANCAR MOVLW .5
MOVWF TEMPO_INTEN
LOOP_INI BSF PORTA,ON ;ON PLANTA
BSF PORTA,STAR ;INICIO ARRANQUE 2.5 SEGUNDOS
BSF PORTA,GUN
MOVLW .15
MOVWF TEMPO
LOOP_ST1 CALL DEMORA
DECFSZ TEMPO,1
GOTO LOOP_ST1
BCF PORTA,STAR ;APAGO ARRANQUE Y ESPERO 1SEG
BCF PORTA,GUN
MOVLW .15
MOVWF TEMPO
LOOP_ST2 CALL DEMORA
DECFSZ TEMPO,1
GOTO LOOP_ST2
DECFSZ TEMPO_INTEN,1
GOTO LOOP_INI
BCF PORTA,ON ;TERMINARON LOS 5 INTENTOS, EXISTE FALLO DE ARRANQUE APAGO TODO Y DOY ALARMA
GOTO FALL_STAR
FALL_STAR BCF INTCON,7 ;DESHABILITO TODAS LAS INTS
BCF PORTA,OK
CALL DEMORA ;LED INDICANDO FALLO DE ARRANQUE
BSF PORTA,OK
CALL DEMORA
GOTO FALL_STAR
;***************************************************************************************************************************
ON_REPOSO BSF PORTA,ON
BCF PORTA,STAR
BCF PORTA,GUN
GOTO LOOP
;***************************************************************************************************************************
;***************************************************************************************************************************
;******************************RUTINA DE DEMORA DE 200mSEG************************************
DEMORA movlw .156 ; 1 set numero de repeticion (B)
movwf PDel0 ; 1 |
PLoop1 movlw .213 ; 1 set numero de repeticion (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
PDelL3 goto PDelL4 ; 2 ciclos delay
PDelL4 clrwdt ; 1 ciclo delay
return ; 2+2 Fin.
;***********************************************************************************************
END ; directive 'end of program'
-
No activas las interrupciones, porque en MAIN la configuracion de INTCON esta al final y no llega ahi:
MAIN CLRF INTCON ;DESHABILITO TODAS LAS INTs
BSF STATUS,5
BCF STATUS,6 ;BANCO 1
MOVLW 0XFF
MOVWF TRISB ;PORTB RB4-RB7 =ENTRADAS
CLRF TRISA ;PORTA SALIDAS
CLRF PIE1
BSF OPTION_REG,7 ;DESHAB PULLUP
BSF OPTION_REG,6
BCF STATUS,5 ;BANCO 0
CLRF PIR1
MOVLW 0X07
MOVWF CMCON ;DESCONECTO LOS COMPARADORES DE TENSION DEL PORTA
CLRF PORTA ;BORRO TODAS LAS SALIDAS
CLRF CHANGE
CALL DEMORA
CALL DEMORA
CALL DEMORA
CALL DEMORA
CALL DEMORA ;ESPERO 1 SEGUNDO A NORMALIZAR TODO
CALL ACCIONAR
[b] MOVLW 0X88 ;AQUI NO LLEGA[/b]
MOVWF INTCON ;ACTIVO LAS INTs RB4-RB7 Y RB0[/b]
Pon esto antes de CALL ACCIONAR:
MOVLW 0X88
MOVWF INTCON
En la interrupcion al principio mejor asi:
Inicio_ISR
movwf W_Temp ; Copiamos W a un registro Temporal.-
swapf STATUS, W ; Invertimos los nibles del registro STATUS.-
movwf STATUS_Temp ; Guardamos STATUS en un registro temporal.-
Otra cosa, tu chequeas que fue interrupcion en PORTB pero no miras si fue por RB4 o RB5????
-
Gracias Tapi8, mil gracias ya vi el error, ademas llamaba una subrutina que no existia la de ACCIONAR que realmente es una parte del codigo, ya esta oK, nuevamente mil gracias, chauuuuuuuuuuu
:-/
:-/
:-/
((:-)) ((:-)) ((:-))
PD: eso me pasa por trabajar hasta tarde, comienza uno a volverse necio, chauuuuu
-
Ahhhhhhhh no puede ser, ahora lo paso a un PIC16F84A y las INTs nuevamente no funcionan, ME VOY A VOLVER LOCOOOOOOOO, el codigo queda asi donde estara la falla???
;**********************************************************************
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;********REG USO GENERAL********************************************
w_temp EQU 0C
status_temp EQU 0D
PDel0 EQU 0E
PDel1 EQU 0F
ESTADO EQU 10
TEMPO_INTEN EQU 11
TEMPO EQU 12
PCLATH_TEMP EQU 13
ON EQU 0
STAR EQU 1
GUN EQU 3
OK EQU 4
CHG EQU 0
reset org 0
goto MAIN ;vaya al inicio
org 4 ;aqui viene la Interrupcion
goto INT ;vaya a atender las INT
;********************ATENCION A LAS INTERRUPCIONES*****************************
INT movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
BTFSC INTCON,0
GOTO MARCAR ;SE ACTIVO LA INT TMR0
GOTO SAL_INT
MARCAR BSF ESTADO,CHG ;MARCO CAMBIO
SAL_INT movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
BCF INTCON,0 ;BORRO FLAG
retfie ; return from interrupt
;**********************FIN ATENCION DE LAS INTERRUPCIONES**************************************************
MAIN BSF STATUS,5 ;BANCO 1
MOVLW 0X00
MOVWF TRISA ;Salidas
MOVLW 0XFF
MOVWF TRISB ;Entradas
MOVLW 0X80
MOVWF OPTION_REG ;SIN RBPULL
BCF STATUS,5 ;BANCO 0
CLRF PORTA
BCF ESTADO,CHG
CALL DEMORA
CALL DEMORA
CALL DEMORA ;ESPERO 600 mS PARA ESTABILIZAR VCC
MOVLW 0X88
MOVWF INTCON ;HABILI INTs PORTB
GOTO ACCIONAR
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%SUBRUTINA ACCIONAR %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ACCIONAR SWAPF PORTB,0 ;CARGO ENTRADAS Y COLOCO EN BITS DE MENOR PESO
ANDLW 0X03 ;BORRO LOS 6 BITS DE MAYOR PESO
ADDWF PCL,1
GOTO OFF_TOTAL
GOTO ARRANCAR
GOTO NO_OPERE
GOTO ON_REPOSO
;*****************************************
OFF_TOTAL BCF PORTA,ON ;APAGO TODO FIN DE TODO
BCF PORTA,STAR
BCF PORTA,GUN
BCF ESTADO,CHG
GOTO LOOP
;*****************************************
ARRANCAR MOVLW .5
MOVWF TEMPO_INTEN
LOOP_INI BSF PORTA,ON ;ENCIENDO PLANTA
BSF PORTA,STAR ;INICIO ARRANQUE 2.5 SEGUNDOS
BSF PORTA,GUN
MOVLW .15
MOVWF TEMPO
LOOP_ST1 CALL DEMORA
DECFSZ TEMPO,1
GOTO LOOP_ST1
BCF PORTA,STAR ;APAGO ARRANQUE Y ESPERO 1SEG
BCF PORTA,GUN
MOVLW .15
MOVWF TEMPO
LOOP_ST2 CALL DEMORA
DECFSZ TEMPO,1
GOTO LOOP_ST2
DECFSZ TEMPO_INTEN,1
GOTO LOOP_INI
BCF PORTA,ON ;TERMINARON LOS 5 INTENTOS, EXISTE FALLO DE ARRANQUE APAGO TODO Y DOY ALARMA
BCF ESTADO,CHG
GOTO FALL_STAR
FALL_STAR CLRF INTCON
BCF PORTA,OK
CALL DEMORA ;LED INDICANDO FALLO DE ARRANQUE
BSF PORTA,OK
CALL DEMORA
GOTO FALL_STAR
;***************************************************************************************************************************
NO_OPERE BCF PORTA,ON
BCF PORTA,STAR
BCF PORTA,GUN
BCF ESTADO,CHG
GOTO LOOP
;***************************************************************************************************************************
ON_REPOSO BSF PORTA,ON
BCF PORTA,STAR
BCF PORTA,GUN
BCF ESTADO,CHG
GOTO LOOP
;***************************************************************************************************************************
LOOP BCF PORTA,OK
CALL DEMORA
CALL DEMORA
CALL DEMORA
BSF PORTA,OK
BTFSC ESTADO,CHG
CALL ACCIONAR
CALL DEMORA
CALL DEMORA
CALL DEMORA
CALL DEMORA
CALL DEMORA
BTFSC ESTADO,CHG
CALL ACCIONAR
GOTO LOOP
;***************************************************************************************************************************
;-----------------------RUTINA DE DEMORA 200mSEG------------------------------------
DEMORA movlw .156 ; 1 set numero de repeticion (B)
movwf PDel0 ; 1 |
PLoop1 movlw .213 ; 1 set numero de repeticion (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
PDelL3 goto PDelL4 ; 2 ciclos delay
PDelL4 clrwdt ; 1 ciclo delay
return ; 2+2 Fin.
;-----------------------------------------------------------------------------------
END ; directive 'end of program'
-
Me parece que estas configurando al reves el trisa y trisb
MAIN BSF STATUS,5 ;BANCO 1
MOVLW 0X00
MOVWF TRISA ;ENTRADAS
MOVLW 0XFF
MOVWF TRISB ;SALIDAS
segun el codigo el puerto a es todo salida y el port b todo entrada, es asi? sino simulaloo en el mplab
-
Saludos, gracias asi estan bien, lo que esta mal puesto son los comentarios PORTA=SALIDAS y PORTB=ENTRADAS, gracias
PD: correjido
Al parecer lo que tengo mal es que en la Rutina de atencion a las INTs no leeo el puertoB y eso hace que entre y se quede en un bucle al salir, segun lei DEBO SI O SI leer el puertoB antes de borra el FLAG, hare cambios a ver, chauuuuuuuuuu
-
Bueno definitivamente era eso, Se debe LEER el PORTB SI o SI dentro de la rutina de atencion a las Interrupciones si no se hace, al salir se activa la misma INT aunque se haya borrado el FLAG correspondiente (Intcon, 0) y se queda en un bucle, el problema hasta hoy no lo habia notado es mas no sabia que existia esa posibilidad porque siempre que use la INT por cambio de estado en RB4-RB7 su atencion la hacia en la misma rutina de interrupciones, en este programa en particular NO LO HAGO, lo hago por fuera de la rutina de interrupciones por ende en la rutina NO LEO el PORTB NUNCA y ese es el problema, SOLUCION cambiar mi codigo y leer el puerto y hacer lo que hacia afuera en la Rutina de interrupciones, chauuuuuuuuuuuuu