View previous topic :: View next topic |
Author |
Message |
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
interrupt switch |
Posted: Mon Feb 17, 2020 4:39 am |
|
|
Dear Friends,
I am using EXT1 on PIC18F4520 to detect interrupt of three switches which are connected on Port A: PIN_A1, PIN_A2 and PIN_A3. I used the configuration of diodes as illustrated in the attachment. When I press, the routine is being executed because I also attached an LED on RB1 to see if the button is triggering the interrupt and so it is. the problem is that on the display always showing "003" Even during startup. instead n internal 10K pull-up I made 10K pullup on the breadboard.
http://helengammon.com/images/Wired_or_multiple_interrupts.png
the code is:
Code: | #INT_EXT1
void EXT1_isr(void)
{
if(input_state (PIN_A1 == 1))
{
read_port = 1;
}
if(input_state (PIN_A2 == 1))
{
read_port = 2;
}
if(input_state (PIN_A3 == 1))
{
read_port = 3;
}
else read_port = 0;
clear_interrupt(INT_EXT1);
} |
Part of the Main() code:
Code: |
set_tris_b(0x43);
set_tris_a(0xff);
output_low(Pin_b7);
enable_interrupts(INT_EXT1);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
|
on RB0 I have 1Hz input that why I need EXT1 as switch interrupt. What could be the issue? I am missing something? I have PIC18F4520 and Crystal of 20MHz |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Mon Feb 17, 2020 5:26 am |
|
|
What is 'display' hardware ? LCD module, link to PC, 7-segment LED, 3 LEDS ?
You really need to show us your 'display function'. It almost sounds like you
never clear the display or have the I/O set incorrectly.
Also, unless you NEED very, very fast I/O, let the compiler automatically handle the set_tris() details, which it does by default. I've only needed to manually set I/O ports, 2-3 times in 2 decades. If you do it manually, you run the risk of setting them wrong and wonder 'well it worked fine 3 hours ago ?'... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Mon Feb 17, 2020 7:51 am |
|
|
You also show both INT0 and INT1 enabled, but only a handler for INT1.
You have got a handler for INT0 I trust?.
Also the picture says 'all pins have internal pull-ups enabled', but PORT A
does not _have_ any internal pull ups, so the pins won't be reliable. |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Mon Feb 17, 2020 1:50 pm |
|
|
I have lcd output. If you want when i arrive home i will send the whole code. Ttelmah i said in the last sentence that instead of internal pullups i made my own pullups hardware. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Mon Feb 17, 2020 1:54 pm |
|
|
No, you said 'pullup'. Singular. There needs to be a pullup on every
input pin. |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Mon Feb 17, 2020 2:29 pm |
|
|
Yes i made pullups on every pin....sorry in that case. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Mon Feb 17, 2020 3:43 pm |
|
|
Cut code for a simple program to test each pin and confirm you don't have a wiring problem or shorted pins. |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Mon Feb 17, 2020 4:22 pm |
|
|
Ok let me trim the code and if i have the same problem i will write it in the forum. |
|
|
|