1
00:00:00,390 --> 00:00:00,690
Hello.

2
00:00:00,690 --> 00:00:01,380
Welcome back.

3
00:00:01,380 --> 00:00:07,620
In this lesson we're going to see how to initialize an inputs been using bare metal code for our Texas

4
00:00:07,620 --> 00:00:10,920
Instrument team 4C 1 2 3 microcontroller.

5
00:00:10,950 --> 00:00:16,730
So these are the peripherals we have on our development board and we over here.

6
00:00:16,980 --> 00:00:18,390
We know where they are connected.

7
00:00:18,420 --> 00:00:23,850
Switch one is connected to peer for switch two is connected to PSU and we've got three entities from

8
00:00:23,860 --> 00:00:26,590
which copy this on and went to create a new project.

9
00:00:26,670 --> 00:00:27,470
So I've copied this.

10
00:00:27,480 --> 00:00:28,970
It's in my clipboard I pressed.

11
00:00:29,000 --> 00:00:35,670
I did this and then I press control SEE RIGHT WHEN to create a new project to buy here and create a

12
00:00:35,670 --> 00:00:36,940
food for it.

13
00:00:37,040 --> 00:00:38,690
I call this GPL your input

14
00:00:43,140 --> 00:00:47,630
and I'll quote a project to keep your input as well.

15
00:00:49,840 --> 00:00:59,410
And I'm going to select the board team for C 1 2 3 0 8 6 p.m. like this and then okay over here and

16
00:00:59,410 --> 00:01:06,520
then on the Simpsons going to select the core on a device I'm going to select the startup and then Okay

17
00:01:07,060 --> 00:01:09,530
I'm going to rename this to the name of the MCU.

18
00:01:09,780 --> 00:01:12,370
Tim 4C 1 2 3 0.

19
00:01:12,460 --> 00:01:19,480
H can forget about the other stuffs you h and I'll come over here rename this to application API like

20
00:01:19,480 --> 00:01:29,420
this and I'll come over here right click a new item I'll call it main name the C and I'll paste helping

21
00:01:29,440 --> 00:01:30,160
out here.

22
00:01:30,160 --> 00:01:31,290
Right.

23
00:01:31,480 --> 00:01:40,060
Okay so we can come to target options sets the X toward 216 sixteen megahertz debug dropdown over here

24
00:01:40,120 --> 00:01:47,970
select the SD link select the still areas I CDI come to settings and take this reset and round okay.

25
00:01:47,970 --> 00:01:48,290
And then.

26
00:01:48,310 --> 00:01:59,470
Okay so I'll include my MCU head by right clicking over here an include file this one here like this.

27
00:01:59,470 --> 00:02:11,050
Once that is done open up Main function into main over here like this open close and I'll start by initializing

28
00:02:11,650 --> 00:02:12,620
the clock.

29
00:02:12,670 --> 00:02:17,910
So what we're going to do is we're going to just recreate what we're going to create a simple experiment.

30
00:02:17,920 --> 00:02:24,640
When the push button push button lets a push button one is pressed we're going to turn on these red

31
00:02:24,700 --> 00:02:26,590
or green LCD.

32
00:02:26,890 --> 00:02:31,990
We can use the green lady for this example when we push button is pressed we simply turn on the green

33
00:02:31,990 --> 00:02:32,470
LCD.

34
00:02:32,970 --> 00:02:36,370
So let's start by initializing the clock access.

35
00:02:36,370 --> 00:02:46,890
Both are our LCD and our switches connected to switch is connected to P.F. port F so we've got to initialize

36
00:02:46,890 --> 00:02:51,210
clock access for Port F so come over here our GC

37
00:02:54,160 --> 00:03:00,890
GPI oh and then I'll do syrup X to zero over here

38
00:03:06,770 --> 00:03:15,220
and they will port f clock essentially once that is done we can come here see GPL you f

39
00:03:18,010 --> 00:03:29,590
and we can say FDA are over here we can say as your X your x 0 8 and this will initialize is who sets

40
00:03:29,630 --> 00:03:39,020
the green LRT as output and we can see this by just expanding your X or a two binary.

