1
00:00:00,630 --> 00:00:00,950
Hello.

2
00:00:00,960 --> 00:00:01,650
Welcome back.

3
00:00:01,650 --> 00:00:08,910
In this lesson we're going to see how to set up GPA you interrupt for our team 4C 1 2 3 microcontroller

4
00:00:09,390 --> 00:00:15,060
and this simple experiment Well we're going to do is we going to be controlling one output device in

5
00:00:15,050 --> 00:00:22,500
a wire infinite while one loop in the main function and when we press our switch one and switch to on

6
00:00:22,500 --> 00:00:29,970
the TVC board and interrupt the screen to occur and upon occurence of this interrupt the content of

7
00:00:30,030 --> 00:00:36,300
an interrupt service routine or an interrupt handler is going to execute and this interrupt handler

8
00:00:36,690 --> 00:00:39,450
we're going to be blinking our green algae in there.

9
00:00:39,690 --> 00:00:45,240
And remember these are just used as examples entities are just examples you can replace the blinking

10
00:00:45,240 --> 00:00:53,160
of the LRT with your own complex algorithm more complex control of any you know eye or device you are

11
00:00:53,160 --> 00:00:58,470
dealing with so I'm going to create a new project by coming over the New Vision project

12
00:01:05,650 --> 00:01:07,580
or create a photo for the project.

13
00:01:07,590 --> 00:01:11,010
I call this GPL you interrupt GPL you underscore interrupt

14
00:01:13,560 --> 00:01:18,060
and the project is going to be called GPL you interrupt to swirl

15
00:01:25,220 --> 00:01:27,440
and I'm going to like the board to foresee.

16
00:01:27,440 --> 00:01:32,500
1 2 3 0 page 6 p.m. and this is it.

17
00:01:32,650 --> 00:01:33,760
Okay.

18
00:01:33,850 --> 00:01:40,070
And over here understand this I'm going to select core on the device which starts up over here and then.

19
00:01:40,120 --> 00:01:40,870
Okay.

20
00:01:40,950 --> 00:01:42,770
Going to rename this to the name of the board.

21
00:01:42,790 --> 00:01:47,440
Tim 4C One two three.

22
00:01:47,560 --> 00:01:49,070
Going to click a dropdown over here.

23
00:01:49,090 --> 00:01:55,090
So group I'm going to rename it to AP AP and I'm to come over here.

24
00:01:55,090 --> 00:02:02,310
Target options X total I'm going to set to 16 megahertz debug group down over here.

25
00:02:02,310 --> 00:02:06,400
Still there is ICD I am going to click over here reset and run.

26
00:02:06,490 --> 00:02:07,040
Okay.

27
00:02:07,060 --> 00:02:07,370
And then.

28
00:02:07,420 --> 00:02:08,380
Okay.

29
00:02:08,590 --> 00:02:12,160
Once they start I'm going to right click you I turn it a C file.

30
00:02:12,160 --> 00:02:13,370
I'll give it a name.

31
00:02:13,480 --> 00:02:18,080
Man over here and a right click to include the port header.

32
00:02:18,100 --> 00:02:19,890
This is it.

33
00:02:20,140 --> 00:02:22,150
Once they start we're going to dive straight in.

34
00:02:22,180 --> 00:02:28,530
We start off by enabling our entities in the course we're going to use the switch one and switch two.

35
00:02:28,780 --> 00:02:33,740
We need to unlock the switch one which is locked by default.

36
00:02:33,830 --> 00:02:42,730
Gonna open one stop with its main course and open enclosure over here and I'm going to start off by

37
00:02:42,730 --> 00:02:47,530
enabling clock access to port F so see system control and then I come here.

38
00:02:47,540 --> 00:02:56,640
RC GC GPL you and she's your ex over here to see you once that's done port.

39
00:02:56,770 --> 00:02:59,410
F pins you it's locked.

40
00:02:59,410 --> 00:03:03,030
So we need to unlock this in order to be able to use this switch.

41
00:03:03,070 --> 00:03:12,550
When I say GPL you f over here I'm going to access the lock register and I'm going to pass the special

42
00:03:12,640 --> 00:03:19,310
unlock value which is this value over here.

43
00:03:19,590 --> 00:03:24,800
They put a comment here for you on lock PFC.

44
00:03:26,200 --> 00:03:27,480
That's what we're doing here.

45
00:03:27,520 --> 00:03:34,910
Once that's done I'm going to access the comments register and make it configurable so I see a GPL you

46
00:03:34,950 --> 00:03:43,390
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

47
00:03:43,390 --> 00:03:53,350
to go to GPL u f and then look over here and then I'm going to post here right.

48
00:03:54,050 --> 00:04:01,390
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

49
00:04:01,390 --> 00:04:01,810
here

50
00:04:03,670 --> 00:04:18,910
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

51
00:04:26,060 --> 00:04:27,620
see it's your x 1 one

52
00:04:32,800 --> 00:04:41,250
essentially you're saying make P F 1 A P of 4 on the PFC your

53
00:04:46,780 --> 00:04:48,910
input penis that's what we're doing here.

54
00:04:49,000 --> 00:04:58,680
By disabling them once they started we're going to make P F 3 into output pin we're going to set P.F.

55
00:04:58,690 --> 00:05:05,680
3 2 and 1 into output pins and these are where the ladies are connected so come over and see you can

56
00:05:05,680 --> 00:05:14,320
you f direction register pass your ex over here it's your E

57
00:05:17,520 --> 00:05:18,620
right.

58
00:05:18,750 --> 00:05:19,800
Once that's done.

59
00:05:19,860 --> 00:05:26,520
Gonna come down here and I'm going to set them all up Teach to parents by setting the stage to enable

60
00:05:26,840 --> 00:05:37,620
them to kill you f or I hear the n gonna pass your effects point F over here and I'm going to enable

61
00:05:37,620 --> 00:05:46,860
pull up registers for PFC Ram P.F. one to do this I'm going to see GPO F by a p r register

62
00:05:49,620 --> 00:05:53,190
and I'm going to pass your X one one over here

63
00:06:05,200 --> 00:06:16,170
P.F. 4 and PFC Maria once that's done well I'm going to do is disable interrupt globally by saying disabled

64
00:06:16,170 --> 00:06:19,900
by our queue we need to do this before we configure interrupt.

65
00:06:20,100 --> 00:06:23,550
I'm going to configure P for PFC row for fallen edge.

66
00:06:23,550 --> 00:06:27,330
Trigger interrupt to do this.

67
00:06:27,330 --> 00:06:32,600
I start off by saying GPL you f i s.

68
00:06:32,610 --> 00:06:38,610
And then course gratuities signing is your ex on one

69
00:06:48,060 --> 00:06:54,040
making them each sensitive.

70
00:06:54,500 --> 00:07:07,890
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

71
00:07:07,920 --> 00:07:19,200
forward we're going to set it to detect falling edge by saying apply f GPA you f I E3 and over here

72
00:07:25,730 --> 00:07:28,020
2 x 1 1

73
00:07:40,800 --> 00:07:46,650
wants test done we've got to clear any prior interrupt and then unmask to interrupt

74
00:07:49,110 --> 00:07:52,980
or come down here and she tell you f

75
00:07:56,850 --> 00:08:05,790
I she r you want to punch your ex when one over here.

76
00:08:11,910 --> 00:08:16,220
And then I said GPL you f I am

77
00:08:19,960 --> 00:08:30,380
you know punch your ex one one over here.

78
00:08:34,240 --> 00:08:39,670
Right after that we've got to enable interrupt in the end Vic and set the priority.

79
00:08:39,670 --> 00:08:47,410
Show the are what you pay your interrupt port F is Ira q 30 to anybody interrupted said a priority I'm

