Wednesday, January 07, 2015

Alternatives in programming the AVR microcontrollers

As a long time PIC programmer, spoiled by the bit support in, I think, all the compilers available, free or not, going to AVRs it was quite a shock to see what "enormities" I had to write to assign a value to a pin using the features provided by the avr-gcc compiler.

By example, in a code of a graphic LCD library, to set or clear the "chip select" pin, you had to write:

#define GLCD_CMD_PORT   PORTA        // Command Output Register
#define GLCD_CSEL1      0x03        // CS1 Bit Number
#define GLCD_CSEL2      0x04        // CS2 Bit Number

GLCD_CMD_PORT |= 0x01 << GLCD_CSEL1; // select chip 1
GLCD_CMD_PORT &= ~(0x01 << GLCD_CSEL2); // deselect chip 2

Opposed to the simplicity of C18/XC8/SDCC C compilers:

PORTAbits.RA3 = 1; // for GLCD_CSEL1 to be set
PORTAbits.RA4 = 0; // for GLCD_CSEL2 to be clear-ed

Of course, you can write macros to mask that and get close to the features PIC compilers are offering but I always looked over the shoulder in the PIC garden for such a simple pin manipulation.

I don't blame AVRs for this avr-gcc compiler inability, the micros are amazing and I love to use them. And I don't say the compiler is not good in what is doing because it misses this feature - the compiler is also amazing in what it produces for free. It is a fantastic team. I only say that this is scary for a beginner coming from the PIC world.

And if continues to bother you, there are alternatives. For C programmers, the alternatives are not free, CodevisionAVR compiler is an excellent commercial alternative.  But if it happens to know other languages, like Pascal and Basic, there is a fantastic free alternative: LunaAVR, a compiler, assembler, disassembler, debugger and a graphical IDE with a lot of useful assisting tools. It provides even object oriented programming if you are into it. And the compilation result is in many cases better than the one in avr-gcc! Go to their site, it is worth a part of your time and I bet you will be content.

No comments:

Post a Comment