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
#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.
#include <stdio.h>
#include <AT892051.h>
RE: Help with my first C program.
<nbucska@pcperipherals.com>
RE: Help with my first C program.
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.
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.
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.
RE: Help with my first C program.
RE: Help with my first C program.
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.
Try the compiler WinAVR from http:\\www.avrfreaks.com
RE: Help with my first C program.
Sincerely,
HaiB
HVB
RE: Help with my first C program.
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...