41
00:03:39,310 --> 00:03:47,300
So how serious or zero force year here and then perhaps you are one serious you here like this actually

42
00:03:47,300 --> 00:03:54,070
helps you one so I here this is bit zero bit one bit to be three.

43
00:03:54,070 --> 00:03:57,280
So this is P three right.

44
00:04:06,050 --> 00:04:13,820
Once that is done we can because P F one over here which is going to be because peer 4 which is going

45
00:04:13,820 --> 00:04:16,750
to be our switch one is supposed to be set as input.

46
00:04:16,760 --> 00:04:19,730
We need not do anything by default.

47
00:04:20,060 --> 00:04:26,540
The the pin has zero debt and to set to input you you have to write zero to that particular pin.

48
00:04:26,570 --> 00:04:30,080
So since we have not changed opinion its default status zero.

49
00:04:30,110 --> 00:04:32,070
We don't have to write anything into it.

50
00:04:32,090 --> 00:04:38,420
One other thing too is that our PINs here are normally high meaning without pressing that pin the pin

51
00:04:38,420 --> 00:04:39,810
state is high.

52
00:04:39,830 --> 00:04:44,050
If you read from the pin without the button being pressed it's high.

53
00:04:44,480 --> 00:04:46,370
When we pressed the pin that pin goes low.

54
00:04:46,370 --> 00:04:52,550
So we call this button an octave low button so to detect whether a person has pressed on the switch

55
00:04:52,580 --> 00:04:55,780
or the button we have to read low.

56
00:04:56,540 --> 00:05:02,640
If we read high it means it's not being pressed or it's in its initial state.

57
00:05:02,780 --> 00:05:09,210
So we've got to enable a pull up resistor for our push button to switch to and they would put up resistor

58
00:05:09,230 --> 00:05:11,120
we used to P R register.

59
00:05:11,600 --> 00:05:17,060
So before we do that actually let's enable them both as digital pins and went when say Chip GPL you

60
00:05:17,160 --> 00:05:24,890
f and I'm going to use the DP and register and I'm going to

61
00:05:27,860 --> 00:05:35,250
pass you x 1 8 over here and this enables both pins simultaneously.

62
00:05:35,250 --> 00:05:39,020
And I explained this and you see that it's corresponds to the pins we are interested in.

63
00:05:39,780 --> 00:05:40,950
So we have one here.

64
00:05:40,950 --> 00:05:47,380
This is serious it's one for the first name Beau in hexadecimal notation.

65
00:05:47,410 --> 00:05:51,810
Each digits here becomes four digits in binary right.

66
00:05:51,910 --> 00:05:56,320
And for binary digits or for binary numbers are known as a limbo.

67
00:05:56,390 --> 00:06:02,620
So if you hear someone say this the word if you had limbo like this.

68
00:06:02,620 --> 00:06:05,570
This of course for bits.

69
00:06:05,590 --> 00:06:08,360
So each digit here is known as a name though.

70
00:06:08,410 --> 00:06:10,440
Right.

71
00:06:10,480 --> 00:06:17,020
So when we expand this number here we get serious through a 1 in binary when we expand the 8 we get

72
00:06:17,110 --> 00:06:26,270
1 0 0 0 0 like this and we know this is bit zero bit one bit to be three and bit three here is set high.

73
00:06:26,480 --> 00:06:28,900
It's three SPF three criminality.

74
00:06:29,350 --> 00:06:32,470
And this is it's four bits four is P F four.

75
00:06:32,470 --> 00:06:35,650
That is our switch one over here like this.

76
00:06:35,740 --> 00:06:36,280
Okay.

77
00:06:36,430 --> 00:06:40,060
So this sets both of them to digital pins.

78
00:06:40,120 --> 00:06:47,560
Once they start and we can said they pull up resistor for our our switch sources GPI o f and then I'll

79
00:06:47,560 --> 00:06:55,390
use the P U R register and they will say is your X we passed one two here like this.

80
00:06:55,390 --> 00:06:58,170
So the stage was set up is complete.

