need help coding pic16f84a scanning of switches

Thread Starter

ernestclydeachua

Joined Aug 5, 2012
16
hello i need help coding
i want to produce an out put like this


ive done some programming

and changed the ports it runs on simulation but wont run in the circuit it cause my LEDs to turn off and on when i energize a single switch

heres the code
Rich (BB code):
;RB0 controls RB7 and RA0 
;RB0=0 then RB4 and RA0=0, else it will be 1 when RB0=1
;RB1 controls RB5 and RA1
;RB2 controls RB6 and RA2
;RB3 controls RB7 and RA3
 
	list      p=16F84A            ; list directive to define processor
	#include <p16F84A.inc>        ; processor specific variable definitions
	errorlevel -302, -207	
 
	__config _CP_OFF &_XT_OSC & _PWRTE_ON & _WDT_OFF
 
cntr1	equ	h'21'
cntr2	equ	h'22'
bfr1	equ 	23h
 
	ORG     0x000             ; processor reset vector
  	goto    main              ; go to beginning of program
 
	ORG     0x004             ; interrupt vector location
	nop
	retfie                    ; return from interrupt
 
main:
	bsf	STATUS,RP0
	movlw	b'00000000'
	movwf	TRISA
	movlw	b'00001111'
	movwf	TRISB
	bcf	STATUS,RP0
 
newloop:
	movf PORTB,W
	movwf bfr1
	movf bfr1,W
	movwf PORTA
	rlf bfr1,F
	rlf bfr1,F
	rlf bfr1,F
	rlf bfr1,F
	movf bfr1,W
	movwf PORTB
	goto newloop	
 
	end
 

absf

Joined Dec 29, 2010
1,968
If your schematic looks something like mine it should work.

Of course, you have to put in the 4MHz crystal and the 2x 22p capacitors since you're defining "_XT_OSC". You see, the simulator is very forgiving. It works even without that.

Allen
 

Attachments

Last edited:

ErnieM

Joined Apr 24, 2011
8,377
If it works in sim but not on the hardware then the sim and the hardware don't match.

Did you try to see what happens at the inputs when you change the switches? Can you drop a voltmeter on them and see you have good goes-into's that don't interact?
 

absf

Joined Dec 29, 2010
1,968
It looks like your switches are connected to gnd, and pulled up with 10K resistors. And your 16F84A has 20 pins?

Allen
 
Last edited:
Top