16F628A encaprichado ¿me pueden ayudar?

Hola,

Estoy intentando programar un 628A para que realice una secuencia simple de acciones:

Poner en alto RB3 Esperar un par de segundos Poner en bajo RB3

y en un bucle infinito...

Si RB0 se pone en bajo Poner en alto RA2 Esperar un par de segundos Poner en bajo RA2

Poner en alto RB4 Esperar un par de segundos Poner en bajo RB4

Poner en alto RA3 Esperar un par de segundos Poner en bajo RA3

El problema es que cuando lo pruebo, pone RB3 en alto y queda as=ED sin hacer nada m=E1s, ni aunque le llegue un bajo por RB0.

Prob=E9 con dos c=F3digos, uno en assembler y otro en c con el PCW de CCS, los dos se comportan igual.

Este es es c=F3digo del MPLAB:

;**********************************************************************

list p=3D16f628a ; list directive to define processor #include ; processor specific variable definitions radix hex

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _LVP_OFF

T4SD0 equ 0x22 T4SD1 equ 0x23 T1SD0 equ 0x25 T1SD1 equ 0x26 T1SD2 equ 0x27 PDel0 equ 0x28 PDel1 equ 0x29

;**********************************************************************

org 0x00 ; processor reset vector goto Inicio ; go to beginning of program org 0x05

;**********************************************************************

Inicio movlw 0x07 ;Turn comparators off and movwf CMCON ;enable pins for I/O functions bcf STATUS,RP1 bsf STATUS,RP0 ; cambio al banco 1 --------- movlw 0x01 ; habilito RB0... movwf TRISB ; en el PORTB, como entrada bsf PCON, 3 bcf STATUS,RP1 bcf STATUS,RP0 ; vuelvo al banco 0 --------- clrf PORTA clrf PORTB ;--------------------------------------------------------- bsf PORTB, 3 ; inicia el encendido del celular ;call Tmp4Seg ; cuenta 4 segundos call PDelay ; Delay 5000 cycles (including call+return) bcf PORTB, 3 ; finaliza el encendido del celular goto Dormir

;**********************************************************************

Dormir btfsc PORTB, 0 ; verifica un evento... goto Dormir ; si NO hay evento, vuelve a dormir ;call Tmp4Seg ; si HAY un evento, espera 4 segundos... call PDelay ; Delay 5000 cycles (including call+return) btfsc PORTB, 0 ; ...y vuelve a verificar si existe el evento... goto Dormir ; si NO hay evento, vuelve a dormir call Llamar ; si HAY un evento, llama goto Dormir

;**********************************************************************

Llamar bsf PORTA, 2 ; activa el clear 1 call Tmp1Seg ; espera 1 segundo bcf PORTA, 2 ; desactiva el clear 1

bsf PORTB, 4 ; activa el clear 2 call Tmp1Seg ; espera 1 segundo bcf PORTB, 4 ; desactiva el clear 2

bsf PORTA, 3 ; activa el redial ;call Tmp4Seg ; espera 4 segundos call PDelay ; Delay 5000 cycles (including call+return) bcf PORTA, 3 ; desactiva el redial

return

;**********************************************************************

Tmp4Seg movlw .55 ; 1 set number of repetitions (B) movwf T4SD0 ; 1 | Tmp4SegL1 movlw .181 ; 1 set number of repetitions (A) movwf T4SD1 ; 1 | Tmp4SegL2 clrwdt ; 1 clear watchdog clrwdt ; 1 cycle delay decfsz T4SD1, 1 ; 1 + (1) is the time over? (A) goto Tmp4SegL2 ; 2 no, loop decfsz T4SD0, 1 ; 1 + (1) is the time over? (B) goto Tmp4SegL1 ; 2 no, loop return ; 2+2 Done

;-------------------------------------------------------------

