Transcript for:
Overview of 8051 Microcontroller and Memory

hello people i am acharya let's continue with our second lecture so here i'm going to tell you about the processor and the memory of eight zero five one so what do you know eight zero five is a microcontroller it has internal processor memory and io our first focus is on the processor so ad51 has an eight bit processor that's how we say it what does that mean it means it can do eight bit operations in one cycle simply what means is when you say add there is an instruction add whenever you learn the instruction set you know it right you are adding two eight bit numbers at a time in one operation so here get get this clear what is an 8-bit number and what is the 16-bit number and 8-bit number has the range 0-0 to ff please get a few things crystal clear we write every number in hexadecimal when i say v i'm not only talking about myself or us teachers including you including programmers when you do programming you type when you're typing a program you'll be giving numbers every number you give is in hexadecimal form are you clear inside the computer the number will become binary okay so 0 0 will be zero zero zero zero zero zero zero zero ff will be one one one one one one one you know every digit takes four bits correct i'm sure you also know the shortcut to get the value of any number eight four two one is the break up so suppose you want seven seven is four plus two plus one so i don't need eight so i'm putting a zero but i need four two and one so this is seven i want 3 3 is 2 plus 1 so it is 0 0 1 1 i want 6 6 is 4 plus 2 so that is 0 1 1 0 i i hope you knew this but even if you didn't i hope now you understood how to get any number instantly in binary right so f is fifteen fifteen means eight plus four plus two plus one so one one one one again one one one one so that is zero zero to f that's your range this is the range of an eight bit number a sixteen bit number on the other hand now you tell me you tell me a 16 bit number will go from zero zero zero zero four digits up to f f f in binary form it will be sixteen zeros up to sixteen ones are you clear come on let's do a small quick exercise tell me what is 34 it's a how many bit number eight bit number correct one two three four sixteen bit number six one seven zero sixteen bit number three nine eight bit number right uh four one seven six sixteen bit number are be clear tell me four one seven six in binary you have to be very fast at this because you need it all throughout the subject what's the point of having a problem every time rather put an effort and get clear this clear immediately right in the beginning so four one seven six is four this is four one this is one seven six this is four one seven six in binary last one six one seven zero oh it has the same digits pretty much the same digits uh two f uh seven nine as an example two f seven nine two is zero zero one zero f is one one one one seven is zero one one one nine is one zero zero one okay are we clear so these are sixteen bit numbers and these are eight bit numbers is the concept of 8-bit and 16-bit number clear so when i say the processor is an 8-bit processor it means it can operate on 8 bits at a time so i want to do 24 plus 35 all hexadecimal right answer is 5 plus 4 9 2 plus 3 5 59 it can do this in one cycle are you clear whereas if i want to do 1 2 3 4 plus 3 1 5 2 as an example of testing some numbers here it will require two cycles these are 16 bit numbers the processor is an 8 bit processor it will break it down into two cycles first it'll add this of course it doesn't directly do 16-bit edition we'll be doing it in in a program but the idea is the same that we'll be doing in two steps first we'll add the lower bytes four plus two is six five plus three is eight then we'll add the higher bytes two plus one is three three plus one is four of course when you add the higher bytes we are going to take the carry that goes from lower byte to higher byte of course i'm gonna teach you all that when we do programming this is right now in introduction so i wanted this to be clear to you what is the meaning of 8-bit processor add subtract multiply divide and or xor these are the arithmetic logic operations that we do there more also rotate and all which you'll see when you see the whole instruction set they are all eight bit operations are we clear right higher processors are 16-bit processors 32-bit processors modern era is a 64-bit error it can do 60 so modern processors 64-bit processors they do 64-bit operation in one cycle can ad51 do 64-bit operations yes please don't say no okay you are an engineer you're going to engineer the idea it can do 64-bit operations but it'll take eight such small operations such parts of operations to add to 64-bit numbers but of course it can add 64-bit numbers will just take much more time so modern processors are much faster because they have bigger processing units 8051 didn't need that for the generation that it was in eight bits was enough and whenever you do intense programming with ad51 you'll understand it delivers on point whatever task is fit for ad51 it delivers on point anyway so it has an 8-bit processor it has internal memory what form of memory rom as well as ram rom is used rom is of size 4 kb ram is of size 128 bytes okay sorry for background writing 4 kilobytes 128 bytes understand what rom and ram are used for microcontrollers are not used in computers the big difference between using a computer and using an appliance in your computer you change its programs on a day-to-day basis you do coding i'm sure you have done or you do intend to do in the future so you can write your own programs run them do them as many times as you want so your memory in which you write your programs should be writable memory whereas whereas microcontrollers are used in appliances now this is an appliance tell me does it have a program of course that's what runs this remote are you ever going to change this program do you change this program on a day-to-day basis do you intend to open this remote and rewrite its code no these are permanent programs okay so my program should not be need not be stored in a memory where i need to write on a daily basis further something very important this remote has this as your power supply the batteries right i have removed the batteries right in front of you so power supply is gone should the programs be lost no if i put the batteries back and i shut this should i say some prayer before i use it hoping that it'll work no it should work right and it does work i'm not sure whether you can read what is there if you trust me and you trust the cameraman there is evidence it still is working pretty much how it's supposed to work that means the programs are not lost that means the programs are stored in raw i told you stop behaving like a layman start looking at the world like an engineer these things should come to you naturally the next time for the next device that you evaluate the programs need not be changed but the programs need to be there even if power supply is lost same applies to your fridge or your tv or your washing machine you switch off your washing machine you switch off you shut down the power supply of your whole house you go for a long vacation you come back you turn on the appliances they should still work the program should not be lost you don't want to change the programs on a day-to-day basis you'll never change the program of your fridge or your washing machine but it should work even after losing power supply and getting it back the program should remain where they are that means programs must be stored in permanent memory which means programs must be stored in rom so henceforth in microcontrollers you are learning 8051 your focus is on microcontrollers whenever we say program memory we are talking about rom are we clear the other word for rom in microcontrollers is program memory are we clear right this is not true for computers in the computers you in the computer you change your program on a day to basis but in a micro controller you don't so programs are stored always in rom are we clear so what is stored in ram data data in a microcontroller is changeable today i want the ac temperature to be 24 that doesn't mean tomorrow i want it to be 24 tomorrow i can make it 23 i can make it 20 i can make it 18 when i'm cooking food today i need so-and-so temperature for cooking i don't care what temperature i cooked in yesterday today i'm cooking at so-and-so temperature that means this data is going to change every time you cook and when you switch off and you switch it on you don't want that data again you are going to enter your own data so your data doesn't need to remain even after power supply is lost which means data will be stored in volatile memory which means data will be stored in ram are we clear so programs are stored in rom data is stored in ram henceforth when i say the word i or wherever you learn all of 8050 and from whenever your teacher says data memory the teacher is talking about ram and your teacher says program memory he or she who is your teacher is talking about wrong are we clear now look at their sizes rom is of 4 kb ram is of 128 bytes when you look at these numbers for the first time you feel what nonsense what is this why would you you work with such a small processor 4 kb of rom is just to today we talk about megabytes not even megabytes in megabytes outdated we talk about gigabytes and terabytes correct that's the modern world i told you 45 years have a lap since this was me it's not that this kind of memory is outdated if you understand where a microcontroller like 8051 is used these memories are far more than sufficient keep one thing in mind when you're learning 8051 it has stood the test of time since 44 years since it was made it's been taught and is still being taught in universities all around the world i have students have my website that have full courses of these processors i've been physically teaching since 20 years virtually online i've been teaching since the past four years i have students from all over the world and they all learn 8051 so what you're learning is tremendously successful and is an ideal standpoint so never question what you're learning okay i'm not trying to preach here i'm just saying some students try to build a wall between themselves in the subject just to get an opportunity to get away from it so that shouldn't happen these memories are way more than sufficient when you understand where to use them say for example 4kb rom 4kb rom means you have 4000 bytes actually four thousand four multiplied by one zero two four four zero nine six bytes but i'm keeping it simple four thousand bytes in rom you store programs that means instructions instructions can be one by two byte or three byte let's take an average two byte okay so that means there are two thousand instructions that you can store on an average around two thousand instructions now you tell me do you need two thousand instructions to run this remote no way what is the program like i said it doesn't have to run windows or doesn't have to have any fancy os its first program is to identify the key that is pressed that's a one and a half page program right its next program is to display something on the lcd that's again one one and a half page program the last program is to do serial communication that's a two-page program what is that all together about 300 lines of code what did i say you have the capacity of putting 2 000 instructions whereas 300 to 500 instructions are enough to run the program of this device and much much lesser to run the program of this device just to identify one of these two keys next is to send either lock or unlock the program for it is the same you just send a different number for lock and different number for unlock and the next is to encrypt the number and send it all of it will not require more than 200 lines of code and you have the scale scope of 2 000 instructions is suddenly this memory seeming to be quite sufficient next look at ram what is the size of ram 128 bytes what does that mean you can store 128 such numbers this is one by eight bits is one byte so you can store 128 such numbers what data do you want to store in this do you want to store songs do you want to store movies you want to store my face no what do you want to store you want to store the temperature that is a one byte number a temperature temperature is in this range of course it won't even go up to ff it's an ac for crying out loud the temperature won't cross 30 35 so 0 to 35 i won't even go up to zero so 16 to 35 or whatever even if it has to go from 0 to 55 that can be stored in one single byte one byte is what you need to store temperature one byte is what you need to store the mode one byte for the fan speed three bytes timer okay you have an on time two bytes for that off time two bytes for that two plus two four plus three seven seven bytes is all you need to store the data over here that's all you need throw in another 30 37 throw another 40 by 47 still you have 128 bytes of storage space i'm not trying to sell 8051 to you don't get scared all i'm trying to make you understand is these numbers are far more than sufficient when you understand where ad51 is used and if you want to build some really challenging application and you feel you need more memory you always have the freedom to connect external memory you can connect external ram also external rom also though in most cases you don't need it but the scope of expansion is always there like a phone comes with internal memory but most phones not apple but most phones allow you to put those memory cards inside so it has internal memory but it allows you to expand it cameras they come with internal memory allow you to put which you need to put because internal memory is quite less you put those memory chips inside so there is always a scope of increasing memory if need be but in most cases it's not required so that was the idea of this lecture to tell you what is the processor make you understand what these memories do and well what is the significance of their sizes hope you understood it next lecture we'll be looking at the i o section