80
00:08:47,410 --> 00:08:48,520
going to do and Vic

81
00:08:53,260 --> 00:09:02,830
interrupts priority thirty over here and I'm going to say three shifts five over here we're going to

82
00:09:02,830 --> 00:09:04,540
set it to a priority of three

83
00:09:17,890 --> 00:09:27,760
Mr. Stone I'm going to a neighborhood interrupt by doing and Vic I as a neighbor will register in next

84
00:09:27,770 --> 00:09:35,570
year over here you course sure x 4 and then one two three four five six seven seven zeros

85
00:09:46,820 --> 00:09:47,500
right.

86
00:09:48,270 --> 00:09:49,510
So this is it.

87
00:09:49,530 --> 00:09:55,530
This should set up or interrupt our switches for detecting fallen edges whenever I fallen agents detected

88
00:09:55,590 --> 00:09:56,460
an interrupt.

89
00:09:56,500 --> 00:09:56,940
Okay.

90
00:09:57,750 --> 00:10:03,630
Let's continue with our main function I'm just going to put some content into you while one loop over

91
00:10:03,630 --> 00:10:03,960
here

92
00:10:07,410 --> 00:10:15,320
and over here we going to blink the red LCD so I'm gonna tell you f data register then I'm gonna pass

93
00:10:15,330 --> 00:10:21,380
your x 2 over here and I'm going to see it the M S

94
00:10:24,570 --> 00:10:26,450
see you want to blink.

95
00:10:26,490 --> 00:10:31,680
That's one hundred over here and we're going to disable it by doing GPL you f

96
00:10:36,000 --> 00:10:40,930
data register then I'll put Ampersand to it it over here

97
00:10:45,170 --> 00:10:54,250
sure to like this delay the same amount today and this one hundred yeah okay.

98
00:10:54,440 --> 00:11:00,650
Once that's done we can implement or interrupt handler I'm going to come down here to put the interrupt

99
00:11:00,680 --> 00:11:03,650
callback function here so it's void

100
00:11:07,050 --> 00:11:15,220
and it has to be written this way void GPL you f underscore handler

101
00:11:19,950 --> 00:11:24,960
then I'm going to pass for it in here and open close.

102
00:11:24,980 --> 00:11:27,650
This right here is

103
00:11:33,020 --> 00:11:37,010
the red LCD in here we're going to target the green Naledi.

104
00:11:37,100 --> 00:11:41,030
We're going to talk good screen for three times whenever the interrupt occurs.

105
00:11:46,800 --> 00:11:48,740
We can use a loop to accomplish this.

106
00:11:48,760 --> 00:11:50,780
I'll save for it.

107
00:11:50,790 --> 00:11:53,100
Are you close your eyes.

108
00:11:53,100 --> 00:12:00,070
Less than three hours plus plus over here open and close.

109
00:12:00,540 --> 00:12:10,410
I'm going to do GPL you f data register then I'm going to pass a pax sure page over here then delay

110
00:12:10,420 --> 00:12:14,250
m s gonna pass.

111
00:12:14,340 --> 00:12:20,560
Why should I help pass one hundred then turn it back off GPA you f

112
00:12:23,170 --> 00:12:29,210
data and then no sunshine and an activity over here.

113
00:12:29,410 --> 00:12:38,100
X 0 8 delay I can clear this one hundred here like this.

114
00:12:40,780 --> 00:12:48,700
So once that is done we need to clear the interrupt flag before we return to our shape over here.

115
00:12:48,720 --> 00:12:56,610
Keep your f ICR in or pass your X one one over here.

116
00:13:09,550 --> 00:13:10,960
This one last step we could take.

117
00:13:10,960 --> 00:13:16,780
It's not absolutely necessary but sometimes the interrupt flag is not cleared.

118
00:13:16,780 --> 00:13:19,330
We've got to force read it to clear it.

119
00:13:19,610 --> 00:13:28,150
So create a volatile variable here so volatile and call this read back and we're going to force read

