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.

Problem facing when using Timer0 of 16f877a

Status
Not open for further replies.
If you explain what you are trying to achieve it will be easier to advise.

However, if you use the port B change interrupt then you need to keep a record of the previous state so you know which pin changed. Doing port xor previousState will give you the bits that have changed.

Mike.
 
ok this is my plan. i have two external push button. For push button_1, when i press it it will be doing task1 and for push button_2 when i press it, will be doing task2. because both push button also have to be an external interrupt. So i'm curious where to place the second push button since 16f877a only has a external interrupt pin which is RB0.

can u get my idea?So i plan to use the change state of RB7:RB4 to know between this two external interrupt i know which button i pressed.

thank you.
 
This is fairly simple to do as long as you keep a copy of the previous state.

Code:
	movfw	PORTB
	xorwf	Previous,W	;W=changed pins
	xorwf	Previous,F	;previous=PortB
	andwf	Previous,W	;w=new presses
	movwf	NewKeys
	btfsc	NewKeys,7
	goto	Key7Pressed
	...

NewKeys will have a bit set for every pin that went from 0 to 1.

If your keys are active low then insert an xorlf 0xff after the load from the port.

Edit, I should point out that the above code works much better on a 10mS interrupt due to problems with key bounce when using interrupt on change.

Mike.
 
Last edited:
hi pommie,
since only RB7:RB4 have the change state function. so when i do i need to clear the lower byte of portb? because i'm using portb.0 also.And the 'Previous' in your coding izzit i need to assign 0x00 to it, so that there is value in previous.

thank you.
 
I would just use a timer interrupt to read your keys. Your 6mS interrupt would work quite well. Doing it this way you can use as many bits of port B as you wish and you can have a completely separate interrupt for RB0. Yes, Previous should be initiated to zero.

Mike.
 
hi pommie,
my 6ms already used to do its task something like blink the led. So i try to add in the code to check my push button evry 6ms interrupt. but for my push button i have a nested loop to check how many times i have pressed the push button. because different push number will have different task to do.

So when i test on the code.i found that, i need to press quite long time to let the system know the push button has been pressed .and let say when i push the second time i want the system to do another task. but , final result is when i just push once the system already go to the push twice task. So i think it should be the debounce problem. So i decided to use the change port function of portb.

am i choosing the correct way?

thank you.
 
Status
Not open for further replies.

Latest threads

Back
Top