User forums > Embedded development

How to output HEX file for AVR programming?

(1/2) > >>

slow_hand:
Hey all,

I'm kind of new at AVRs and C but I know Java pretty well. Many of my friends use CB and I thought to try it as well and I like it much better than PN2.
I wrote a simple 'Hello World' kind of program that I want to burn on an ATMEGA168 AVR.

Here is the code:

#define F_CPU 1000000UL

#include <inttypes.h>
#include <avr/io.h>
#include <util/delay.h>

void _delay_ms(); // Function deceleration

int main(void)
{
    DDRB = 0b11111111; // Set PORTB pins as output
    PORTB = 0b00000000; // Set output on all pins to logic 0

    while(1)
    {
        PORTB=00000000; // LED OFF - at bit 0
        _delay_ms(500); // Wait 0.5 sec
        PORTB=00000001; // LED ON - at bit 0
        _delay_ms(500); //Wait 0.5 sec
    }
    return 0;
}


I've noticed a few "strange things".

1. On every tutorial I saw no one defined function prototypes before main, but I'll get all kind of errors if I won't do that. Do I really have to do that?

2. On the tutorials I saw the function was called delay_ms and not _delay_ms, however the one without the underscore won't work.

3. I have WinAVR installed so I changed the default compiler to GNU AVR GCC and set the path to WinAVR folder. After I build the file I will get an EXE file but not a HEX file like I need to burn to the MC. How can I solve this?

Thanks!

mariocup:

--- Quote from: slow_hand on June 19, 2009, 10:24:44 pm ---3. I have WinAVR installed so I changed the default compiler to GNU AVR GCC and set the path to WinAVR folder. After I build the file I will get an EXE file but not a HEX file like I need to burn to the MC. How can I solve this?

--- End quote ---

You can generate a hex file in a post build step with CB like


--- Code: ---cmd /c <architecture>-objcopy -O ihex Input.elf Output.hex

--- End code ---

slow_hand:
Thank you for the reply, however, can you be a little more specific as I could not understand what to do exactly. Another thing, I don't have an .elf file after buidling... I get main.o & main.exe files.

mariocup:
Hi,

put the command of avr objcopy in the bost-puilt step like


--- Code: ---cmd /c avr-objcopy -O ihex <executable> <converted_hex_file>

--- End code ---

Replace the <executable> by name of your executable or use instead a CB variable like $(TARGET_OUTPUT_FILE). Then specify the name for the resulting hex file.

If the programmer is a command line tool you could even do the flash programming in a post build step too.

slow_hand:
Oh OK I understand! I actually got my code working! :)
Where is the post-build step located? I can't find it in the compiler settings or anywhere else...

Navigation

[0] Message Index

[#] Next page

Go to full version