Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem in 8051 programming in keil

Status
Not open for further replies.

gopintj

Member level 4
Joined
Sep 1, 2010
Messages
77
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Location
Thirukalukalukundra, Kanchipuram, Tamilnadu, India
Activity points
1,953
hi, i am very new to 8051. I have done some basic courses with pic micro controllers. Thereby, i would like to learn 8051.
I use Keil 4.10
Let me explain you how i created my first project.
I opened the keil 4.10 and selected new micro vision project from PROJECT menu and chose the destination folder. I, then selected intel 80c51 and also copied standard 8051 code and added file to my project.

Then, i got a blank space. I opened a new text document and saved my program with extension "*.c"
Then, i added that *.c file into my project and selected F7.

The program gets run and shows this message.

"Build target 'Target 1'
assembling STARTUP.A51...
compiling sample3.c...
linking...
Program Size: data=9.0 xdata=0 code=27
"sample3" - 0 Error(s), 0 Warning(s)."

But the problem is, i cant get the hex file. :cry:

This is my program

#include <reg51.h>
void main(void)
{
unsigned char z;
for (z=0;z<=255;z++)
P1=z;
}

Please anyone guide me.
 

Do the following:

Go to Project Tab
Open "Options for Target 'Target 1'
A window will appear with many options..
Click Output tab
Check "Create HEX file" option
You can also change the path where .HEX file will be created
 
While mlkz_01 has covered the issue of the missing HEX file, you should be made aware of two issues with your program code.

1. When coding a MCU/Processor which does not have an OS/RTOS you should never allow the execution from leaving main(), for the simple reason there is no OS to which pass execution/control.

Rather than:

Code:
#include <reg51.h>
void main(void)
{
    unsigned char z;

    for (z=0;z<=255;z++)
       P1=z;
}

Use an infinite loop:

Code:
#include <reg51.h>
void main(void)
{
    unsigned char z;
  
    while(1)
    {
        for (z=0;z<=255;z++)
           P1=z;
    }
}

Or

Code:
#include <reg51.h>
void main(void)
{
    unsigned char z;

    for (z=0;z<=255;z++)
       P1=z;

    while(1);
}

The first example repeats your "for" loop indefinitely and second example runs your "for" loop once while holding execution within main() indefinitely.

Also it should be noted if you wish to view the state of PORT1, using LEDs for example, you'll need to implement a delay after each update of PORT1.

For example:

Code:
#include <reg51.h>
void main(void)
{
    unsigned char z;
  
    while(1)
    {
        for (z=0;z<=255;z++)
        {
           P1=z;
           _wait_ms(1000); // Substitute for your delay routine, example delays for 1 second between PORT1 state changes  
        }
    }
}

Hope the info helps in your endeavors,

BigDog
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top