1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

basics of 8051 microcontroller

Discussion in '8051/8951' started by PG1995, Mar 15, 2012.

  1. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,645
    Likes:
    13
    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. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    Hi PG... Jon Wilder posted this IDE / Simulator http://mcu8051ide.sourceforge.net/ for people like you who want to program 8051 and derivatives

    I have been using it with SDCC.... I also use VSM studio IDE from Labcenter... It also interfaces to SDCC so you can do C as well.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,645
    Likes:
    13

    Thank you, Eric, Rogers.

    I'm a total beginner so simple stuff would do for me.

    It says that it has everything in one place, code editor, assembler, etc. and can even work as a simple virtual trainer (e.g. it has LEDs etc.). Is this really true? Do you know of any better simple software out there besides this one?

    Thanks for the help.

    Regards
    PG
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    I think is absolutely brilliant for free...

    Its laid out like MPLAB IDE so most of us here will get along with it.
     
  7. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,645
    Likes:
    13
    Hi Rogers

    Is Proteus good software? At school they have this software (they also have Keil assembler) so I can get its copy for free. If you think MCU 8051 IDE is better, then I can use it. Please let me know. Thank you.

    Regards
    PG
     
  8. Jon Wilder

    Jon Wilder Active Member

    Joined:
    Oct 22, 2010
    Messages:
    859
    Likes:
    82
    Location:
    Fresno, CA
    The 8051 (despite the fact that it has developed its own community of haters with no other reason to hate on it than its physical age) is an awesome microcontroller that is super fun to code in assembly. I started on PIC microcontrollers and got very familiar with Microchip assembly. Then I moved up to the 8051 and found that I much preferred the way Intel assembly is set up over Microchip assembly. Plus the internal architecture of the 8051 just makes much more sense than the PIC 16F architecture.

    Although it is derivative dependent, it's important to note that the "standard 8051" ports have weak internal pull ups. This means that they sink more current than they can source when being used as outputs so most things will need to be buffered. However, certain derivatives (such as the Atmel AT89LP52) have configurable outputs that will allow you to set the output pins as either the "classic" style outputs, input only, or full push-pull outputs with strong pull ups. When Port 0 is being used as a standard I/O port, it is open drain so external pull ups are required on port 0 to pull the port 0 pins high when 1's are written to the P0 latch (port 0 has strong internal pull ups that are only active when it's being used as an address/data port for external memory access).

    Hope you have fun learning this chip. If you haven't decided on a derivative yet I recommend the Atmel AT89S series. With the Atmel AT89ISP cable (or you can make your own), the AT89S series can be programmed in the target circuit with ISP (In System Programming).
     
    Last edited: Mar 16, 2012
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    Ditto.... I was the opposite... I started on the phillips chips and the XA range.. I used raisonance tool kit for a while (free version) then i just used asm... I have the full version of Proteus... so I bought the 8051 package... the programming was nice and easy... but Proteus didn't cater much for all the derivatives mainly I2C... So I got the small pic package. It had the pi16f84a.... the pic16f877a... and the pic18f452.. models... I used assemble first...

    I wrote my first professional application (a datalogger) based on the Phillips XA51 .... I bought the first oshonsoft basic compiler, it was only 15euro's, and wrote about 4 more..
    As I had bought pic and pic18 I moved to pic18 and wrote a fork lift truck display.....

    I now use pics all the time. I have now settled for pic18f4520 / 4620 / pic16f887 and pic12f675.... These few chips cover ALL my needs.

    All this and I still like playing with 89C51RD2's now and again...
     
  10. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,645
    Likes:
    13
    Hi

    I was trying to work with the code below in MCU 8051 IDE. First problem is that I don't know how to change XTAL setting. I doubt the MCU doesn't have it. The other problem is the LEDs doesn't blink. The LEDs at BIT 0, 2, 4, and 6 don't turn on. Please help me with it. Thank you.


    Code (text):

    MOV  A,#55H
    AGAIN:  MOV  P1,A
            ACALL DELAY
            CPL      A
            SJMP     AGAIN
    DELAY:  MOV  R5,#2
    HERE1:  MOV  R4,#180
    HERE2:  MOV  R3,#255
    HERE3:  DJNZ     R3,HERE3
            DJNZ     R4,HERE2
            DJNZ     R5,HERE1
            RET
     
     
  11. Jon Wilder

    Jon Wilder Active Member

    Joined:
    Oct 22, 2010
    Messages:
    859
    Likes:
    82
    Location:
    Fresno, CA
    Comment out the delay when simming it (sims take forever to run delay loops). With the delay loop commented out the LEDs do flash.

    To change the xtal frequency, go to Project ---> Edit Project. There's a text window that lets you change the xtal frequency.
     
    Last edited: Mar 19, 2012
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    They do blink..... Remember that the simulator isn't in realtime..... I run it in ISIS the code works ok.

    (You need an "end" statement at the end )
     
  13. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,645
    Likes:
    13
    Thanks, Rogers.

    Do you mean to say that they blink in the MCU? Why can't I notice the blinking then?

    Does the MCU have XTAL setting?

    I also have Proteus ISIS. I couldn't find LED panel there? Do I have to use individual LEDs for each BIT?

    One other important I wanted to ask is how did you burn that code (which I gave in my previous post) into the ROM in ISIS?

    Please help me with the queries above. It would be really kind of you.

    Regards
    PG
     
  14. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    You'll need a programmer to burn the code into the onboard flash
    I used to use a built in bootloader on my phillips chips( I just needed to Ground the EA pin )


    The Xtal is just connected ( I don't think there's a setting )

    Yes in Proteus you connect an led to each pin ( there is a bargraph LED in the library)
     
  15. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,645
    Likes:
    13
    Hi again :)

    Do there exist programmable MCU chips? I mean the chips which can be programmed to work as 8051, 8052, or some other MCU such as Microchip's PIC. Please let me know. Thank you

    Regards
    PG
     
    Last edited: Apr 13, 2012
  16. Jon Wilder

    Jon Wilder Active Member

    Joined:
    Oct 22, 2010
    Messages:
    859
    Likes:
    82
    Location:
    Fresno, CA
    The hardware on the chip is what makes the MCU what it is. You cannot program a chip to run as if it were a different MCU.

    There are, however, MCUs with on board flash program memory where the program can reside on chip rather than requiring external EPROM memory for the code.

    The only real differences between the 8051 and the 8052 are that the 8052 has an additional 128 bytes of on chip RAM (256 bytes internal RAM...upper 128 bytes must be indirectly addressed) and the addition of a 3rd timer (timer 2) that has 16 bit auto reload and can serve as the UART baud rate generator to give you finer control over the UART baud rate, which makes crystal selection not as critical. The 8052 also has a capture module on chip that allows you to time an external event and "Capture" the value in timer 2 when the external event occurs to calculate the time it took for the event to happen.

    The Atmel AT89S series are Atmel's 8051 line. I use the Atmel AT89S8253, which is very much like an 8052 with the addition of an on chip SPI interface. There are a few other goodies on it as well like programmable watchdog timer, x2 clock option (runs at 6 cycles per instruction rather than the 8051 standard 12 clocks per instruction), dual data pointers, on chip data EEPROM (2K) and 12K of flash EEPROM for code space. The AT89S series is also ISP (In System Programmable) compatible and works well with Atmel's AT89ISP programmer (PC parallel port interface required).
     
    Last edited: Apr 13, 2012
    • Thanks Thanks x 1
  17. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    I use the p89 series from phillips.. again for the same reason as Jon.

    You can program FPGA's to work like mico's... But I never understood why someone would want to!! Just as easy to use the actual chip....

    Microchip DOES produce a 8051 chip anyway....
     
    Last edited: Apr 13, 2012
  18. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,645
    Likes:
    13
    Thanks a lot, Jon, Rogers, for your replies.

    Now please help me with the query given in the attachment. Once again, many thanks for your help.

    Regards
    PG
     
  19. Jon Wilder

    Jon Wilder Active Member

    Joined:
    Oct 22, 2010
    Messages:
    859
    Likes:
    82
    Location:
    Fresno, CA
    You are correct. In order for it to decrement 256 times, it would have to decrement the register from 0 to roll over to 255 for the 256th count. However, as soon as the decrement returns a zero result it will jump so the rollover never happens.

    But...in all honesty, is it going to be human perceivable? Probably not.
     
  20. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,645
    Likes:
    13
    Thank you for the reply, Jon.

    Q1: For some reason, I wasn't able to completely understand what you said; perhaps, it has to do with my limited knowledge of English language. So, you also think that the book is incorrect and the loop can only be repeated 255 times?

    Q2: Please have a look on the attachment and kindly help me with the query. Thank you.
     
  21. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    I think that its correct... You can loop 256 times.... We do it without thinking...

    R0 = 0 ; this is theoretically 0x10 ( 256 )
    loop:
    DJNZ R0, loop

    if you test after decreasing, the first test would be on 0xFF .. the first loop is at 0... (256)
     

Share This Page