title: Hold button on/off using assembly code using PIC16F887
body: <p>I'm using assembly, MPLAP and PROTEUS, to write code turn a LED on or off by a button. The problem here is that my code turns on led when the button in the up position and turns it off when the button at down position.</p>
  
  <p>What I want is: Click the button and the LED turns on and stays on. Click the button again and LED turns off and stays off. Repeat this forever.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>; Exam 7 - Bonus 2
  
  
  INCLUDE "P16F887.INC"
  Status  EQU 0x20    ; Bien dung de
  BSF     Status,0;
  
  
  ;Init----------------
  BANKSEL TRISD   ; Lua chon bank 1
  BCF     TRISD,0 ; PortD,0 la Output
  CLRF    TRISD
  BSF     TRISC,0 ; PortC,0 la Input
  
  BANKSEL PORTD   ; Lua chon bank 0
  
  ;Main--------------
  check db 0
  Start
  
  
  mainloop
  
  
  btfsc PORTC,0
  GOTO OFF
  
  ON
  movlw 0
  movwf PORTD
  GOTO mainloop
  
  
  
  OFF
  movlw 1
  movwf PORTD
  GOTO mainloop
  
  
  
  ;.............................
  
  END
  </code></pre>