120
00:13:28,150 --> 00:13:28,990
it.

121
00:13:28,990 --> 00:13:39,510
Here have I seen read back you cause GPL you f ICR register like this.

122
00:13:39,730 --> 00:13:45,960
So the reason we've got some arrows is because we don't have our shoot or delay function here.

123
00:13:46,060 --> 00:13:52,870
You can bring an actual function using the timer that we learned how to build or you can just use the

124
00:13:52,900 --> 00:13:55,090
pseudo delay function it's quick to work with.

125
00:13:55,090 --> 00:14:08,170
I just use the pseudo delay here Floyd delay in this thing to delay the open enclosure over here and

126
00:14:08,170 --> 00:14:16,480
then I have my nested loop to perform the delay for me also for int i equals zero.

127
00:14:16,650 --> 00:14:26,530
It's less than that delay amount passed by the user by plus plus and open enclosure by here in the loop

128
00:14:26,530 --> 00:14:39,270
RC for int j because you j is less than three thousand one hundred and eighty J plus plus open enclosure

129
00:14:39,430 --> 00:14:45,350
here and then I'm going to fetch the prototype of this put it up here and we don't need to fetch the

130
00:14:45,350 --> 00:14:47,480
prototype of the interrupt handler.

131
00:14:47,540 --> 00:14:49,150
The system recognizes this.

132
00:14:49,160 --> 00:14:54,070
So you need not fetch the prototype here and it has to be written exactly this way.

133
00:14:54,410 --> 00:14:55,230
Right.

134
00:14:55,230 --> 00:14:58,060
So once this is done we can build and see what we have.

135
00:14:58,060 --> 00:15:03,950
I'm going to click here to build let's get it on our board and see how it looks.

136
00:15:04,160 --> 00:15:09,880
So I'm going to click here to download onto a board and I can see the red LDS blinking.

137
00:15:09,890 --> 00:15:15,120
No I'm going to press a wire switches and see what happens.

138
00:15:15,170 --> 00:15:17,200
Nothing happens here.

139
00:15:17,570 --> 00:15:18,550
Nothing happens yes.

140
00:15:18,590 --> 00:15:21,470
Well let's see.

141
00:15:21,650 --> 00:15:22,100
Okay.

142
00:15:22,100 --> 00:15:25,660
It's because we we've not enabled global interrupt.

143
00:15:25,760 --> 00:15:29,930
Remember before we configured to interrupt we had to disable it globally.

144
00:15:29,930 --> 00:15:36,710
So I'm going to come here and enable that underscore underscore and enable I argue like this right.

145
00:15:36,740 --> 00:15:42,160
And when we press our button regardless of the button with press we want to see that green LCD blink.

146
00:15:42,510 --> 00:15:43,500
OK.

147
00:15:43,700 --> 00:15:51,200
I'm going to click over here then it's going to toggle so fast we wouldn't see we wanted to talk the

148
00:15:51,230 --> 00:15:52,940
three times right.

149
00:15:52,940 --> 00:15:53,890
This the new could.

150
00:15:53,920 --> 00:15:58,120
The red is still blinking because the red is what's in the main function.

151
00:15:58,130 --> 00:16:01,530
The main function is infinite loop over here.

152
00:16:01,530 --> 00:16:09,530
So I'm gonna press the push button that you can see the green is blinking and then this one too.

153
00:16:09,930 --> 00:16:14,470
So whenever I would press the push button the interrupter cares and what is within the interrupt handler

154
00:16:14,480 --> 00:16:16,200
is executed.

155
00:16:16,670 --> 00:16:25,420
Right here the green entity comes on when we press this right.

156
00:16:25,490 --> 00:16:28,340
So this order is what is less than you have any questions at all.

157
00:16:28,550 --> 00:16:30,980
Just send me a message and I shall see you later.

158
00:16:30,980 --> 00:16:31,570
Have a good day.
