×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help with my first C program.

Help with my first C program.

Help with my first C program.

(OP)
I am trying to program an atmel AT89C2051. As you might know it has a capacity of 2K. Now the program itself is only a few lines. But when I compile it, a hex file is produced that is 3.2K. So I get an error message. The large file is because of to lines in the program:

#import<file1.h>
#import<file2.h>

I picked up the program in book on Microcontroller programming by Ibrahim Dogan. And he uses the exact same chip.

The question is: What am I doing wrong?

Please help

Tom

RE: Help with my first C program.

(OP)
correction: I meant
#include <stdio.h>
#include <AT892051.h>

RE: Help with my first C program.

By what test did you determine that the header files were at fault?

If they really are, there should be a means of linking only the functions you're actually using.   The programming book should have a section that explains how to do that.

TTFN

RE: Help with my first C program.

Hi-

You might have to "modify" some of the header files.
stdio.h is quite comprehensive and will include much
code that will point to library routines that can be
removed.  

There might be several (other) causes of this:

1. You might be using a different stdio.h file linking
   an incorrect library (like the one on the development
   system....)

2. The library itself might have "grown" with new
   functionality from the version that the author used.

3. You might not even need the library at all!  If you
   don't have any printf, scanf, etc, etc statements
   in your code, you can get away with leaving it off!
   Many times, I/O code for the microcontrollers do not
   need to have "standard I/O" and just do bit diddly
   stuff with I/O pins.  Depends upon your application
   of course.

4. You might have to "leverage" the functions that you
   need locally and create your own "mini stdio.h" file
   and library routines.

So, in short, you might be doing nothing wrong at all!
Hope this helps.

  Cheers,

   Rich S.

RE: Help with my first C program.

(OP)
THe reason I am doing it in C is simply because I want learn the language.

IRstuff :

"By what test did you determine that the header files were at fault?".

Tom: I eliminating the lines.

IRstuff :

"If they really are, there should be a means of linking only the functions you're actually using."


I did just that, and didnot make any difference.
Then I relized that only one line is making the problem and it is:

printf("This is an RS232 test message\n");

By eliminating this line the hex file size was reduced to only 133 Bytes!


This line occurs in a for loop, in fact the whole progam is these few lines:

//----------------------------
main()
{

serial_init();   /*initialize serial port */
for(;;)        /*Start of loop */
    {
    printf("This is an RS232 test message\n");
    }
}
//----------------------------

So I gave up and went to the next example which was an alternative to the first one, without using the printf().

This time around a hex file of 1.2 K was produced. But I get the following message from the Programmers software:

"Data Address, 95FH, in Hex File is outside valid memory range, 0000H - 0800H, for selected chip. Programming aborted"

I am using UVISION2 V2.31.
Then after alot of tries I realized that when the
"memory model", "Code ROM size" in
"Projects/option for target/Target" is changed the
"Data Address, 95FH" changes to different addresses.

But I havn't been able to fix the problem yet.
 

Tom

RE: Help with my first C program.

(OP)
Does anyone know of a alternative compiler for AT892051.

RE: Help with my first C program.

It's not the header files themselves, it's the functions IN them that you're including by using them in your program (i.e., printf() ).  That function is a beast when it comes to resources (as you found out).  I suggest learning C on a PC first to get a feel for the language itself before moving to the embedded world.  This will give you a chance to feel comfortable with the language construct before looking at the nuances and issues specific to the embedded world.  If you're working on an embedded system with no display, printf() isn't going to do much for you...

RE: Help with my first C program.

Not only is printf rather pointless on a embedded processor, but printf is a relatively complicated procedure, since it has to accommodate variable length, variable number and variable formatting.

A more meaningful procedure would probably be putc(), placed within a FOR loop that indexes through the output string.

TTFN

RE: Help with my first C program.

I think you need to start you code at some low address C:0x0000H maybe(!?)..... Some compiler may start your code at very high address... That is the reason to waste the whole memory..... Check the hex file using notepad...you will see you code is not that big
Sincerely,

HaiB

HVB

RE: Help with my first C program.

Hi
It may be that you also have to create a release version instead of debug version. If the compiler adds debug information to the link(the hexfile) it can use up a lot of space. Also try to avoid using printf(), that function uses far to much space. Like the other guy said, access ports directly...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources