Previous in Forum: Looking for Electric Motor   Next in Forum: Transformer law
Close
Close
Close
2 comments
Associate

Join Date: Jul 2007
Posts: 26

PIC interrupt help

09/15/2007 12:27 PM

hi

i am programming pic 16f877 in c using FED pic c compiler .i want to connect a switch to RB4 and generate an interrupt when the switch is closed so that i could go to the main prog and increase a count variable and also switch on 3 leds connected to the first 3 bits of Port A.

this is how i did it but it does'nt work

i created a variable called Flag of type byte as a global var.

then in the main prog i tested if Flag was 1 or 0,if 1 i then increased count and set portA to 111.

then in the interrupt routine i tested the RB4 bit ,if 1 then i set Flag to 1 then cleared RB4

i dont know what to do again

any help or any link to an example or tutorial involving interrupts on RB4-RB7?

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16510
Good Answers: 669
#1

Re: PIC interrupt help

09/15/2007 1:47 PM

Presumably you havn't got an emulator so that you can step thru and watch what's happeming..or if you have then maybe the interrupts dont work in step mode.

Simplify it to check the interrupt....

Get the interrupt routine to complement a variable and sentd it to your leds. Start with the variable set to 00 then each interupt should toggle the leds on/off this will check if the interrupt routine is working.

Do you have to configure/setup registers to enable the correct pins as interrupt enabled? And have you enable the interrupt in software?

I use Zilog micro's so I may be way off but they are similar...hope this is some help.

Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Guru

Join Date: Dec 2005
Location: Etats Unis
Posts: 1871
Good Answers: 45
#2

Re: PIC interrupt help

09/16/2007 1:34 AM

Do you have the interrupt on change registers set correctly? Are you reading the port to reset the change detection latches? You have to do that after each interrupt to set the new state to trigger the return to the previous state. You also have to set several interrupt enables to ensure that the interrupt flag gets routed to the actual interrupt. Then if you are using other interrupts you have to pole to determine what peripheral is causing the interrupt and route your code accordingly. Don't forget to clear interrupts before returning or you'll be stuck in a forever loop.

__________________
The hardest thing to overcome, is not knowing that you don't know.
Register to Reply
Register to Reply 2 comments
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.

Previous in Forum: Looking for Electric Motor   Next in Forum: Transformer law
You might be interested in: Switch Boots, Audio Switch Matrices

Advertisement