Question

I've always blinked leds on PORTB in PIC16F628A.

Nowdays i need to do that on PORTA because I'm trying keypad matrix on PORTB.

The code below runs perfectly on RB3 of PORTB, but I doesn't in PORTA.

Here is the example in PORTA. I've tested and the problem is in BTFSS and BTFSC function... Because if I turn led off or on manually is functioning well. (also I've ommited delay_1s_routine code)

main
    ;*********CONFIGURACION LED**********
    clrf Puerto_Led
    movlw 0x07
    movwf CMCON
bsf STATUS,RP0
        clrf TRISA
bcf STATUS,RP0

loop
    call prende_apaga_Led
    call delay_1s_routine
goto loop


prende_apaga_Led
 btfsc PORTA,RA1    ;si esta en 0 salta el GOTO
 goto $+3
 bsf PORTA,RA1      ;Pongo en '1' el bit del Led Verde
 return
 bcf PORTA,RA1      ;Pongo en '1' el bit del Led Verde
return

Thanks in Advice!!

EDITED: Put real values on code

PD: Tested this instruction separately and works great - bsf PORTA,RA1 - bcf PORTA, RA1

Was it helpful?

Solution

I prefer:

Instead of going into techno quirks and philosophical debates, bypass the problem..

I always use shadow registers for port states and test and drive over them.

So use a bit in your RAM to reflect the state of PORTA, RA1. Trust me it will work seamlessly.

OTHER TIPS

In your code after the label prende_apaga_Led, You seem to be treating the LED pin once as an input (testing using btfsc), and once as an output (bsf and bcf). The pin can not be used as both at the same time. Either you set the associated TRISA bit as input or output and stick to it.

It seems to me that the code you are trying to do toggles the value of the LED based on its previous state. The way you are doing it won't work. An easier way to do it is by using the xor function as follows: movlw 0xYY; where YY is the pattern in which 0 means no change to the pin output, 1 means toggle then follow by xorlw PORTA

so simply it will be as:

    clrf Puerto_Led
    movlw 0x07
    movwf CMCON
    bsf STATUS,RP0
    clrf Conf_Led
    bcf STATUS,RP0
 loop
    movlw 0xYY ; change YY, i.e. if the LED is on RA2 YY will be 0x04
    xorlw Puerto_Led
    call delay_1s_routine
    goto loop
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top