PDA

View Full Version : PIC16F628A input question



yankee
- 31st December 2005, 19:12
Is it possible to have the PIC working on one operation due to an input from a toggle switch, then have another toggle switch input immediately interupt the first operation and perform a second operation, taking precedence over any other operation? I would need both operations to work independently of one another.

Example:

Switch1 on porta.0 = 0 then operation 1

Switch2 on porta.1 = 0 then stops operation 1 before it finishes and over rides with operation 2

Maybe I'll have to use another PIC in the circuit to stop the first PIC?

BobK
- 31st December 2005, 22:47
Hi Yankee and Happy New Years to all!

Yes you can do what you want to do but you are not going to get Port A inputs to work in the manner you are requesting. Your regular input (the one with the least priority) can be a PortA input but if you want to interrupt it with more priority then you will need to use PortB.0 for that one.

I personally have not done interupts myself yet but there are enough posts on this forum that will provide you with what you are looking for. Just goto the search and enter "Interupts" and you will find what you need.

Have fun!

BobK

yankee
- 3rd January 2006, 04:45
Hi Bob, thanks for the reply. I searched and could find nothing that I was able to understand. Can someone provide a little help?

Thanks in advance! ~ Dave

peterdeco1
- 3rd January 2006, 09:13
Hi Yankee. You can do it simply with your code. The following assumes porta is held high and your input switches have common negative. Portb.0 controls operation1. Portb.1 controls operation2.

START:
LOW PORTB.0 'cancel operation1
LOW PORTB.1 'cancel operation2
IF PORTA.0 = 0 THEN OPERATION1 'ignore switch #2 but if #1 switch on do operation1
GOTO START

OPERATION1:
IF PORTA.0 = 1 AND PORTA.1 = 1 THEN START 'both switches off cancel both operations
HIGH PORTB.0 'do operation 1
IF PORTA.1 = 0 THEN OPERATION2 '#2 switch on do operation2
GOTO OPERATION1

OPERATION2:
LOW PORTB.0 'cancel operation1
HIGH PORTB.1 'start operation2
IF PORTA.1 = 0 THEN OPERATION2 'ignore #1 switch & stay here if #2 switch on
GOTO START 'switch #2 off go home

yankee
- 5th January 2006, 03:35
OK, I'll try that out!

I'll tell you what, it isn't easy going from strictly analog for 25 years to digital. Maybe this old dog can learn some new tricks.

Thanks!