PIC Programming With the Basics – Article 3

Using the Interrupt Routine

This is the 3rd article which will teach you how to programme the PIC using c language. (We are using MicroC for this example). Before continuing this article, you have to refer the first 2 article which will give you the very fundamentals of programming. If you quite sure on those fields, then its ok. So we will continue form there.

As in the previous articles, we’ll continue as steps.

Step1: Make a new project for this task. I’m sure that now you are able. If not please refer the first two articles, PIC programming with the Basics…. Article 2.

Step2: We will be doing more examples on coding. Until then please copy this coding part and paste it in the coding window.

Step3: In this case, a pin (PORTC.f7) will be blinking until an interrupt is given. When it receives an interrupt, it will quickly off the blinking pin and another pin will set to high. (PORTC.f5)

First of all, you must understand about the Interrupt. Actually in denotes the same meaning. When you received an interrupt, what will you do? Defineatly you will attend to that interrupt and then continue of your previous work.

Let me get an example. Just assume, you are reading a novel when no body is at home. Assume the novel is very interesting. So you are keeping on reading with out doing any.

But what will happen, suddenly if the phone is ringing? Although the novel is interesting, you want to read is continuously, you have to keep it that place and have to go and answer the phone. After that what will you do? After finishing the call, you are coming to that same place and get the book and continue where you stop at previously.

Interrupt denotes the same example. Your programme will continue. That means your Main programme will continue. When an interrupt is received, the main programme will be stopped, and get in to the Interrupt Routine. After finishing it, it will automatically come to the position where he stops previously and continue from there.

So now you have an idea of the interrupt. So we will continue to coding section again.

Here is the code:

void interrupt()

if(INTCON.INTF==1)

PORTC.f7=0;

PORTC.f5=1;

delay_ms(2500);

void main()

INTCON=0×90;

TRISB=0xff;

PORTB=0×00;

TRISC=0×00;

PORTC=0×00;

while(1)

PORTC.f7=~PORTC.f7;

delay_ms(250);

We will discuss about coding later. Until then I’ll explain above code quickly.

First running method is the Main method. At the beginning, PORTB is assigned to the input, PORTC is assigned to the output.INTCON register should need to assigned like that. It will enable the Global Interrupt Enable bit, PORTB-0 interrupt on.

Then it will continue to the later part. Until you are switching off the pic, it will blink a pin with 250ms intervals.

But when an interrupt is received to the PORTB.f0 pin, the main programme will be stopped and it will run the Interrupt routine. It will switch off the PORTB.f7 pin to Zero, set PORTB.f5 pic to high. The delay is used to stay in that method some time. After the delay, it will come to the main programme again and continue the programme. Thatmeans blink the bulb again.

The Proteus simulation interface is given below.

You can now test the programme.

If there are any suggestions, please use the comment section.

Thanks (Admin)

Leave a Reply

Next Post

Anoto Digital Pen Technology: How Does This Technology Work?

What on earth is a digital smartpen and how does it differ from other pens on the market? The well-known Anoto digital pen technology is the path breaking high-tech pen technology that is responsible for transfer of handwritten text from paper into digital media in many of the digital pens […]
Anoto Digital Pen Technology: How Does This Technology Work?

You May Like