Jump to content
Sign in to follow this  
Baixue

Interrupt On Change On Porta(pic16f690)

Recommended Posts

I am still dealing with IOC on the low pin count demo board, which has a PIC16f690 on it. I wrote the IOC for portb and it works perfectly, however, it just doesn't work on porta (I use porta.5 as IOC pin in my case), which is really frustrating and confusing. Could some one take a look at my code and see what the problem would be? Appreciate a lot!!

#include <system.h>
#pragma DATA 0x2007, _HS_OSC & _WDT_OFF

void main()
{
trisc=0x00; //configure portc as output
portc=0x00;//initialize portc
trisa=0xff;//configure porta as input, use porta.5 as IOC

ioca=0x20;//enable porta.5 IOC

set_bit(intcon,7);//enable all interrupts
set_bit(intcon,6);//enable all peripheral interrupts
clear_bit(intcon,5);//disable the timer0 interrupt
clear_bit(intcon,4);// disable the RA2/INT exteranl interrupt
set_bit(intcon,3);//enable the interrupt(RABIE)


ansel =0x00; // the fllowing two used to turn off analouge modle
anselh =0x00;

while(1)
{
	delay_ms(200);
	portc=0x00;

			}
}


void interrupt()
{
portc=0x01; // when interrupt happens, light up a led
porta=0xff;//write to porta to clear the interrupt
clear_bit(intcon,0);// clear the interrupt flag(RABIF)	

}

Share this post


Link to post
Share on other sites
Looks like you forgot to set up your IOCA register to tell the processor which A ports you want to monitor for change.

 

I need it here(at line 10):

ioca=0x20;//enable porta.5 IOC

 

Could it be any other reason? Thanks a lot!

Share this post


Link to post
Share on other sites

Sorry about that, I can't see for looking.

 

I can't see anything obviously wrong with your code other than the rather short delay in your main loop. Could it be that the program works but your not seeing the LED because of the short delay given the the interrupt is likely to happen mid way through the 200mSec delay.

What happens if you comment out the "portc=0x00;" line in the loop?

Share this post


Link to post
Share on other sites

I still couldn't figure out what's wrong with my code, I decide to give up working on porta. I think I just will let the IOC work on portb,cause it works perfectly on any port of portb. Shrug~~

 

Thank you so much for your help though,AlexR!

 

Regards,

Baixue

Share this post


Link to post
Share on other sites

You have the chip configured to use _HS_OSC, which uses porta pins 4 and 5 (page 199 of the datasheet).

 

According to page 62 of the datasheet, IOCA<5:4> will always be 1 when using HS oscillator mode. Port A IOC will probably work on a differect Port A pin.

 

- Bill

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...