CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

interrupt switch

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

interrupt switch
PostPosted: Mon Feb 17, 2020 4:39 am     Reply with quote

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: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 17, 2020 5:26 am     Reply with quote

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: 19506

View user's profile Send private message

PostPosted: Mon Feb 17, 2020 7:51 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 17, 2020 1:50 pm     Reply with quote

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: 19506

View user's profile Send private message

PostPosted: Mon Feb 17, 2020 1:54 pm     Reply with quote

No, you said 'pullup'. Singular. There needs to be a pullup on every
input pin.
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Mon Feb 17, 2020 2:29 pm     Reply with quote

Yes i made pullups on every pin....sorry in that case.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 17, 2020 3:43 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 17, 2020 4:22 pm     Reply with quote

Ok let me trim the code and if i have the same problem i will write it in the forum.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group