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.

i'm stumped!!

Status
Not open for further replies.

kutalinelucas

New Member
i was wondering if somebody could help me with this.

I have a program which reads port a, and takes a valid signal when one of the concurrently held keys is released. the problem i have is i want the program to compaire the value to a number of possibilities, and im not sire where im going wrong. any help would be greatly appriciated.
cheers.

Code:
WaitNoKey	call	Delay10	;required for debounce
		
		movfw	SWITCH_PORT		;get keys
		movwf	tmp1
		comf	tmp1, W	
		andlw	0x3f		;keep only bottom 5 bits		!!NEED TO CHANGE THIS LINE!!
		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	0x3f		;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,.,	port was inverted so should act like active low
		
		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
	


		
checkchar	movF	PUSH_B		
		xorwf	validkeypress	;here the valid press should be active high, because of the comf.	;
		btfsc	STATUS, Z	;skip next instruction if there is no match
		call	Outputa
		retlw	0x00



				;;;here i want it to cycle through and compaire the read value to a number of stored values, and act accordingly, 
				
		

		
Outputa		
		movlw	0x00
		call	Text_A			;get a character from the text table
		
		call	LCD_Char		;here after it returns a 0x00, it goes back to loop - not good. ;		call	Delay10
		incf	countchar, 
		clrf	SWITCH_PORT
		retlw	0x00
 
Why have you filled my code with white space. :mad: :mad: I can't even follow it without scrolling up and down like an idiot. AND, why didn't you post on the original thread so that people would have a slight clue what you are trying to achieve.

Mike.
 
i am sorry, and i've asked a question about your code before and did give you credit :) . im not very good at this i must admit. i know i've butchered it fairly blindly. just know i really did appreciate the help. i didnt think old posts were read, as it was about 2 weeks ago. sorry mike
 
He added lot's of blank lines. The horizontal formating was mine.

Edit, where did the post go that I was replying to?

Mike.
 
mike, is there any chance you could help me out this one last time? i promise to leave your spacing, im just not sure where to return to. at the moment it'll work fine with just one combination, but i've tried and cant get it to loop through lots of diffrent conditions

lucas.
 
Why don't you start by explaining exactly what you are trying to do. The original thread was about reading 5 keys and returning a value between 1 and 31 for the combination that was pressed.

Mike.
 
yes. its a one handed keyboard, so the bit values of port a correspond to a letter of the alphebet. i have the pic connected to a lcd display. the program works in the way i can compaire the valid signal from the port against any stored value, but i dont know how to compaire the valid reading against all possible combinations, and then return to the loop
 
sorry that doesn't make much sense. i can say, press bit 3 & 4, when one is released the character 'a' appears on the display, it then resets and i can do it again, but i want to be able to press any combination and have the corresponding character to be displayed, ie to loop through all the bit values which i have stored in registers until a match is found, before starting again
 
Something like this should work,
Code:
WaitNoKey	call	Delay10mS	;required for debounce
		movfw	PORTB		;get keys
[COLOR="Blue"]		xorlw	0xff		;invert them[/COLOR]	
		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	Delay10mS	;wait 10mS for debounce
		movfw	Keys		;gets keys from last time
		movwf	OldKeys		;keep copy for later
		movfw	PORTB		;get new key state
[COLOR="blue"]		xorlw	0xff		;invert them[/COLOR]	
		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

		movwf	OldKeys		;contains the valid key combination

	;do whatever with valid code

[COLOR="blue"]		movfw	OldKeys
		xorlw	.01
		btfsc	STATUS,Z
		goto	Not01
		movlw	'A'
		call	OutPut
		goto	WaitNoKey
Not01		movfw	OldKeys
		xorlw	.02
		btfsc	STATUS,Z
		goto	Not02
		movlw	'B'
		call	OutPut
		goto	WaitNoKey
Not02		[/COLOR]
		goto	WaitNoKey	;go around and do it all again

The blue bits are changes from the original code.

Edit, noticed a mistake - marked in red. Edit 2, no it wasn't a mistake.

It would be much better to use a table to convert it. Maybe you could try that.

Mike.
 
Last edited:
i can't get it to work. Isn't there anyway i could just do a bit test else return on this bit of code;

Code:
checkchar	movF	PUSH_B		
		xorwf	validkeypress	
		btfsc	STATUS, Z	
		call	Outputa
		retlw	0x00
 
i know this is a shitty thing to say, because you've helped me so much, but basically if i can't get this little bit of code to work in the next hour and half my degree is down the drain. im not trying to do any sort of a guilt trip but im getting desperate
 
Sorry, as far as I can see that code should work as intended. Did you change it to port A?

What happens with this code?
Code:
WaitNoKey	call	Delay10mS	;required for debounce
		movfw	PORTA		;get keys
		xorlw	0xff		;invert them
		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	Delay10mS	;wait 10mS for debounce
		movfw	Keys		;gets keys from last time
		movwf	OldKeys		;keep copy for later
		movfw	PORTA		;get new key state
		xorlw	0xff		;invert them
		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

	;do whatever with valid code

		movfw	OldKeys
		addlw	0x30
		call	OutPut
		goto	WaitNoKey	;go around and do it all again

Mike.
 
kutalinelucas said:
i know this is a shitty thing to say, because you've helped me so much, but basically if i can't get this little bit of code to work in the next hour and half my degree is down the drain. im not trying to do any sort of a guilt trip but im getting desperate

Sorry to be rude, but if you can't do it yourself you don't deserve to pass your degree, it's supposed to prove that you're capable - not that you can get someone else to do the work for you.
 
and nigel, im doing a computing degree not electronics, this was a small part of a large project which i needed help with. i have my specialties which i help people in other forums, which i thought places like this was for. you may be very knowlegable in this area but i am still learning. that last post was a last ditch attempt, and i must be honest i did exaggreate the importance, but after spending 3 months of a project, i was pissed off to be defeated my a pic
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top