Hello.
Welcome back.
In this lesson we're going to see how to initialize an inputs been using bare metal code for our Texas
Instrument team 4C 1 2 3 microcontroller.
So these are the peripherals we have on our development board and we over here.
We know where they are connected.
Switch one is connected to peer for switch two is connected to PSU and we've got three entities from
which copy this on and went to create a new project.
So I've copied this.
It's in my clipboard I pressed.
I did this and then I press control SEE RIGHT WHEN to create a new project to buy here and create a
food for it.
I call this GPL your input
and I'll quote a project to keep your input as well.
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
then on the Simpsons going to select the core on a device I'm going to select the startup and then Okay
I'm going to rename this to the name of the MCU.
Tim 4C 1 2 3 0.
H can forget about the other stuffs you h and I'll come over here rename this to application API like
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
out here.
Right.
Okay so we can come to target options sets the X toward 216 sixteen megahertz debug dropdown over here
select the SD link select the still areas I CDI come to settings and take this reset and round okay.
And then.
Okay so I'll include my MCU head by right clicking over here an include file this one here like this.
Once that is done open up Main function into main over here like this open close and I'll start by initializing
the clock.
So what we're going to do is we're going to just recreate what we're going to create a simple experiment.
When the push button push button lets a push button one is pressed we're going to turn on these red
or green LCD.
We can use the green lady for this example when we push button is pressed we simply turn on the green
LCD.
So let's start by initializing the clock access.
Both are our LCD and our switches connected to switch is connected to P.F. port F so we've got to initialize
clock access for Port F so come over here our GC
GPI oh and then I'll do syrup X to zero over here
and they will port f clock essentially once that is done we can come here see GPL you f
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
the green LRT as output and we can see this by just expanding your X or a two binary.
So how serious or zero force year here and then perhaps you are one serious you here like this actually
helps you one so I here this is bit zero bit one bit to be three.
So this is P three right.
Once that is done we can because P F one over here which is going to be because peer 4 which is going
to be our switch one is supposed to be set as input.
We need not do anything by default.
The the pin has zero debt and to set to input you you have to write zero to that particular pin.
So since we have not changed opinion its default status zero.
We don't have to write anything into it.
One other thing too is that our PINs here are normally high meaning without pressing that pin the pin
state is high.
If you read from the pin without the button being pressed it's high.
When we pressed the pin that pin goes low.
So we call this button an octave low button so to detect whether a person has pressed on the switch
or the button we have to read low.
If we read high it means it's not being pressed or it's in its initial state.
So we've got to enable a pull up resistor for our push button to switch to and they would put up resistor
we used to P R register.
So before we do that actually let's enable them both as digital pins and went when say Chip GPL you
f and I'm going to use the DP and register and I'm going to
pass you x 1 8 over here and this enables both pins simultaneously.
And I explained this and you see that it's corresponds to the pins we are interested in.
So we have one here.
This is serious it's one for the first name Beau in hexadecimal notation.
Each digits here becomes four digits in binary right.
And for binary digits or for binary numbers are known as a limbo.
So if you hear someone say this the word if you had limbo like this.
This of course for bits.
So each digit here is known as a name though.
Right.
So when we expand this number here we get serious through a 1 in binary when we expand the 8 we get
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.
It's three SPF three criminality.
And this is it's four bits four is P F four.
That is our switch one over here like this.
Okay.
So this sets both of them to digital pins.
Once they start and we can said they pull up resistor for our our switch sources GPI o f and then I'll
use the P U R register and they will say is your X we passed one two here like this.
So the stage was set up is complete.
We simply need to read our pin state if it's pressed we turn on reality.
If it's not we keep it off.
So I'm going to open my while one loop over here open and close and I'm going to come over here and
to read.
I simply need to see whether the pin has become what as B has changed from zero to one because I said
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
F and then data register and then I'm going to read the bits correspond into the pin which is Pier for
here if data register value if the data register value it and I'll perform B twice and with 0 x 1 0
and by passing you x 1 0 I'm performing between this and with this bit with the current value in the
data register.
So if this and this if this resort if this returns a positive result it means that pain has not been
pressed because in an end operation if you perform logical end if two numbers are 1 the resource is
1.
If one number is 1 and the other is 0.
The resource is 0 so if both numbers cause I've got one here as one up front and then the next up around
it's going to be the corresponding bits in this data register.
So if we take the corresponding bit and its value is 1 and then we perform a bit twice.
And with this one here which is essentially this one here in binary and the resort is 1.
This means they are both 1 if they are both 1 it means the switch has not been pressed since the switch
is active low when we press the switch to switch value the corresponding bit here has to be low.
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
the resort is no one mean and if it's false then our switch has been pressed.
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
simply turn on the LCD by writing 0 x page over here
else we can write we can disable the LCD by saying ls
we say GPL you f
data register and we use the number sunshine over here and add to sign and to X 88 so that we disable
just a bit we want to disable right.
So let's rebuild and see what we have going to click over here to compile it's finished compiling.
I'm going to click here to download onto my board and it's finished downloading.
Okay so I'm going to press the switch one as press the criminality comes on I press it comes on and
then it comes on.
So basically we check in whether the state has changed over here and I hope you you understand this.
If you do not understand the statement just send me a message by it's really simple.
I'll put a comment here
switches octave low right.
So this all there is for this lesson.
If you have any questions just let me know and I'll see you later.
Have a nice day.