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.

pic resets on multiple button pushes

Status
Not open for further replies.

flawed

New Member
i have a pic circuit with 5 inputs via pull up resistors on porta which work fine on their own, but the pic resets when more than one button is pushed concurrently. Could anybody please suggest why? would it be a problem wih the circuit or am i doing something wrong in the code? I currently have 10k resistors pulling up to 5v.
 
Last edited:
Show the code

Could you show the code reading the inputs of Port A?
 
well i've just noticed that it only resets when the held buttons includes RA1 for some reason. i only need 5 inputs so i'll just use ra5 instead. - and it was happening even when i took all of the switch code out

cheers for replying
 
i dont think it'll be the code, i took all of the switch lines out and it still happened, more likley to be something to do with the pcb, im just happy i dont have to redo the hardware.
 
What PIC are you using? What other functions are associated with RA1? RA1 isn't the MCLR pin on that particular PIC, is it?
 
its a 16f876a, nah it itsn't mclr - thats pin 1. its funny because it'll work fine on a single keypress. im new to pbasic so im trying not to rock the boat too much, im already tripping over myself!
 
actually could you help me with this? its some code pommie (i think) posted a couple of weeks ago which i've been trying to change but confused myself.

I want to take the value of the switches being held concurrenly on porta, but i only want the state of the port to be valid when one or more switches are released. then the port is reset until all buttons are released where it loops again. i think i may have butcherd his code too much tho

Code:
WaitNoKey	call	Delay10	;required for debounce
		movfw	SWITCH_PORT		;get keys
		movwf	tmp1                           ;im using pull up res's so active low. not sure if this is                                                                    ;right way to go about it
		comf	tmp1, W	
		andlw	0x1f		;keep only bottom 5 bits
		btfss	STATUS,Z	;are any keys pressed
		goto	WaitNoKey	;yes, so carry on waiting

		clrf	Keys		;indicate no key pressed


WaitValid	call	Delay10		;wait 10mS for debounce
		
		movfw	Keys		;gets keys from last time
		
		movwf	OldKeys		;keep copy for later
		
		movfw	SWITCH_PORT	;get new key state

		movwf	tmp2
		comf	tmp2, w
		
		andlw	0x1f		;keep only bottom 5 bits
		
		movwf	Keys		;save for next time around
		
		xorwf	OldKeys,w	;keep only keys that have changed
		
		andwf	OldKeys,w	;and were pressed last time around
		
		btfsc	STATUS,Z	;will be non zero if a key was released
		
		goto	WaitValid

		movfw	OldKeys		;contains the valid key combination

		movwf	validkeypress	;store valid keypress in reg,.,
		
		call	checkchar

waitnopress	movfw	SWITCH_PORT		;= skip if set ;) - z set if theres a match
		xorlw	0x3f			;bit mask with 111111
		btfss	STATUS, Z		;so if there is a match, and no buttons are pressed, z is set
		goto	waitnopress		;skips the next instruction and goes back to the beginning.......
		goto	WaitNoKey
 
Last edited:
Grounds a floating

Wonderfull wierd things :eek: happen when ground's float around. I had a strip board that almost worked right. Certain things worked fine, others did not. Turned out that all of the ground stripes weren't grounded together. Power can do the same thing....:confused:
 
YEP;

BANKSEL ADCON1
movlw 0x06
movwf ADCON1
BANKSEL PORTA

it really isn't a problem though, i have 5 available ports which are behaving themselves. i don't suppose you could help me with the code posted above??
 
flawed said:
actually could you help me with this? its some code pommie (i think) posted a couple of weeks ago which i've been trying to change but confused myself.
Well, I cleaned up the code a bit and simulated it and it seems to work fine. It picks up any and all pressed active-low switches until one of them is released. What problem are you experiencing with this code?

Code:
WaitNoKey
;       call    Delay10         ; required for debounce
        comf    Sw.Port,W       ; get 'active low' keys
        andlw   0x1f            ; any keys pressed?
        skpz                    ; no, skip, else
        goto    WaitNoKey       ; keep waiting
        clrf    Keys            ; indicate no key pressed
WaitValid
;       call    Delay10         ; wait 10mS for debounce
        movf    Keys,W          ; gets keys from last time
        movwf   OldKeys         ; keep copy for later
        comf    Sw.Port,W       ; get new key state
        andlw   0x1f            ; keep only bottom 5 bits
        movwf   Keys            ; save for next time around
        xorwf   OldKeys,W       ; keep only keys that have changed
        andwf   OldKeys,W       ; any keys released?
        skpnz                   ; yes, skip, else
        goto    WaitValid       ; branch and wait for any release
        movf    OldKeys,W       ; contains the valid key combination
        movwf   validkeypress   ; store valid keypress in reg,.,
;       call    checkchar
 
its working fine now, it wasn't the bit of code that was causing me problems. thanks for doing that tho
 
Status
Not open for further replies.

Latest threads

Back
Top