Welcome to the third tutorial in the simple microcontroller series.
In this tutorial, we're going to talk more about the architecture in the memory and the
registers of the PIC10F200.
So we're going to go over a little bit about how that all works, and how it's important
to you.
So first of all we talked about earlier, and I think it was the first tutorial, how there's
only 256 words of flash memory or program memory in the PIC10F200.
Now the Atmega328P has 32K of flash memory.
And you'll notice that I'm saying 32K of bytes versus 256 words, and you thought, that's
weird, why does the PIC10F200 have 256 words, while the Atmega has 32K bytes, it's because
the PIC has a set, a constant, instruction length of 12 bits.
And so if we took it out, and we multiplied 256 words, times 12 bits and then divided
by eight to get the amount of actual bytes it is, that would come out to be 384 bytes.
Okay, that that doesn't mean anything, what we want to know is how many instructions we
can put in and actually use, which is 256.
So if there's any confusion about that, I just wanted to put that out there.
And that is why we say words versus bytes, because the bytes just don't make a whole
lot of sense.
And the words do and moving on.
So let's go over really quick, a couple of the stats of the microcontroller.
And the first one is the microcontroller runs at four megahertz.
Now each instruction takes four cycles or four ticks to execute.
So in reality, you can execute 1 million instructions per second.
So even though we have the 4 million clock cycle, we have 1 million instructions per
second.
We also have three GPIOS, which are general purpose input output pins, so that they can
be used as either an input to measure something or to receive data for some from something
else or as an output.
When you want to light up an LED or communicate with something else.
We also have one input pin, it cannot be changed.
And so you have three input output and one input pin.
Let's look at the actual pinout really quick.
And we can see that if you have a six pin package, you're using up all the pins, but
since we're using a DIP, you'll notice that there are two No Connect pins.
That's because there's no reason for them.
But the standard eight pin package is what they used for the DIP.
So we'll ignore those No Connects.
And you'll notice that other than VDD, which is power, and VSS, which is ground, all of
the other pins are shared.
Like it says GP3 along with something else, what that means is basically within the program
itself, you can say I want to use this as either a clearing pin to do a master reset,
or I want to use it as a GPIO.
And as you program it, you make that selection.
So as I mentioned, there's GP0 through GP2, so GP0, GP1, GP2, and those are the input
output pins.
And then there's GP3, which is the input only.
And then you've got MCLR, which has a bar over it, which basically means that when it's
high, its inversed.
So that basically means that to clear it, you want to pull that down instead of put
it up.
So that's what that bar means when you look at the symbol there.
And then there is the ICSP, In Circuit Serial Programming, clock CLK and the ICSP data.
And those are just lines that when you're communicating with your programmer, those
are what you connect to, so that your programmer can actually control the microcontroller and
send in what program needs to be in there to run it.
Right.
Okay, so that is what we have to work with here.
Now let's talk really quickly about the, the software that you put on there, the firmware.
So you have the flash memory.
And this is where you put in your data.
And this is the program that you actually want to run.
And when you remove power from it, that data stays in.
And that's very important.
And that's different from the data memory that we'll go over in a second.
So there's a lot of things to think about.
But we're only going to worry about a couple of things in this video, if you want to get
into a little bit more depth.
The written tutorial has a little bit more detail.
But for right now, I just want to focus on the fact that you have your addresses that
go from 0000h, which h stands for hexadecimal, to 00FFh.
And if you are confused about the F's and you don't know what hexadecimal is, we strongly
recommend you learn more about that before moving on, because we will use that all the
time.
So within that space, you have a lot of different things.
But the big things are the PC, the program counter.
The reason this is so important is because this actually tells your your controller where
you are in the program, it takes a program and it moves from line to line and it executes
this then moves to the next one, execute this, moves to the next one.
But there are certain commands that will make it jump around to different places in that
PC, that program counter will change.
Basically, if you use a GOTO or some sort of subroutine, it'll change that, which actually
brings me to the next thing that we need to worry about.
And that is the stack.
So you have two levels of stack in this microcontroller.
What happens is when your program counter is going along, and it goes and does a subroutine,
let's say we want delay subroutine, and it says, oh, okay, I'm going to jump down here
and execute that code, what it's doing is it's remembering where it was by taking that
program counter, putting it into the stack, putting the new program counter in, so it
goes down to the subroutine you want, runs that subroutine, pulls that address back from
the stack, and then goes back up into the place that was in the program.
Now the reason there's two is because sometimes you'll be in a subroutine, and you want to
call another subroutine.
And so it'll take that address and stick that into the stack as well run that other subroutine,
go back to the first subroutine, and then go back to the very original place that you
were at.
Now, if you want to call a subroutine inside of a subroutine inside of a subroutine, it'll
fail.
There's not enough space in the stack, there's only two levels.
So you might forget this right now.
But sometime you're going to try and do that.
And it's not going to work and you're going to be like.
Ah yes, that's what I did wrong.
You can only do that twice, because you run out of space in that stack.
And the whole program just crashes.
And finally we have the data memory.
Unlike the flash memory for the program, this memory gets erased every time it loses power.
And this is where you have things like the special function registers.
And where you keep your variables it's acts like your RAM.
So, really quick, I want to go over the special function registers, there's quite a few of
them, they take the space from 00 - 10.
And the biggest things that we're going to be using at first are going to be the GPIO
register, which is where you can control the output of the pins.
That's where you say write a one to this pin or write a zero, so it's high or low.
And then there's the TRISGPIO register, which is where you control whether or not that pin
is an input or an output.
So we're going to be using those quite a bit from the very beginning.
And so those are the two biggest ones.
For the rest of the registers, we briefly go over them in the written tutorial.
But again, they're not quite as important at this point.
And we'll cover them later.
Now finally, since we have 10h for our special function registers, we have from 10 - 1F as
our variables.
And so if you look at that, you can see obviously, we have 16 bytes of variables that we can
use our 16 bytes of RAM before we just run out of space.
And so again, the PIC10F200 is a very simple, very, small microcontroller.
But we're still going to be able to do some pretty crazy things with it.
And that's it.
So now we've gone over kind of the basic architecture of the PIC10F200.
Why we use words instead of bytes to talk about the programming space.
We talked about the stats, so how many GPIOs we have available in the clock speed and stuff
like that.
We also talked about the program memory, how that works, the things that we need to worry
about here at the beginning.
And then we also talked about the data memory, how that works, and the things that we can
change that we need to change.
I hope you found this video interesting.
I hope that you come back and join us on the next tutorial.
We basically only have one more tutorial before we actually start building the circuit and
start doing things with it.
Right now, we're laying that foundation, and we're getting some good stuff so that we're
ready to move forward.
Like this video, subscribe to our channel and we'll catch you on the next one.