title "Program"
include "p16f84a.inc"
;===== variables ===========
count1 equ 0xc
count2 equ 0xd
;===== end variables =======
;===== set ports ======
bsf STATUS,RP0 ;set PORTB, 0 to input, others to output
movlw 0x1
movwf TRISB
movlw 0x0
movwf TRISA
bcf STATUS, RP0
; ====== end ======
movlw b'10000'
start:
BTFSC PORTB,0 ; exectute next instruction if PORTB,0 is 1.
movwf PORTA
goto start
end
I am trying to send b'10000' to portA only if bit 0 on PORTB is 1. Basically make the LED lit when I press a button. I use the PIC simulator but also when testing in circuit, it doesn't work. I ground (w/ 10k resistor PORTB,0). Please explain what I am doing wrong! Thanks!!!!
Pin RA4 is multiplexed with the Timer0 module clock
input to become the RA4/T0CKI pin. The RA4/T0CKI
pin is a Schmitt Trigger input and an open drain output.
All other RA port pins have TTL input levels and full
CMOS output drivers
Open-Drain RA4 pin on PIC Microcontroller
I had a problem with RA4 pin which I cound not send '1' nor output 'high' to this pin. After some searches, I have found that RA4 pin (pin 3 for PIC16F627a) is "Open-Drain" type output pin. That means it cannot source current and it will be high impedance when assigned logic '1' to it. I cannot set this pin as an output pin by using 'TRISA=0x00'. The solution is attaching a pull up resistor (10K) to the RA4 pin in order to use this pin as an output pin.
; the button is released to return normal
; program flow.
btfsc PORTA, RAx ; Declare port/pin that the button is on
goto skip_bttn ; button is up, stop checking..
movlw d'10'
movwf temp ; Loop a few microseconds for debounce delay
decfsz temp, F ; .. requires variable Count to be defined.
goto $-1
btfsc PORTA, RAx ; check if button is up too soon (false indicator)
goto skip_bttn ; button is up, skip action code
; Action Code
; Implement action that button performs.
btfss PORTA, RAx ; Wait until button released to continue program.
goto $-1
skip_bttn: ; Label placed after button detect
Thanks guys, but at the moment, im trying to find out what is wrong with my program. When I compile, everything is fine, but when I simulate the hex, the line that turns on LED is always skipped. what can I do?