Skip to main content

Hex file generation using Keil

Keil Î¼vision is an Integrated Development Tool(IDE) to write, simulate and flash our program written either in assembly language or in C. We can also flash our program to mcs51 series(8051 family) microcontroller using Keil Î¼vision IDE. But I will prefer you to use Flashmagic developed by NXP to flash your program into 89c51(I am emphasize that 8051 has no flash memory. But we can use other microcontrollers that are code compatible with 8051 like 89c51 from Atmel or 89c51RD2BN from NXP etc.). But we want to familiar with Keil Î¼vision to generate hex files from our embedded C programs. You want to click here to download latest version of Keil Î¼vision. This will redirect you to official website of Keil. You must fill the form before download Keil. The Keil Î¼vision IDE setup file has more than 100 Mb in size. After downloading this setup file double click on it and install it. During installation this may ask your e-mail ID and lot of things. If you want notifications about new update you should fill this form. After installing Keil Î¼vision you can see an icon of Keil Î¼vision on your desktop.

• Open Keil Î¼vision by clicking on this icon.
• Close any open project by project menu→close project

• Create new project by project menu→new μvision project

• You will be asked to enter location for enter a location for new project. You should create a new folder for this purpose(you should have a folder for Keil vision programming purpose, you don't want to create new folder every time).It can be done easily by browsing through your harddisk partitions and you should give a project name during this phase.
• On next dialogue box you want to select target microcontroller. Select AT89c51 from data base.

• Keil vision then ask you "if you want to copy standard startup code?" Click yes.

• In project workspace window you will see your project has been created with its name. Inorder to watch each file you just click on +symbols shown on left side of each file. You can see that there is already a file added named as 'STARTUP.A51' Source Group 1. This file contains the code which will be executed before your main program to initialize the internal SFRs.
• To add new source file you want to right on Source Group 1. Then add files to Source Group 1. You can also open existing files using this method.
• Now following window will open. You can choose file type(C or ASM) from that window as well as you can choose name of your file there. After completing that just click add.
•You can now see a new file on Source Group 1 of project work space as shown below. Open that file. Now you will get a new editor window as shown below.

•You can type your program on this editor window. Now you can see I written a program to toggle port bits.
•Let us compile this file(here qwerty.c) into MCS-51 object code. Right click on qwerty.c in project workspace→build target.
Errors will reported at output window. The warning related to the fact that STARTUP.A51 and qwerty.c are occupy at same code space. This can be easily resolved by right clicking on STARTUP.A51 and select remove. However ignore the warnings.

You can see output window at the bottom of editor window as I mentioned earlier. See the image shown below,
◆ In order to generate hex code you want to go to project menu→rebuild all  target files.

◆Again go to project menu→options for target.


Then you can see a new window as shown below,
If you do not got this window you do not want bother about it.There is a chance for getting an unexpected window. If you got any window rather than this window just rebuild all target files again and then go for options for target from project menu.
You can now see the above window.
◆From above window select output tab. Then you can see a new window as shown below.
◆In the above window you should check box for 'create hex file'. You can also select your target folder to store hex file and rename the hex file generated.
You can use this hex files to flash the program to microcontroller. The software named flashmagic help you to flash this hex file into microcontroller. Flashmagic is developed by NXP which uses serial communication to flash your program in hex to microcontroller.  While installing previous versions of Flashmagic you will get a pdf manual which teaches you how to use Flashmagic. I don't know new version of Flashmagic is giving this manual or not. This software can use any beginner since it has better UI and only you want to choose target microcontroller and hex file which you want to flash. But you should know about the COM port of your computer(which COM port is used for serial communication and how much baud rate is used by that COM port for serial communication). Then click on start after selecting COM port and baud rate. You can download Flashmagic from here.

Comments

Popular posts from this blog

8051 Simple Programs

Sum of 8-bit Numbers Stored in Memory Here  we will discuss about 8051 programs but we can't discuss about all of the 8051 instructions. For programming 8051 we should know about assembler directives as well as instruction set. Click  here to download Atmel c51 user guide that will discuss about 8051(c51 family microcontroller) instruction set, assembler directives, c51 cross assembler from Atmel.  Program ORG 00H MOV R0,#50H   ; get memory location in memory pointer R0 MOV R1,#51H   ; get memory location on memory pointer register R1 MOV A,@R0       ; get content of memory location 50H to accumulator ADD A,@R1        ; add content of A with content of memory location 51H and store result in A MOV R0,#52H    ; get 52H to memory pointer R0 MOV@R0,A         ; copy content of A to memory location 52H END Add 16-bit Numbers ...

Introduction to 8051 embedded C

For 8051 we need to include the file reg51.h. This file contains the all the definitions of 8051 registers. With this information C compiler produces hex file that can be downloaded into the ROM of the microcontroller. It is important to note that the size of the hex file produced by the assembly language is much larger than the hex file produced by C compiler. Apart from this fact, there is many reasons for writing programs in C instead of assembly: ●It is much easier and less time consuming to write programs in C assembly. ●C is more flexible; it is easier to modify and update. ●Programming in C allows to use code available in function libraries. ●Program written inC for one microcontroller is portable to other microcontrollers with little or no modifications. Data Types in 8051 Embedded C The table shown below lists the data types that are available in typical C51 compiler. The gives information about the size of the data variable and it's value range. Data type ...

Frequency of Oscillation of RC Phase Shift Oscillator

Derivation of Frequency of Oscillation We have to find out the transfer function of RC feedback network. Feedback Circuit of RC Phase Shift Oscillator Applying KVL to various loops on the figure, we get, $$I_1 \left(R+\frac{1}{j \omega C }\right) -I_2R=V_i \text{ ....(1)}$$ $$-I_1R+I_2\left (2R+\frac {1}{j\omega C}\right)-I_3R=0\text{ ... (2)}$$ $$0-I_2R+I_3\left(2R+ \frac{1}{j\omega C}\right)=0\text{ ...(3)}$$ Replacing \(j\omega\) with \(s\) and writing equations in the matrix form, $$\begin{bmatrix}R+\frac{1}{sC} & -R & 0 \\-R & 2R+\frac{1}{sC} & -R \\0 & -R & 2R+\frac{1}{2sC} \end{bmatrix}\begin{bmatrix}I_1\\I_2\\I_3\end{bmatrix}=\begin{bmatrix}V_i\\0\\0\end{bmatrix}$$ Using Cramer's rule to find out \(I_3\), $$\text{Let, }D=\begin{bmatrix}R+\frac{1}{sC} & -R & 0 \\-R & 2R+\frac{1}{sC} & -R \\0 & -R & 2R+\frac{1}{2sC} \end{bmatrix}$$ \(|D|=\begin{vmatrix}R+\frac{1}{sC} & -R & 0 \\-R & 2R+\frac{1}{...