basics of 8051 microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by PG1995, Mar 15, 2012.

  1. PG1995

    Thread Starter Active Member

    Apr 15, 2011
    753
    5
    Hi

    I have started learning 8051 microcontroller using this book. You can see the list of the chapters in the attachment. In first five or six chapters the book uses assembly language and afterwards it uses C language. I have some basic knowledge of C++ programming.

    Is there any software available (I'm sure there would be one) which I can use to learn the basic assembly language programming, or programming in general, of 8051? For example, when I was learning basic C++ I used CodeBlocks compiler. The compiler, simulator or whatever you want to recommend me should use graphical user interface (not some DOS kind of stuff). Thank you for your help.


    Regards
    PG
     
  2. steveb

    Senior Member

    Jul 3, 2008
    2,433
    469
    Is this a class with a lab course associated with it? Most microcontroller type classes have a lab section in which the concepts are applied on real hardware. If so, then I would recommend you use whatever tools are used in the lab.

    Also, page X or your book recommends two assemblers, and the diskette that comes with the book provides more information on those.
     
  3. PG1995

    Thread Starter Active Member

    Apr 15, 2011
    753
    5
    Thank you.

    The course does have a lab associated with it but I don't it would help me much because the instructor doesn't know much about the stuff and this is the first time he is conducting the this lab.

    Yes, I have checked it; the page X has the recommendations (e-book version doesn't contain page X). The link mentioned on the page has good stuff.

    1: Do you have any idea which one of the two, Proview32 and Keil, is a good one?

    2: When we can also use C language to program the 8051, then what's the advantage of using the assembly language?

    3: The link also mentions a trainer. Is there some kind of virtual trainer available in the form of a software? I have found these:
    http://mcu8051ide.sourceforge.net/
    http://www.edsim51.com/

    Thanks a lot for the help.

    Regards
    PG
     
  4. steveb

    Senior Member

    Jul 3, 2008
    2,433
    469
    First of all, I hope someone else here will step in and help you more than I can. This is not a subject I know a lot about. I used the 8051 back in the 90's. I can't even remember the tools I used. I'll do my best and I encourage anyone to shoot me down without mercy if I give bad information.

    Wow, that is sad. Hopefully another student in your class will have experience enough to teach both you and your instructor. :mad:

    I guess you should ask a lot of questions here and hopefully an 8051 expert will step in on the harder questions. Also look for other forums and sites that focus on the 8051.


    I don't, unfortunately, for the reasons mentioned above

    It depends on your skill and creativity.

    In the old days, we used to try to do most of the programming in C and then write assembly routines on sections that ended up being too slow. Sometimes you can use assembly to streamline the program because you are one step closer to understanding the lower level hardware.

    Before that, we did it all in assembly, and before that I even did programming at the machine code level.

    Nowadays, I do it all in C. I figure if that is not good enough, then I chose the wrong processor. :p

    Sorry, I'm not sure.
     
    PG1995 likes this.
  5. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    Here are my 2 cents worth.

    If you just want to get a project done in a hurry, get an Arduino.
    If you want to learn how to develop embedded systems, programming in C is sufficient.
    If you want to build a solid understanding of how any and all microcontrollers work, learn ASM first before learning C.

    I have never used an 8051 but this is not a bad MUC to learn. You will discover that once you master a MCU of this type, it becomes easy to adapt to many other MCUs (the exception is the Microchip PICs).

    It will be best to find a good introductory book on the 8051 or MCS-51.

    I would also recommend reading:
    "Understanding Small Microcontrollers" as a starting point, even though this is about the Freescale HC05 family. It will introduce you to all aspects of MCUs in general.
    (332 pages, 2.7MB pdf)

    http://www.physics.mcmaster.ca/phy4d6/Docs/M68HC05TB.pdf
     
    PG1995 likes this.
  6. PG1995

    Thread Starter Active Member

    Apr 15, 2011
    753
    5
    Thank you very much, Steve, MrChips.

    @Steve: I appreciate your effort to respond to every part of my previous post. I'm happy that the world has moved on and people don't have to write machine codes any longer! :)

    If someone has experience with Keil μvision software, then please let me know. I need your help. Thanks.

    Best wishes
    PG
     
  7. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    That is the wrong attitude.
    Learn ASM.
    It doesn't hurt and wouldn't hurt.
     
  8. PG1995

    Thread Starter Active Member

    Apr 15, 2011
    753
    5
    Hi MrChips

    That has also happened in the past few times that you misinterpreted me! :) I didn't say I won't learn assembly language. Actually I have started working on it because the book I use first exposes the reader to the assembly and many persons including you suggested to first learn the assembly first. I'm still happy I don't have use strings of 0's and 1's for coding.

    Regards
    PG
     
  9. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    For many years we taught machine coding by entering 0's and 1's into the front panel of DG Nova 2 mini-computers using toggle switches. This is still a great way to learn about computers.

    How can you understand calculus if you do not understand basic arithmetic?
     
    PG1995 likes this.
  10. PG1995

    Thread Starter Active Member

    Apr 15, 2011
    753
    5
    Hi

    As I mentioned above I have some experience with C++. While writing C++ code, every code has to start with int main(). In the book I'm using to learn coding of MCU using the assembly, some programs start with ORG 0H and some don't. For example, the code below (have a look on the attachment to see what the code does) doesn't use the line ORG 0H. What do you have to say on this? Pleas let me know. Thanks.

    Code ( (Unknown Language)):
    1.  
    2. MOV  A,#55H
    3. AGAIN:  MOV  P1,A
    4.         ACALL DELAY
    5.         CPL      A
    6.         SJMP     AGAIN
    7. DELAY:  MOV  R5,#2
    8. HERE1:  MOV  R4,#180
    9. HERE2:  MOV  R3,#255
    10. HERE3:  DJNZ     R3,HERE3
    11.         DJNZ     R4,HERE2
    12.         DJNZ     R5,HERE1
    13.         RET  
    14.  
     
    • IMG.jpg
      IMG.jpg
      File size:
      97.5 KB
      Views:
      24
  11. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    Do you start your day with coffee, tea, juice or do you brush your teeth first?
     
  12. PG1995

    Thread Starter Active Member

    Apr 15, 2011
    753
    5
    Okay. So, the code starts with ORG 00H and ends with END. Thanks.
     
  13. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    Not exactly.

    ASM is like any other language. You have to learn the language and the reasons for using certain words.

    In this specific example,

    1) you can use ORG 00H,
    2) you can omit it,
    3) you can use just about any value, such as ORG 0, ORG 5, ORG 25, ORG FFH and you probably will not notice any difference.

    Just learn the reason it is there.

    In ASM, don't take anything for granted. The purpose for learning ASM is so that you can become an expert and not just a middle of the road programmer.
     
    PG1995 likes this.
  14. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    When you get on the bus, do you like to sit at the front, in the middle, or the back?
    Do you take the window seat and leave space for someone else?
    On a double-decker, do you like to sit up front on the upper level to watch out?

    That is what the ORG statement does. It tells the assembler to instruct the loader where you want to begin your code in memory. You get to choose. (The default starting location is 0).

    With a C compiler, the loader puts you where ever space is available. You don't get to choose.
     
  15. PG1995

    Thread Starter Active Member

    Apr 15, 2011
    753
    5
    Thank you for the explanation, MrChips. I understand it now.

    Best wishes
    PG
     
  16. Arm_n_Legs

    Active Member

    Mar 7, 2007
    183
    10
    Hi,

    You can learn 8051 assembly language and C programmning using the eval version of the Keil uVision 4. It has an assembler, C compiler, and simulator. If you want to learn it by programming with a hardware, you can try the Silicon Lab eval board (http://www.silabs.com). The eval version of Keil uVision 4 is usually bundle with the Silab eval kit.
     
  17. @android

    Member

    Dec 15, 2011
    178
    9
    1. Keil is good. I've used it. Easy to use.
    2. Using assembly language requires knowledge about internal architecture of uC + instruction set. But definitely assembly language improves your skills in programming because it doesn't offer flexibility like C.
     
  18. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    My advice is - make certain that you learn and understand ASM first.
    After you have mastered ASM, you can do all your programming exclusively in C, knowing that you are confident with what you are doing.
     
  19. @android

    Member

    Dec 15, 2011
    178
    9
    And yes that MAZIDI book is very good!
     
  20. GetDeviceInfo

    Senior Member

    Jun 7, 2009
    1,571
    230
    thumbs up to Keil. Like most coding, if you depend heavily on bloated libraries, you'll generate bloated code. Although I used MASM and hand coded machine code for many years, I don't do it now, and don't care to. I hate to even look at it, and close any thread that contain it.
     
Loading...