(upbeat music)
- Welcome to the third tutorial
in our PIC18F14K50 microcontroller series here
where we are basing this on C instead of Assembly,
as we did in our previous series.
This tutorial, we will actually be doing
the exact same thing we did in tutorial two,
basically a hello world or blinky project,
but we will be using the MPLAB Code Configurator.
The MCC, MPLAB Code Configurator,
which is a plugin of MPLAB IDE.
And we're going to show how, in this case,
it might not actually simplify things too much
because this is such a simple project,
but you should be able to see
exactly how this would scale extremely well
as you're going to much, much more complex projects.
So with that, let's go over this,
just in case you didn't watch tutorial number two,
which if you didn't, go watch it,
but I'm still going to assume you didn't.
And let's just talk about what we have here really quick.
The schematic diagram here
is we basically have our PICkit 4
connected to our PIC18F14K50,
and all it will be doing is programming it
and providing power.
And then we have our resistor connected to pin 16,
and then our LED connected from our resistor to ground.
And that is it.
So the schematic is extremely straightforward,
and all we are going to be doing here
is toggling it on and off every 50,
or every half second turn it on,
half second turn it off, half second turn it on,
and that is all we are going to be doing.
So with that, let's actually jump in
and start looking at MPLAB
and exactly how the code configurator works,
and how it can simplify things.
Okay, so this is the bare MPLAB X IDE,
and they have their splash screen right here
that I got rid of,
and I deleted all my previous projects
to make it completely clean.
So just like we did in tutorial two,
we will want to start a new project.
So, we just go up here to new project.
Again, it will be a standalone project,
even though you'll see this MCC Harmony right there,
that's not what we want.
We want the standalone project.
We click next, then we select our PIC,
which again, this is gonna be the advanced 8-bit version
of the PIC18F14K50, right up there at the top.
And, I will be using the PICkit 4, as I did previously.
Not going to have any support debug header.
And we are going to be using the XC8 compiler.
And let's just call this BlinkyLED_MCC,
'cause we will be using the MCC.
Set as main project, use project location as project folder.
Hmm, interesting.
Nah, I think that's fine.
Leave it alone, encoding, now finish.
Now, you'll notice here, as this is loading,
that I have this button here, the MCC,
and that's very obviously what we want to go into,
but this doesn't come as part of it.
It might, you might have it already,
you might have selected it
when you were downloading it, whatever.
If you did not, however, you can go up to tools and plugins.
And it will pop up and have updates available,
plug-ins, don't even worry about all that.
Just go to search MCC, go to,
well, it'll be available probably.
Let's try that again.
Well, for you it'd be available.
For me it's installed, because it's installed.
Either way, go to whichever one works for you,
search for MCC,
and then you will see MPLAB Code Configurator.
And if you have not already downloaded it,
select it, and download it,
and activate it, and all that sort of stuff.
I actually had to download a couple
of other different things.
It took a while, probably five, ten minutes
for it all to download
and for the first time to run through.
And if that's the case, just pause this video,
let it run through its thing.
But once it is done and you have restarted MPLAB,
then you can come back to this point
and finally click on the MCC button.
So it takes a moment.
There we go.
All right, so we have our content manager wizard,
and as you can see, you can only click on the MCC Classic.
It makes things easy for you.
So we click on that,
and then we have our required content
and our optional content.
So there are additional things that we can use here,
which if you want you can go through
and look at them for yourself,
like the USB framework, that looks fascinating.
Something that we might be able to use later.
You have your digital analog converter,
you have a boot loaders.
I know Sergey loves boot loaders,
so I wouldn't be surprised
if we do something with that later.
But for right now, we can just hit finish,
and it will once again take a little bit
of time to put everything together.
All right, fantastic.
Now our entire screen has changed dramatically,
and so let's just take a moment
to go over what each one of these windows represents.
But frankly at this point,
I highly recommend you just pause this video,
and you kind of click around,
look at it, figure things out.
The only way you're gonna become comfortable with this
is if you just spend some time messing around with it.
I can say, "Hey, this does this, this does that."
But you're not gonna really understand
how it's all connected until you're clicking
and you are figuring it out yourself.
So if you want to,
feel free to pause the video and mess around,
or you can do so after I go over the different areas.
So we're basically going to have our five different parts.
We have one, two, three, four, and five down here.
This down in the bottom left corner.
That's exactly what we had previously.
It's just giving us a little bit of information,
and it's not necessarily MCC-related.
So up here in the top left corner,
we have the resource management area.
So it's basically just telling us
what our different resources are.
And as you can see, when I click on the different ones,
it changes here in the main window.
Our second one down here, this is our device resources.
So it just gives us a a list
of some of the resources that we have.
As you can see, we have the ADC, the comparator,
DAC, ECCP, the UART on all those sorts of things.
And so this is just our device resources area.
Finally, as I mentioned, this is our main window,
and this is where we primarily work and play,
where we make the majority of our changes.
And then over here we have our pin manager
where you can manage and look at all the pins visually,
and right away you might notice that,
hey, wait a second, this is a QFN module,
not a DIP package,
which we will take care of
as we come down here to the pin manager window.
So this is the pin manager package view,
and then this is the pin manager grid view.
So this is where you can control each one
of those pins, and we will do so in a second.
But first things first, since I don't have a QFN pin,
we want to change this to a DIP.
So if you watched the first video, you will remember
that we had to configure the bits all independently.
That was something after we did all of the software
or all of the firmware in the main portion of our program,
we actually had to go configure the pins
and then copy paste it up at the top of our program.
And it was a bit messy.
However, in this, under our main window in the easy setup,
we have all of this stuff,
and frankly I haven't made any changes to it.
It automatically went to the internal RC oscillator.
Internal clock is one megahertz,
and it's all set up basically how we want,
even with the watchdog timer controlled by the SWDTEN bit.
So, very nicely it creates a lot of these configurations
that we had to do manually before.
The only thing that we will want to change in this
is that we want to get rid
of the low-voltage programming enable.
So here we've gotten rid
of the low-programming voltage enable.
We made sure everything else
is good to go the way we wanted it to.
And let's just take a moment
to look at our interrupt module and our pin module,
and notice that there's nothing going on right now.
And with our interrupt module,
we're not gonna do anything in this tutorial.
It's not a big deal.
We're not gonna be touching this.
We will later though, definitely,
but in this pin module,
it says no configurable pin selected,
so we need to change that.
Now, since we are using the exact same setup
as we did in tutorial two,
we know that our resistor is connected to pin 16,
which is RC0.
So as we go down here,
we can find Port C, pin 16, and let us make that an output.
So I can literally just click right here,
and hey, now it's an output.
That's all I had I needed to do.
And notice how it basically made it so
hey, you can't use it as both an input or an output.
And as you change this, as you modify these,
you'll notice that they're connected
so that it makes it simpler for you.
So you don't accidentally say,
"Hey I want to use this pin as both an analog input
and also as a interrupt input."
Like, oh, wait, that that doesn't really work.
Then that can be something that happens
if you're not being careful here.
This forces you to say,
"Oh, this is going to have some sort
of traffic jam with some other input or output or pin."
And it takes care of that for you,
which is a nice little feature.
So now we've selected that,
and you can see it's actually popped up
here in our package view,
and it's obviously here under our Pin Modules.
Now we can give it a custom name,
and I want to call it BlinkyLED,
even though Sergey in his tutorial called it LED1,
which is much more professional.
But this is the opportunity
where we can look and say the pin name is RC0, as we know.
It's a pin module, it's a GPIO.
That's what it's set up to be right now.
We can say, "Hey, we want it to start high,"
which we don't, so we're just gonna leave that alone.
It defaults to being analog, which we don't want,
so let's click that.
And it says its output, which is exactly what we want.
And I'm curious, if I click this,
does it change down at the bottom?
Oh yes.
Oh yes it does.
See, it's beautiful when things work the way they should.
I also want to note that over here
you can see that my custom name of BlinkyLED
popped up right there.
So again, makes things nice and simple.
So even though we won't use these,
there are a couple more options
that we might use in the future.
And that's just your WPU which is your weak pull-up.
Your OD, your IOC,
so your interrupt control and stuff like that.
And since we can't,
since RC0 doesn't even have these options,
notice there is nothing to select.
So now unless I missed something important, we are ready.
So let us go back up here,
and we can generate our MCC code.
And this might take a moment as well.
So it's creating a bunch of files, interlinking them,
and making everything beautiful.
Now that things are done, we can jump over to projects,
and you'll notice that it created for us some header files,
device config dot H, MCC dot H, pin manager dot H,
and then also some source files,
which is our main dot C,
and our device config dot C,
MCC dot C, and pin manager dot C.
Now these are interesting
in that you don't really want to touch
any of these MCC generated files.
Nothing in these areas do you want to touch,
but they are great to look at.
And I think the most important one
would be your pin manager dot H.
And this is where it tells you
some other things that you can do.
So if you remember from tutorial two,
to do the pin toggle we had to do that XOR command,
and it was simple but not exactly straightforward.
Whereas with this, if you come down,
you can see that MCC creates it
so that if I want to toggle things,
all I have to do is call BlinkyLED_toggle,
and it will do this work for me,
and it'll toggle the bit for me, and it's fantastic.
So this pin manager dot H is a great resource
to check to see what has been automated for you,
so you don't have to write more complicated code
that's already been done for you.
And not that any of this is complicated,
but it's nice to make it even more simple.
So you can see here we can change the input output,
the port, set high, set low, the toggle,
get the value, all these sort of things.
So again, this pin manager dot H is a very useful resource.
Then we also have the MCC dot H and the device config dot H,
which are also nice to look at
if you need a little bit more information,
but I don't think that they're nearly as helpful
as that pen manager dot H.
Yep, I don't even know if this device configuration
does show the crystal frequency of one megahertz.
So fantastic, let's close these,
and open up main dot C.
Okay, so it should be noted that until this point
we have not written a single line of code.
We have not done a single thing.
So now we are finally in main dot C,
and to blink this LED,
we will only need two lines of code.
Now, I'm going to close this commented code,
because it's kind of annoying,
and you can just delete it.
It doesn't really matter.
Oh yeah, I think I might just delete it,
'cause those, just I don't need those to pop up.
Okay, so it includes instead of the XC dot H
or XC8 dot H, it just includes MCC dot H,
and then it gives you a couple of things like,
oh, do you want to enable the peripheral interrupts?
You just uncomment that line.
Do you want to disable them?
Uncomment this line.
So it gives you a couple of more things, but again,
we're not gonna be using interrupts in this,
so we can completely ignore that
and delete it if we want,
but I'm not going to worry about it too much,
'cause it's not as long and obnoxious as the other.
But finally we are down here in while one,
and all we need to do is add our application code.
So let me copy in my code really quick.
Okay, so I just copied in my two lines of code here,
and you'll notice a slight difference
from mine versus Sergey's written tutorial,
and that's because he named his LED1,
and I named mine BlinkyLED.
But you'll notice that all I have here
is the BlinkyLED_Toggle,
and then a delay of 500 milliseconds,
and that's it.
That is all we have to do.
Now the funny thing is that we spent,
I don't know, five, ten times longer
doing the configuration.
And so from a purely practical standpoint on this one,
this doesn't necessarily make sense,
but hopefully as we went through this you could see how,
oh, if I want to use all of these different peripherals,
or if I want to use all these different interrupts,
if I wanna use analog, whatever,
that this will significantly ease the pain
and time consuming minutia
that sometimes can be overwhelming
when you're dealing with embedded systems.
So with all of this,
despite everything else being simplified,
you still need to go in and make it
so when we run this it is getting power from the PICkit 4.
So let's go to our BlinkyLED MCC project, properties.
Wait for it to load, PICkit 4, power,
power target from PICkit 4.
And then let's change that to 4.75 again,
'cause that seemed to work so well last time.
And then hit okay.
Now if I didn't miss anything, when I hit upload,
it should build and upload just beautifully.
Let's cross our fingers.
Make.
Build successful, connecting to programmer.
Yes, I know that I need this to be five-volt tolerant.
All right, there we go.
And the LED is blinking, and once again we are successful.
So that's really it for the MPLAB Code Configurator.
It can be a bit daunting at first,
but as you get more used to it,
it'll be quite straightforward.
We were able to get this LED to toggle on and off.
Now, Sergey loves practicality.
He loves getting his hands dirty,
and he realizes that the best way to learn
is for you to get your hands dirty.
So as homework assignment,
he thinks that you should do the same exact circuit,
but add another resistor and LED,
and make it so they turn on and off
opposite to each other,
just so you get your feet a little bit more wet,
you venture out there a little bit,
and really, truly understand what's going on here.
It's not too difficult,
but it should be a fun challenge for you.
So I highly recommend you do that.
If you found this interesting,
please give this video like, (mouse clicking)
subscribe to our channels so that
you can get notifications (bell ringing)
for the rest of these tutorials as we go through them.
Have a great day, and we will catch you in the next one.
(toaster shifting)