Crash Course on C Programming for Embedded Systems Learners | Amit Rana | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Crash Course on C Programming for Embedded Systems Learners

teacher avatar Amit Rana, Engineer, Programmer and Trainer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

31 Lessons (4h 58m)
    • 1. 0. Embedded C course intro

      1:24
    • 2. 1. Install C Compiler on Your Computer

      7:48
    • 3. 2. First C Program

      9:29
    • 4. 3. Inputs with scanf

      4:43
    • 5. 4. Commonly needed Datatypes

      12:57
    • 6. 5. Operators in C : division and mod

      6:21
    • 7. 6. If Condition in C : Part 1

      11:48
    • 8. 7. If Condition in C : Part 2

      4:21
    • 9. 8. If Condition in C : Part 3

      9:32
    • 10. 9. For Loop in C : Part 1

      9:49
    • 11. 10. For Loop in C : Part 2

      5:54
    • 12. 11. While Loop in C

      7:45
    • 13. 12. Arrays in C : Part 1

      12:05
    • 14. 13. Array in C - Part 2

      8:46
    • 15. 14. Array Program : 1

      8:15
    • 16. 15. Array Program : 2

      11:59
    • 17. 16. Char Array : 1

      13:35
    • 18. 17. Char Array : 2

      12:43
    • 19. 18. Char Array : Strings

      8:37
    • 20. 19. Converting int to string

      10:49
    • 21. 20. Using Pointers - 1

      17:14
    • 22. 21. Using Pointers - 2

      8:31
    • 23. 22. Using Pointers - 3

      7:33
    • 24. 23. Functions in C - Part 1

      9:07
    • 25. 24. Functions in C - Part 2

      8:42
    • 26. 25. Functions in C - Part 3

      11:11
    • 27. 26. Functions in C - Part 4

      10:22
    • 28. 27. Functions in C - Return values using Pointer

      11:41
    • 29. 28. Functions -- Using Global Variables

      13:16
    • 30. 29. Functions -- Passing Array to Function

      6:11
    • 31. 30 Functions Char array and strings

      15:37
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

33

Students

--

Projects

About This Class

You started learning embedded systems in excitement but stumble on some basic C programming concepts? Would you like a quick revision to C Coding to understand embedded systems better? Then this course is perfect for you.

This is a Crash Course on C Programming targeted specially for embedded systems learners. This is not to be considered as a full C Programming course but a crash course. Only those topics are included which are mostly used in embedded Systems. Please check entire curriculum before you enroll.

Meet Your Teacher

Teacher Profile Image

Amit Rana

