Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Read an IO pin PIC16F84A Help!

Status
Not open for further replies.

vladtess

New Member
Hi there! Here is my code:

Code:
	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!!!!
 
Hi,

If you mean you are grounding RB0 with the 10k to make it go low then its probably too high a resistance.

The normal way to switch an input is the connect the 10k between RB0 and +5v and simply switch or short between RB0 and Ground to pull the RB0 Low.
 
It works its just RA4 brb

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

Check this out:
https://picnote.blogspot.com/2008/10/open-drain-ra4-pin-on-pic.html

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.
 
Last edited:
Here some thing to go by
Code:
;			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
 
Last edited:
i updated my post above Burts re-read

EDIT:

Also you code should include config info and list like:

Code:
	list      p=16F84A           
	#include <p16F84A.inc>       

	__CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

count1 equ 0xc
count2 equ 0xd

    ORG     0x000             ; processor reset vector
;===== 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 0xFF

start:
	BTFSC PORTB,0 ; exectute next instruction if PORTB,0 is 1.
	movwf PORTA
	goto start
	END
 
Last edited:
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?
 
what are you simulating in? I simulated in Proteus and works fine..

Just tried with MPLAB SIM and works perfect also...
 
Last edited:
I use windows simulator, where you load a hex and you can manipulate variables. Called "PIC Simulator IDE"
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top