Hello.
Welcome back.
In this lesson we're going to see how to set up GPA you interrupt for our team 4C 1 2 3 microcontroller
and this simple experiment Well we're going to do is we going to be controlling one output device in
a wire infinite while one loop in the main function and when we press our switch one and switch to on
the TVC board and interrupt the screen to occur and upon occurence of this interrupt the content of
an interrupt service routine or an interrupt handler is going to execute and this interrupt handler
we're going to be blinking our green algae in there.
And remember these are just used as examples entities are just examples you can replace the blinking
of the LRT with your own complex algorithm more complex control of any you know eye or device you are
dealing with so I'm going to create a new project by coming over the New Vision project
or create a photo for the project.
I call this GPL you interrupt GPL you underscore interrupt
and the project is going to be called GPL you interrupt to swirl
and I'm going to like the board to foresee.
1 2 3 0 page 6 p.m. and this is it.
Okay.
And over here understand this I'm going to select core on the device which starts up over here and then.
Okay.
Going to rename this to the name of the board.
Tim 4C One two three.
Going to click a dropdown over here.
So group I'm going to rename it to AP AP and I'm to come over here.
Target options X total I'm going to set to 16 megahertz debug group down over here.
Still there is ICD I am going to click over here reset and run.
Okay.
And then.
Okay.
Once they start I'm going to right click you I turn it a C file.
I'll give it a name.
Man over here and a right click to include the port header.
This is it.
Once they start we're going to dive straight in.
We start off by enabling our entities in the course we're going to use the switch one and switch two.
We need to unlock the switch one which is locked by default.
Gonna open one stop with its main course and open enclosure over here and I'm going to start off by
enabling clock access to port F so see system control and then I come here.
RC GC GPL you and she's your ex over here to see you once that's done port.
F pins you it's locked.
So we need to unlock this in order to be able to use this switch.
When I say GPL you f over here I'm going to access the lock register and I'm going to pass the special
unlock value which is this value over here.
They put a comment here for you on lock PFC.
That's what we're doing here.
Once that's done I'm going to access the comments register and make it configurable so I see a GPL you
f c are over here and then I'm going to punch your ex through one and then once they shut down I'm going
to go to GPL u f and then look over here and then I'm going to post here right.
So once this is done we've got to configure port f for this switch in the LCD so I'm going to come down
here
G P i o f direction register I'm gonna see it and you cross and I'm going to see one one over here
see it's your x 1 one
essentially you're saying make P F 1 A P of 4 on the PFC your
input penis that's what we're doing here.
By disabling them once they started we're going to make P F 3 into output pin we're going to set P.F.
3 2 and 1 into output pins and these are where the ladies are connected so come over and see you can
you f direction register pass your ex over here it's your E
right.
Once that's done.
Gonna come down here and I'm going to set them all up Teach to parents by setting the stage to enable
them to kill you f or I hear the n gonna pass your effects point F over here and I'm going to enable
pull up registers for PFC Ram P.F. one to do this I'm going to see GPO F by a p r register
and I'm going to pass your X one one over here
P.F. 4 and PFC Maria once that's done well I'm going to do is disable interrupt globally by saying disabled
by our queue we need to do this before we configure interrupt.
I'm going to configure P for PFC row for fallen edge.
Trigger interrupt to do this.
I start off by saying GPL you f i s.
And then course gratuities signing is your ex on one
making them each sensitive.
I'm just gonna say GPA F over here IP and then to X on one and then we're going to make sure we're detecting
forward we're going to set it to detect falling edge by saying apply f GPA you f I E3 and over here
2 x 1 1
wants test done we've got to clear any prior interrupt and then unmask to interrupt
or come down here and she tell you f
I she r you want to punch your ex when one over here.
And then I said GPL you f I am
you know punch your ex one one over here.
Right after that we've got to enable interrupt in the end Vic and set the priority.
Show the are what you pay your interrupt port F is Ira q 30 to anybody interrupted said a priority I'm
going to do and Vic
interrupts priority thirty over here and I'm going to say three shifts five over here we're going to
set it to a priority of three
Mr. Stone I'm going to a neighborhood interrupt by doing and Vic I as a neighbor will register in next
year over here you course sure x 4 and then one two three four five six seven seven zeros
right.
So this is it.
This should set up or interrupt our switches for detecting fallen edges whenever I fallen agents detected
an interrupt.
Okay.
Let's continue with our main function I'm just going to put some content into you while one loop over
here
and over here we going to blink the red LCD so I'm gonna tell you f data register then I'm gonna pass
your x 2 over here and I'm going to see it the M S
see you want to blink.
That's one hundred over here and we're going to disable it by doing GPL you f
data register then I'll put Ampersand to it it over here
sure to like this delay the same amount today and this one hundred yeah okay.
Once that's done we can implement or interrupt handler I'm going to come down here to put the interrupt
callback function here so it's void
and it has to be written this way void GPL you f underscore handler
then I'm going to pass for it in here and open close.
This right here is
the red LCD in here we're going to target the green Naledi.
We're going to talk good screen for three times whenever the interrupt occurs.
We can use a loop to accomplish this.
I'll save for it.
Are you close your eyes.
Less than three hours plus plus over here open and close.
I'm going to do GPL you f data register then I'm going to pass a pax sure page over here then delay
m s gonna pass.
Why should I help pass one hundred then turn it back off GPA you f
data and then no sunshine and an activity over here.
X 0 8 delay I can clear this one hundred here like this.
So once that is done we need to clear the interrupt flag before we return to our shape over here.
Keep your f ICR in or pass your X one one over here.
This one last step we could take.
It's not absolutely necessary but sometimes the interrupt flag is not cleared.
We've got to force read it to clear it.
So create a volatile variable here so volatile and call this read back and we're going to force read
it.
Here have I seen read back you cause GPL you f ICR register like this.
So the reason we've got some arrows is because we don't have our shoot or delay function here.
You can bring an actual function using the timer that we learned how to build or you can just use the
pseudo delay function it's quick to work with.
I just use the pseudo delay here Floyd delay in this thing to delay the open enclosure over here and
then I have my nested loop to perform the delay for me also for int i equals zero.
It's less than that delay amount passed by the user by plus plus and open enclosure by here in the loop
RC for int j because you j is less than three thousand one hundred and eighty J plus plus open enclosure
here and then I'm going to fetch the prototype of this put it up here and we don't need to fetch the
prototype of the interrupt handler.
The system recognizes this.
So you need not fetch the prototype here and it has to be written exactly this way.
Right.
So once this is done we can build and see what we have.
I'm going to click here to build let's get it on our board and see how it looks.
So I'm going to click here to download onto a board and I can see the red LDS blinking.
No I'm going to press a wire switches and see what happens.
Nothing happens here.
Nothing happens yes.
Well let's see.
Okay.
It's because we we've not enabled global interrupt.
Remember before we configured to interrupt we had to disable it globally.
So I'm going to come here and enable that underscore underscore and enable I argue like this right.
And when we press our button regardless of the button with press we want to see that green LCD blink.
OK.
I'm going to click over here then it's going to toggle so fast we wouldn't see we wanted to talk the
three times right.
This the new could.
The red is still blinking because the red is what's in the main function.
The main function is infinite loop over here.
So I'm gonna press the push button that you can see the green is blinking and then this one too.
So whenever I would press the push button the interrupter cares and what is within the interrupt handler
is executed.
Right here the green entity comes on when we press this right.
So this order is what is less than you have any questions at all.
Just send me a message and I shall see you later.
Have a good day.