Engineer, Programmer and Trainer

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. 0. Embedded C course intro: If you're trying to study embedded systems and find it difficult to understand the C programming concepts, then there is a good news for you. I have created this beginner's crash course on embedded. See, particularly for you, this course, it's a crash course on C programming, particularly for those who are trying to experiment in embedded systems. We're trying to work on embedded systems, but having difficulty because of the C programming concepts. This is not a detail the C programming course, but it's a crash course which deals out of which explains or give importance to only those concepts which are most important in C programming. There is no detailed theory included in the course, but the course will directly jump start by downloading and installing dollar into your computer and writing some programs to it directly. Most emphasis is given to those points only, which are used for embedded C and 102 times that element C programming tips for embedded systems are also mentioned it to him. Hi, my name is Amit Rana. I am an electronic century or programmer, developer and trainer. I have been working on embedded systems from Australia, and I have also trend more than 25000 students across the world from 150 plus countries. And I have created this crash course to quickly and easily understand the sequence subs for embedded systems people. So if you are looking to clarify this C programming concepts, joint discourse now, Thank you. 3. 2. First C Program: Hi. So let's get started with understanding more about C programming. What you can see on the screen is typically coined as a Hello World program in C language. And instead of going through the theoretical approach where you go from a direct practical approach and try to understand by looking at the screen itself what it means. So the first line that you see its hash include stdio.h. This is called as a directive, which is used to include any additional library into your C program. If you don't use the function out of that library, for example, print f is a function out of this liability. So if you don't use any function out of this library, then it is very well that you don't write this line. It is completely fine. Why I'm telling you this thing is because if tomorrow you go to do some embedded system programming, then you will not see hash include stdio.h because an embedded system doesn't necessarily have a keyboard and a monitor to include the input outputs. So standard input output library is not applicable for Embedded Systems. Far now, let's try to understand it. Or let's try to understand the US since structure, programming structure on a computer perspective, then void main or this male, it's primarily the entry into your program. So whenever you run your program, your program will always run or always start executing. Insert this void man, there is no other place it will execute. It will start executing inside void main. Now let's see One of the program. So let's keep this hash include stdio.h. And let's see what is this function. So print f is a formatted print function which is run or which is used like this. So you write print F and then you open and close or double quotation mark, give a semicolon by the end of every executable line in C and write the statement over here. So this is my trial with C coding. Slash n is an operator which can print new line onto the computer screen. Let's keep it as it is and let's do the build and run. This is my trial with C coding. You can see that now it's okay, this is just an output. Now, how do we accept input? So this is the structure, we just understand this with c. Whatever you write is written in this curly braces. If you write anything out of the Kerberos. Let's see what happens. We've got an error because this is a written outside of the curly bracket. Every executable statement in C will always be within curly braces. Maybe it will meet the main function, or maybe it will be some other function that we have written for some other purpose. But always, every executable will be inside curly brackets, and we'll have a semicolon by the end of it. That is the barebone C programming structure. Now let's start to understand some datatypes. Now what exactly is data types? Let me see. So datatype is something which is used to hold your data into the memory of your computer. Now, memory of your computer doesn't mean the hard disk of your computer. It means the RAM of your computer. Whenever the program runs some computer, the program is executed inside the RAM or Random Access Memory. And there, Let's say I want to perform addition of two numbers. So I want you to have a memory space or some location, some place holder to store those two numbers. In order to store such numbers or any data, what we use in C programming is data types. And they need to be declared very well before we start with the code. Currently, I will not go into the size of the data types. I will just use one data type. It is called deaths inch, and I haven't tried to do something with it. Let's see how do we use in. So you use your data type like this. So inch a comma b, comma c, whatever it is, you can declare like that. Then you can write a value into it. So a is equal to, let's say 58 Humans, Indonesian. I'll just say that for now, b is equal to 74 and c is equal to, let's say a plus b. That's just a mathematical operation I did. Now this is my a tutorial with C coding. That's the first thing we printed. Now I want to print the value of a and B also. And see also, let's, so to print the values of a, b, and c, We write the program like this. So print f, addition of percent, d, percent d, it's specifier when you want to print an integer inside a C print f statement. So addition of percent d. Plus percent d is equal to percent d. The first value is an integer, so percent d, second value is also an integer, so percent d and the third value is also an empty chart, so percent d. And then here you simply pass on those three variables in the exact order you want them to be printed. So first I wanted to bring a, next I want to print B, and next I want to print C. So a comma b comma c. That's so we print the addition of a, B, and C. Let's give a new line here also, so that on that command window we can see the result better. Quote is done. Let's build an RL edition of 58 plus 74 is equal to 130. To see that, let's say if I don't print it correctly, then micrograms correct. But my output may be not correct. So if I pass on C first be letter and a last, they'd only been entered in the same fashion. Okay. It will not do favorites, it will not try to understand what you want to do, and it will just print it the way you have given it. So competitive program is actually done. The human has to make it intelligent. Build and run. Additional 132 plus 74 is 50, and that's definitely not true. But the compiler didn't give you any errors. This is a logical error. However, if you miss something, Let's say if I give single quote over here and sort of double quote to end it against singlehood. Then C compiler giving me an error missing terminating character. So here I should check it. Then if I miss semicolon, for example, somewhere, then if I run the program, it says expected semicolon before printed. So compiler will try to tell you where you have mistaken. If sometimes, let's say you have wrongly tele function. So instead of print F, I wrote only print, then undefined reference to print. It means what the compiler cannot understand what is the meaning of print. So therefore print F, getting it. So this is how a basic addition of two numbers is done. Percent d is used to specify an integer y printing your results using print f statement. However, let me save it. Edition of ambition of no, let me save it in another way. Edition of float, I will call it. Now if you have a number which is a floating point value, and if you are trying to save it in int, and if we are trying to print the result out of it, then see if I build and run it. 5.87.4. That's what I have given, but it's printing something completely different. So this is not what we want, okay? So it doesn't give you any error, but your result is totally wrong. Now to deal with this, what you have to do is here, you will change the int to float. And here are the print specifier. You will change it from percent d, percent f. F is for footprinting. Now let us give it in the correct order, a, B, and C. So this is a floating point variable, a, B, and C. And this is how you will do the floating point addition. And this is how even print the float numbers in. Let's build and run. 5.8 plus 7.4 is equal to 13, 200, 000 something, whatever it is, getting it. So just try out with this two programs and just get comfortable with C. We are going to understand few more things in the upcoming class. That's it for this session. See you in the next video. Thank you. 5. 4. Commonly needed Datatypes: Hi. In this video we'll try to see what are the different mathematical operators present in c. Nothing. Print f and scan f. Both the functions are only available on the computer version of C, but this mathematical operators are present in every version of C, purposefully embedded, see that we are more interested into. So these are the same mathematics, mathematical operator that we will use anywhere with C language. So this asterisk symbol is for multiplication. Just give me a minute. These bullets is causing a little bit of distraction. So let me remove those bullets. So this asterisk symbol, it is called an asterisk. Commonly we also call it star, but asterisk is the name. It's for multiplication. The forward slash is used for division. Percent symbol is used to create a modulus operation or a modulus operator or the remainder of a division. I will show you what is it. And you know about addition, we already did it and the subtraction. So I will omit addition and subtraction for now. And we'll just try to understand these operators for now. Let us try to lose some programs. Since our focus is to understand C from operators trial, embedded perspect to, it is also important now to understand about D. D type very well before you do any such operation. Why I'm telling you this thing in C, we said is 8-bit datatype an int, it's 16 bit data type. Many people think that many of the typical see trainers will tell you that you cannot use cared to hold the numbers. Let us prove them wrong first. So instead of int ABC, Let's make it carry ABC. Okay? Many and I'm telling you many C3 and hours of professional trainers metal that this is a wrong programs, but this is definitely not a wrong program. So we have a car variable, we have return values into it. And let's print it. I will use personally because I have to print the int value is equal to plus infinity comma a comma b, comma c. Look at it. It's not at all mandatory or compulsory that you have to have int in order to perform the addition. Now this is, um, this was a real mistake. Again, I'm coming from Python background, so I'm forgetting print F. Now see 45 plus 10 is equal to 55. Do we get any errors? Do we get any logical errors or any kind of headers for that matter? No. Why? Because scar can very well be used to store numbers. Then why they say you use only into variable in C? Reason is very simple. Now that's what I'm going to explain you. Now, for that sake, I will open an Excel sheet, okay? Now when I say Kara, it is typically an eight-bit variable. Now what do you mean by eight-bit variable? Now, eight-bit variable, when swatch, you can have a number which is in binary. Minimum this correct eight zeros, 1, 2, 3, 4, 5, 6, 7, 8. And at the max this can be 111111 value. Well, okay, now let's say what is this aid 0 in binary means. So this is binary representation. Let's see what is the decimal representation of it over here. So let's do this entire line highlighted to understand, and let's do this. Enter LAN highlighted to understand. So an eight-bit variable can hold only eight zeros, up to eight ones. Open the calculator in your machine. You have a programmer's area over there, or programmers calculator over there. Choose binary format. Just give eight zeros or it is always 0, so 8000, nothing but 0 and decimal. If you give eight ones in binary, then it is 255 in decimal. Okay? So a camera can hold 0 to 255 numbers. Now, 0 to 255 is a very small range to work with. Okay? You're going to understand you can't do much operation within this range. That's the reason why we don't use CAD and we prefer using inch. Now let us try something with this program where we'll try to say 145, or let's say a 100 plus 27, just a number addition. And let's see. 100 plus 27 is 127. 100 plus 28. Let's try this. A 100 plus 20 is minus 120. Now what is minus number? Where did it came from? Here, you have to understand, again, a very important point. And that is, the data types can be categorized as signed character or signed integer, or unsigned character or unsigned integer. I bit, signed or unsigned, signed integer or unsigned integer, where you don't write anything here. When you just write, it is always assumed as signs care. Now the problem with signed care is the most significant one bit is used as sign. So out of 8-bit, if we get only this phosphate is used as a sign character and all of the others are used only as numbers. So when you are using this signed variable or signed character, then you can see your range is limited from 0 to 255 to minus 128 to 127. When this number becomes one, it is treated as negative number. Let me show you this. What we did, a 100 plus 27. So look at the binary version of it. It is seven zeros. It means with a 7 bit number, 127 is the highest number that is possible over there. As soon as you add one to it, let's see, plus one. Then it becomes the seventh number 1 or seventh bit one addressed all zeros. This is 120 inch C programming. If your variable has been characterized as a signed variable, then this is treated as minus 128. And whatever number you give in front of it will come minus 128 plus one, minuss, minus 127 plus 1 minus 126. Let me show you how it may sound a little bit complex for you, but if you re-watch this video multiple number of times, you will get it. So if I run this, it is minus 120. Let us do one more thing. Let's print one into it. Now, minus 128 plus 1, minus 127 plus 10, minus 11, 8 plus 20 minus 1, 0 h plus 28 minus centered. And you're getting it. So this is how the signed numbers are represented in C programming or C compiler. Particularly when dealing with embedded systems, we are not using the negative numbers much, often, at least when you're getting started with it. So it is very, very, very, very, very, very important habit to cultivate that when you declare your variable, declared it as unsigned char, whatever you want. So this is 100 plus 28 plus 20, for example, let's see the addition here. 148. Cool. Now let's make it 200 plus 50. It should be 250. Sorry. Build until 250. Let's say B, it's 55, then it is 255, the result is 255. All good. Up to this. Now the problem will be when I make it 256. Why it's a problem? Because even if your variable is unsigned car and unsigned carries watch, it will be 11, 11, 11, 11 minutes. A hall 0 to 255 range is given to you. But now your result is going to be 256. And an eight-bit variable cannot hold this number because 256 months adding one more digit to it. So in decimal if ferret 256 look at it. So it is one is added and then rest it zeros. A carrier will not be able to store such number. Instead, it will simply store zeros, the remaining zeros, 0. Getting it. Now, if this thing is for Cara, what is it for? End? Exactly opposite. Exactly opposite. So I'm not, not opposite, but exactly the same way. The only thing with int ids, assigned int will have how much numbers? Let's see. It's minus 327682 plus 32767. And an unsigned inch. We'll have 0, 2, 6, 55, 35. This is the range of 16 bit numbers. When vacuum with embedded systems, we always prefer using unsigned int. And in typical situation than we have very less RAM available in the microcontroller memory. We also use unsigned car. Let's say I'm reading some value which I'm no, that is not going to go above a 100. So it's better to use unsigned car in such situation. Let's try it. So unsigned int ABC. Let's get 65535, 4. Let's keep B answer one. Let's print it. The result is 6, 55, 35. There is the last limit. If I do plus one into it. 65536. Okay, Let's see how UPI, how it appears on the compiler. So on embedded at the compilers into will always be eight, 16 bit wide. Here it may be 32 bit number. Let's try this on. Because compilers will act differently. Yes, compilers will act differently on different computers. So on a PC, int is not just 16-bit, but it is a 32-bit variable. But since we are trying to understand things from embedded perspective, understand that on embedded systems, the int variable is having 16 bit value. If you go to a higher version of microcontroller like 32-bit ARM controllers, then you will have to look into the datasheet of those. Most probably the 32-bit compilers will also implement in ads 32-bit value. And the same limitations will come for it. I hope you have understood this datatype very well in this video. If you haven't, just go back again, try some experiments and try to get it fully. Then we'll start with the mathematical operators. The next video. Thank you for watching this video.