Tuesday, March 18, 2014

GETTING STARTED WITH 8051/AT89C51 USING KEIL uVISION 4 AND PROTEUS

1 comment:

In this step-by-step tutorial you will find:



--Basic connection diagram of 8051 micro-controller

--Stuff about how to write your very basic program for 8051 micro-controller using Keil uVision software and making final .HEX file with it 

--Using Proteus simulation software to simulate 4-bit counter circuit behavior and program

-- A example video showing 4-Bit counter program

Basic connection diagram of 8051 micro-controller

Notes:
-Do not forget to connect EA pin to 5V as this pin can not be left unconnected.
-30pF capacitor are most suitable but their unavailability has moved me use 20pF capacitors.

USING KEIL uVISION 4.0 TO WRITE CODE


1)As you will open Keil software , you will see following screen:
2)Create new project as shown below:
3)Name it. Make sure that you already have made the separate folder to minimize confusion of new project files with old ones. New folder will keep all files related to only to one project hence making it easy to locate files you need afterwards.

4)Select chip manufacturer, in our case Atmel then select chip model i-e AT89c51


5) Software will ask you whether to include 8051 start up code, select NO.

6)This is how you working environment should look like till now:

6) As new project folders are created, now it is time to create a text file which will include your assembly code. Goto file drop down menu and select "New" or simply click blank paper icon in file toolbar.


7) Write your code in the new white work space that just has been created.
8) Its time to save your  assembly code file now. Go to file drop down menu and select save. Save the file into your main project folder.
NOTE: SAVE FILE WITH .ASM EXTENSION AS OUR CODE IS IN ASSEMBLY LANGUAGE.
As you will save the file, the software will detect the .asm language keywords and they become colorful to make them prominent from rest of code. 

9) Now you have to add .asm code file to your project. Right click on the source group folder(sub-folder of main target1 folder) and select "Add files to group (source group)"

10) A small window will appear asking you for location of your .asm code file. Give it the path of wherever you have saved your file, it should be in  your project folder. Select the file click "Add".


11) You may check the .asm file by clicking on the little plus sign at the left of source group.

12)There are some configuration changes that you have to make before you build the final .HEX file. 

-In target tab set the frequency that you are using with 8051, in our case 10.0MHz. So change default value 24.0MHz to 10.0Mhz

-In output tab check the "Create HEX file" box otherwise HEX file will not be created.
After all these settings click OK.

13) Its now time to get final output that HEX file.
Right click on .asm file which is in source group folder and select "Build target" .

14)If there are no errors in code your code will be compiled in couple of seconds showing progress in window at the bottom.
If there are errors in code then they will also be mentioned in same bottom window with number of line that contains error. You may recheck that line rectifying the mistake(s).

15) After successful compilation of code you can find final HEX file in same project folder that contains main project file/asm file/other files.

USING PROTEUS TO SIMULATE  4-BIT COUNTER CIRCUIT

Important: As Proteus does not bound us to connect power supply, XTAL,reset circuit,EA pin and other basic connections so we are ignoring them for sake of simplicity. The important things like Xtal frequency of micro controller can be set from properties of micro controller, as discussed below.

While in actual hardware form for you must follow basic circuit shown at very beginning of this post.



1) Open Proteus



2) Click on "P" to open up part list.
Locate AT89C51 IC as shown below:




3) Locate LEDs as shown below


4) Make connections from 8051 to LEDs




5)Locate GND terminal as shown below

6) Connect all LEDs to GND




7) Double click on 8051 IC to open up its proerties window.

--- Set the operating frequency i-e 10.0MHz
--- Give controller the desirewd HEX file.


8) Click on Play Button to start simulation



CIRCUIT SHOULD START WORKING AS SHOWN BELOW

4-BIT COUNTER CODE:


;------4 bit counter code
ORG 0
MOV P1,#0
BACK1: MOV A,#0
BACK: MOV P1,A
INC A
ACALL DELAY
CJNE A,#15,BACK
SJMP BACK1

DELAY:  MOV R1,#45
H3: MOV R2,#100
H2: MOV R3,#100
H1: DJNZ R3,H1
DJNZ R2,H2
DJNZ R1,H3
    RET

END