81
00:06:58,180 --> 00:07:02,590
We simply need to read our pin state if it's pressed we turn on reality.

82
00:07:02,590 --> 00:07:04,330
If it's not we keep it off.

83
00:07:04,660 --> 00:07:13,270
So I'm going to open my while one loop over here open and close and I'm going to come over here and

84
00:07:13,270 --> 00:07:13,740
to read.

85
00:07:13,750 --> 00:07:20,380
I simply need to see whether the pin has become what as B has changed from zero to one because I said

86
00:07:20,410 --> 00:07:34,130
the pain is active low it's default status 1 so I'm going to do when do f over here of see if GP I O

87
00:07:34,210 --> 00:07:42,370
F and then data register and then I'm going to read the bits correspond into the pin which is Pier for

88
00:07:42,370 --> 00:07:53,360
here if data register value if the data register value it and I'll perform B twice and with 0 x 1 0

89
00:07:53,750 --> 00:08:00,920
and by passing you x 1 0 I'm performing between this and with this bit with the current value in the

90
00:08:00,920 --> 00:08:02,390
data register.

91
00:08:02,390 --> 00:08:11,280
So if this and this if this resort if this returns a positive result it means that pain has not been

92
00:08:11,280 --> 00:08:19,680
pressed because in an end operation if you perform logical end if two numbers are 1 the resource is

93
00:08:19,680 --> 00:08:20,420
1.

94
00:08:20,520 --> 00:08:22,810
If one number is 1 and the other is 0.

95
00:08:22,830 --> 00:08:31,150
The resource is 0 so if both numbers cause I've got one here as one up front and then the next up around

96
00:08:31,150 --> 00:08:34,780
it's going to be the corresponding bits in this data register.

97
00:08:34,780 --> 00:08:39,490
So if we take the corresponding bit and its value is 1 and then we perform a bit twice.

98
00:08:39,520 --> 00:08:47,030
And with this one here which is essentially this one here in binary and the resort is 1.

99
00:08:47,140 --> 00:08:53,060
This means they are both 1 if they are both 1 it means the switch has not been pressed since the switch

100
00:08:53,060 --> 00:08:59,510
is active low when we press the switch to switch value the corresponding bit here has to be low.

101
00:08:59,740 --> 00:09:11,100
So I'm going to see if this if this and this is not true I've put knots over here to indicate that if

102
00:09:11,100 --> 00:09:16,020
the resort is no one mean and if it's false then our switch has been pressed.

103
00:09:16,470 --> 00:09:26,490
And after that and we can see a GPI u a GPA you f we can turn on our D by saying data register and we

104
00:09:26,490 --> 00:09:31,680
simply turn on the LCD by writing 0 x page over here

105
00:09:36,240 --> 00:09:41,180
else we can write we can disable the LCD by saying ls

106
00:09:46,320 --> 00:09:49,230
we say GPL you f

107
00:09:52,530 --> 00:10:02,030
data register and we use the number sunshine over here and add to sign and to X 88 so that we disable

108
00:10:02,050 --> 00:10:05,030
just a bit we want to disable right.

109
00:10:05,160 --> 00:10:12,530
So let's rebuild and see what we have going to click over here to compile it's finished compiling.

110
00:10:12,780 --> 00:10:17,880
I'm going to click here to download onto my board and it's finished downloading.

111
00:10:18,010 --> 00:10:25,140
Okay so I'm going to press the switch one as press the criminality comes on I press it comes on and

112
00:10:25,140 --> 00:10:25,920
then it comes on.

113
00:10:26,160 --> 00:10:31,280
So basically we check in whether the state has changed over here and I hope you you understand this.

114
00:10:31,290 --> 00:10:36,210
If you do not understand the statement just send me a message by it's really simple.

115
00:10:36,400 --> 00:10:38,010
I'll put a comment here

116
00:10:43,040 --> 00:10:48,140
switches octave low right.

117
00:10:48,210 --> 00:10:49,560
So this all there is for this lesson.

118
00:10:49,560 --> 00:10:52,500
If you have any questions just let me know and I'll see you later.

119
00:10:52,500 --> 00:10:53,280
Have a nice day.
