Maker Pro
Maker Pro

How to generate an interrupt on a PIC16F628 when a input changes

T

Timo

hi,

As an example i would like to generate an interrupt and read the inputs
(pressed by buttons).
Any possible code for that wich is usefull? I'm using the C2C C-compiler for
PIC's (www.picant.com/c2c/).
I have a PIC16F628 and pins RA0 and RA1 on port RA are still free for that.
There i would connect 2 buttons on but their value should be read when they
are pressed or something. I just need to see the edges when they are
pressed.

Greetings,

Timo
 
S

Spehro Pefhany

hi,

As an example i would like to generate an interrupt and read the inputs
(pressed by buttons).
Any possible code for that wich is usefull? I'm using the C2C C-compiler for
PIC's (www.picant.com/c2c/).
I have a PIC16F628 and pins RA0 and RA1 on port RA are still free for that.
There i would connect 2 buttons on but their value should be read when they
are pressed or something. I just need to see the edges when they are
pressed.

Greetings,

Timo

That part only has "interrupt on change" function on port B (see
datasheet). But that's not a very good way to read buttons in general
anyway. Better to poll at some reasonable frequency and detect changes
in firmware (as well as debouncing).


Best regards,
Spehro Pefhany
 
P

Peter F. Jørgensen

Timo,

You should really rearrange your hardware setup as the interrupts you are
looking for is on port B.
You can use port B0 as a general interrupt and you can use B4-B7 to generate
a interupt if any of these bits change. In any case you want to read the
relevant port where the keypad is attached to get more data (e.g. about
which key is depressed etc.)

For a keypad I use the external interrupt (port B0), where I in the
interrupt service routine handle the issue that a mechanical key really
toggles many times before being stable and therefore generates a number of
interrupts. A simple timedelay before reading the keypad is maybe not very
intelligent, but is often good enough.

For more information about the interrupt possibilities, you really need to
take a close look at the PIC data sheet from Microchip and probably also the
documentation on you compiler.

regards
Peter
 
Top