Wednesday, 1 August 2012

HOW TO USE KEIL

Finally you have decided to write your own code for the 8051 microcontroller. It doesn't matter whether you have chosen Assembly or C Language for yourself but what matters now is that you need an environment specially designed for 8051. Basically you are looking out for IDE (Integrated Development Environment) that will help you build and compile programs. While there are many options out there, I prefer KEIL uVision in this regard.

UPDATE: You can also click this link for an updated version of this post.





KEIL IDE is basically an assembler and a compiler or whatever you name it. You can write either an Assembly or C language code and KEIL will take care of the rest for you. Furthermore, it supports many of the 8051 variants that you will face. You can download KEIL from their official website using the link below.


After successful download and install, you may have problem getting familiar with it if you're using it for the very first time but don't worry because I am here to give you a graphical tutorial on how to use it for writing your program, compiling it, and finally generating the HEX file.

Here we go

Create a new folder for project to avoid getting mixed up with files

PROJECT > NEW uVISION PROJECT

Give some name and click SAVE

when prompted, select proper device that you're using ( i-e ATMEL > AT89C51 )

When prompted, select YES

Click NEW button and write your code (Assembly or C language)

SAVE the file with proper extension as above

The code you have written gets highlighted

Right click SOURCE GROUP 1 as shown

Add the code you have written into the Project workspace

Go to options for the project

Enable HEX file generation

Build the project

Notice successful build. Ignore the warnings

Use this HEX file to program your IC

These are the simple steps for a successful compilation and generation of HEX file. Now I hope you have created your first HEX file and ready to program it to the 8051. And you know how to do that, right? If your answer is no then please check this out.

UPDATE:

If you have trouble understanding the pictures then here is a video of the same process that I made. Hope you get a better view this time


27 comments:

  1. I'm trying to generate a random number in C language using keil 4 C51. I'm using rand() and appropriate header files that we use in ordinary C compiler. A random number is generated in ordinary c compiler but not in keil 4... Please help me to resolve this!

    ReplyDelete
    Replies
    1. Sorry for the delay. For some reason, your comment had moved to SPAM section :(

      Well I haven't checked Random Number Generation in 8051 myself but I could give you an appropriate suggestion :

      Forget about using the C header files for random number generation in 8051. You can always use the timers for the same purpose. Depending on the range, you can either go for 8bit mode (0-255) or 16bit mode (0-65535). Reading the timer/counter value at any instant will give you a random number in that range depending on it's state at that time.

      The only trick is that if you want a specific range for Random Number Generation, you will have to write your own algorithm for manipulating the above basic procedure for that range.

      (hint: keep reading the timer/counter value until it returns some number within that range)

      Delete
  2. Great work but why my u vision is not showing any AT89CXXX file in atmel part... please he me with this...and please upload or send me your u vision by mail Ravichaudhari712@gmail.com or FB.com/rvch7 please help...You are Great..!!

    ReplyDelete
  3. hi admin, you just write in .hex code procedure, bt i want to program in C language means ?wat i do ? wil u explain the procedure ??

    ReplyDelete
    Replies
    1. I also upload the program code where necessary. You can check my posts about interfacing such LED, SWITCH, KEYPAD etc and read the program code with it. I have properly commented it so you can have an idea of what's happening.

      If you want to properly learn Embedded C language for 8051, you must refer to the book

      "The 8051 Microcontroller and Embedded. Systems. Using Assembly and C"
      By Muhammad Ali Mazidi and Janice Gillispie Mazidi

      Delete
  4. hi sir, can you tell me how to check your code inside keil (i heard it is possible), before burning i want to check weather the code is working accordingly or not....

    ReplyDelete
    Replies
    1. You can always debug your code in Keil which will help you analyse your code in a stepwise fashion. I have already posted about debugging in Keil, check the link below

      Debugging in Keil

      Delete
  5. I have just started to learn 8051 microcontroller and at the end of the semester I have to submit a project on embedded system . for that what will be the best project ?can you give me any advice?

    ReplyDelete
    Replies
    1. I'm afraid I can't tell you about the 'best' project :) because every project is unique and has some usefulness in its own way. However you can check out this list of projects based on 8051 microcontroller. Maybe you can grab yourself the 'best' one ;)

      Projects based on 8051

      Delete
  6. sir,
    i m persuing my btech fourth year .i dont know any basics about keil software
    but we are supposed to do a project on 8051 mc which need this software to write the programm could u please sujjest us how could we get our program sucess
    my project is "ZIGBEE BASED GENSET CONTROLL SYATEM".

    ReplyDelete
    Replies
    1. It becomes easier if you divide your project into smaller parts and verify it in a stepwise fashion.

      If you have no idea about KEIL or 8051, it would be a good idea to know them first and work on some basic tasks. Then you can continue to tackle your project requirements when you get the hold of it.

      Delete
  7. nice...I m going share to this information at my website www.pradipyadav.com

    ReplyDelete
  8. Hi there i need a help i am getting this error
    "minor.c(15): error C267: 'delay_ms': requires ANSI-style prototype"
    for line code [delay_ms(50);] with that target is also not created message is showing
    will you please help me out that how to remove the error so that i can rectify it plzzz reply ASAP

    ReplyDelete
  9. Thank you so much admin. You explained it very well =)

    ReplyDelete
  10. thanks alot. it was my first time to use the keil software, and it was very helpful. very well explained with each and every step.

    ReplyDelete
  11. thanks alot. it was my first time to use keil software,and it is very helpful document.

    ReplyDelete
  12. plz send me code for home automation based on gsm email- mangletech@gmail.com

    ReplyDelete
  13. Thankyou sir. I installed keil software and I am searching for best mentor to learn programming in this software. This will helped to me. ��

    ReplyDelete