It was one of my first experiments related to embedded systems.I was following this document : http://groups.csail.mit.edu/lbr/stack/pic/pic-prog-assembly.pdf Problem emerged at Tutorial 6.I was trying to blink the led at different pace when pressed button.First, I took what tutorial give as an example word by word ,however, it didn't work.When not pressing it sometimes blinks slower sometimes faster, when I push button it blinks in an expected frequency.Then I changed the code to the program below for simplification:

LIST p=16F84A
INCLUDE "p16f84a.inc"

RES_VECT  CODE    0x0000


TIME equ 0x0f

COUNT1 equ 0x0c
COUNT2 equ 0x0d
COUNT3 equ 0x0e

    movlw   0xFF
    movwf   COUNT1

    movlw   0xFF
    movwf   COUNT2

    movfw   TIME
    movwf   COUNT3
    decfsz   COUNT3,1
    goto LOOP3

    decfsz   COUNT2,1
    goto LOOP2  

    decfsz   COUNT1,1
    goto LOOP1



    bsf     STATUS,5
    movlw   b'00011111'
    movwf   TRISA
    movlw   0x00
    movwf   TRISB
    bcf     STATUS,5
    movlw   0x00
    movwf   PORTB


    movlw   0x01
    btfss   PORTA,0
    movlw   0x14
    movwf   TIME

    bsf     PORTB,3
    call    Delay
    bcf     PORTB,3
    call    Delay

    goto MAIN_LOOP


Same thing happened. While it flashed irregularly without pressing the button, when I pressed button at RA0 it blinked faster. I want first phase to be always slow. Where is the problem ? Is the problem in circuit, in software, or in PIC itself. Given physical conditions, as if btfss doesn't work properly either because the switch is problematic or because PIC is burnt. It is more likely that I am failure rather than the hardware is. Maybe there is a logical error in software in spite of similar program flow being expressed with different codes.Could oscillator not have been set up properly ? I had difficulty to set up an RC oscillator. When I add its R it works normal(or I think so). But after adding a capacitor and connecting its other terminal to negative voltage the led always shines.Can you say exactly where the issue lies? What's going on the background?

Additional Information :

At first, I used RBO/INT to do bit test with the switch. But the INT part was suspicious to me. Then I changed it to RA0.(which is what is asked in the question) The result didn't change.

Additional Information 2 : Configuration bits -> __CONFIG _FOSC_EXTRC & _WDTE_OFF & _PWRTE_OFF & _CP_OFF

Additional Information 3 : It turns out that there is no any unintentional reset.Problem remains unsolved.

  • \$\begingroup\$ At first, I used RBO/INT. But the INT part was suspicious to me. Then I changed it to RA0. Problem still remains unsolved :( \$\endgroup\$ Commented Jul 18, 2016 at 6:35
  • 1
    \$\begingroup\$ Whoever it is, someone deleted the first comment above. Nevertheless, I won't delete my answer because it may provide additional information to the other problem solver candidates for which I am thankful. \$\endgroup\$ Commented Jul 18, 2016 at 7:10
  • 1
    \$\begingroup\$ What are your configuration word settings? Did you disable the Watchdog? \$\endgroup\$ Commented Jul 18, 2016 at 8:10
  • 1
    \$\begingroup\$ You could add another LED that you flash once when the code initially starts running. This will let you know if the processor is restarting for some reason. \$\endgroup\$
    – HandyHowie
    Commented Jul 18, 2016 at 9:34
  • 1
    \$\begingroup\$ Have you got a pull up/down resistor on the input, so that the input is not floating when the button isn't pressed? \$\endgroup\$
    – HandyHowie
    Commented Jul 18, 2016 at 9:55

1 Answer 1


From our discussion it looks like the problem is caused by false triggering due to a missing pull up/down resistor on the switch input.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.