Tmp1Seg movlw .14 ; 1 set number of repetitions (C) movwf T1SD0 ; 1 | Tmp1SegL0 movlw .72 ; 1 set number of repetitions (B) movwf T1SD1 ; 1 | Tmp1SegL1 movlw .247 ; 1 set number of repetitions (A) movwf T1SD2 ; 1 | Tmp1SegL2 clrwdt ; 1 clear watchdog decfsz T1SD2, 1 ; 1 + (1) is the time over? (A) goto Tmp1SegL2 ; 2 no, loop decfsz T1SD1, 1 ; 1 + (1) is the time over? (B) goto Tmp1SegL1 ; 2 no, loop decfsz T1SD0, 1 ; 1 + (1) is the time over? (C) goto Tmp1SegL0 ; 2 no, loop Tmp1SegDl1 goto Tmp1SegDl2 ; 2 cycles delay Tmp1SegDl2 clrwdt ; 1 cycle delay return ; 2+2 Done ;------------------------------------------------------------- ;------------------------------------------------------------- ; Code generated by PDEL ver 1.0 on 05/02/2009 at 09:12:14 p.m. ; Description: Waits 5000 cycles ;------------------------------------------------------------- PDelay movlw .6 ; 1 set number of repetitions (B) movwf PDel0 ; 1 | PLoop1 movlw .207 ; 1 set number of repetitions (A) movwf PDel1 ; 1 | PLoop2 clrwdt ; 1 clear watchdog decfsz PDel1, 1 ; 1 + (1) is the time over? (A) goto PLoop2 ; 2 no, loop decfsz PDel0, 1 ; 1 + (1) is the time over? (B) goto PLoop1 ; 2 no, loop PDelL1 goto PDelL2 ; 2 cycles delay PDelL2 clrwdt ; 1 cycle delay return ; 2+2 Done ;-------------------------------------------------------------

;********************************************************************** END ; directive 'end of program' ;**********************************************************************

Y este es el c=F3digo en C:

#include "DosClear.h" #int_EXT void EXT_isr(void) { }

//

***************************************************************************= ***

void Llamar(void) { output_bit(RA2, 1); // enciende el clear 1 delay_ms(1000); // espera 1 segundo output_bit(RA2, 0); // apaga el clear 1

delay_ms(200); // pausa

output_bit(RB4, 1); // enciende el clear 2 delay_ms(1000); // espera 1 segundo output_bit(RB4, 0); // apaga el clear 2

delay_ms(200); // pausa

output_bit(RA3, 1); // enciende el redial delay_ms(2000); // espera 2 segundos output_bit(RA3, 0); // apaga el redial

delay_ms(30000); // espera 30 segundos para la pr=F3xima llamada }

//

***************************************************************************= ***

void main() { int cntLlamadas=3D3;

port_b_pullups(TRUE); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_EXT); enable_interrupts(GLOBAL); //Setup_Oscillator parameter not selected from Intr Oscillotar Config tab

//----------------------------------------------------------------------=

-----

// limpia los puertos en uso output_bit(RB3, 0); output_bit(RA2, 0); output_bit(RA3, 0); output_bit(RB4, 0);

output_bit(RB3, 1); // inicia el encendido del celular delay_ms(400); // espera 4 segundos output_bit(RB3, 0); // finaliza el encendido del celular

while(1) { if(!input(PIN_B0)) { // si RB0 se puso bajo delay_ms(1000); // espera 1 segundo para volver a leer if((!input(PIN_B0)) && (cntLlamadas > 0)) { // y si RB0 sigue bajo Llamar(); // realiza la llamada cntLlamadas -=3D 1; } } else { cntLlamadas =3D 3; } } }

//

***************************************************************************= ***

DosClear.h es as=ED:

#include

#FUSES NOWDT //No Watch Dog Timer #FUSES INTRC_IO //Internal RC Osc, no CLKOUT #FUSES NOPUT //No Power Up Timer #FUSES NOPROTECT //Code not protected from reading #FUSES NOBROWNOUT //No brownout reset #FUSES NOMCLR //Master Clear pin used for I/O #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O #FUSES NOCPD //No EE protection

#use delay(clock=3D20000000) //#use delay(clock=3D4000000) #define RA2 PIN_A2 #define RA3 PIN_A3 #define RB3 PIN_B3 #define RB4 PIN_B4 #define RB5 PIN_B5

Reply to
LucasBols
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.