View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
why we needs interrupts |
Posted: Sun Jan 01, 2012 1:09 pm |
|
|
What is the main purpose of the interrupts? When and why we use them? Help me to be a bit more advanced ;) Thx. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sun Jan 01, 2012 1:43 pm |
|
|
Interrupts
A possible way to visualize this is as follows.
You live in a busy house and you hear the door bell ring. Your only options are to stop what you are doing and answer it or finish what you are doing and hope the visitor is still there. Now the pic without interrupts is like the second option. It doesn't take care of the door bell. It at best can be put in a loop where it periodically opens the door to see if any one is there. With certain things like RS232 which is asynchronous the second approach is vulnerable to missing characters. However with an interrupt any part of the code including say half way through executing any line of code the bell will ring and the interrupt can answer the door and invite the visitor into a parlor so you (the code) can get to it later. The visitor is never missed. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sun Jan 01, 2012 1:47 pm |
|
|
Then (of course) comes the second part.
_If_ you need to keep on doing the job you were working on when the bell went, you must just answer the door, take the package and get rid of the caller as soon as possible. If you stand and chat on the doorstep, vital things that you were doing when the bell went, can/will go wrong.
This is why the interrupt handler should (in 99% of cases) _just_ do the essential jobs that the bell signals need doing, and nothing else.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 01, 2012 5:40 pm |
|
|
Here's another example that I use. Suppose you are waiting for the mail
to be delivered to your mailbox, which is out near the street. When the
mailman picks up your outgoing mail and delivers new mail, he will flip
down the red flag on the mailbox.
So every 30 minutes, all day long, you look out your window to see if the
red flag is down, which means the mail has come in. This is called "polling".
But what if you had a switch and a buzzer connected to the mailbox, and
it went into your house. Then when the buzzer makes a sound, you know
the mail is in, and you can go get it. That is called an "interrupt".
The interrupt is better (in this case), because it saves you the time of
having to look out the window every few minutes to check the mailbox. |
|
|
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
Re |
Posted: Mon Jan 02, 2012 2:28 am |
|
|
Thank you very much Guys(guess)! I'm a self learning boy whit another profession. Unfortunately,there is no much information about CCS programming at internet on my vernacular (Bulgarian). I'm glad to see, that there is people ready to help me at that initial degree.
Best wishes! |
|
|
|