Please Help with struct code to create PORT pin names

typedef struct {
unsigned bbit0 : 1, bbit1 : 1, bbit2 : 1, bbit3 : 1, bbit4 : 1, bbit5 : 1, bbit6 : 1, bbit7 : 1;
}IOREG;
#define PORTB(*(IOREG *) 0x05)

/*

I am using AVR Studio 5.0 to program a AtMega2560 prototype board.

I am attempting to assign PORT bit names to a port so that I can individually manipulate bits of a PORT
with each bit having a simple and obvious name.
If this worked I was hoping I could write code as easy as:

PORTB.bbit1=0; //bit 0 of PORTB reset
PORTB.bbit7=1; //bit 7 of PORTB set

Alas, I don’t know how to create the union or a class to do this correctly. I am new to C# or C++
(as in the above code that does yields an error when the #define statement above is encountered. Error generated: * cannot appear in macro parameter list

I got this idea from C-Language guide AVR_3_04(6).pdf (found this on by Googling for C compilers)

That IOREG keyword? Where did you get that from?

also, PORTB is already defined... you'd probably have to leave some of the includes out. Have you checked in the AVRStudio examples if there is something like it?

How is AVRStudio 5.0? Nice?

Studio 5 has the following problems: No reference manual/comprehensive help for Studio 5 and C language. No command line information for compiler operation, linking, output files, switches. No access to a list file after compilation, just the target .hex file. Compiler will not report that compilation has stopped at a point in code if a programming error caused by roll-over of a variable causes an endless loop...instead it compiles seemingly without error and produces the same .hex file without changes, even after any program change beyond the point in the program that caused an infinite loop. Compiler reports no problem...successful compilation. Studio5 requires an expensive debugger card to even begin any type of debugging, such as simply stepping into the compiled program to look at program flow. Otherwise, I don't know how to bitwise address port pins.

I have looked exhaustively through the samples without finding any help for my posting.

Do you have an objection to the “normal” Atmel syntax…

PORTB &= (1 << PB1);
PORTB |= (1 << PB7);

…or the simplified form…

PORTB &= _BV(PB1);
PORTB |= _BV(PB7);

Compiler will not report that compilation has stopped at a point in code if a programming error caused by roll-over of a variable causes an endless loop

So how is a compiler supposed to spot a run time error?????

GeniusPro: Studio 5 has the following problems: No reference manual/comprehensive help for Studio 5 and C language.

Doesn't it use AVR-GCC?

GeniusPro: No command line information for compiler operation, linking, output files, switches.

Isn't it configurable through some menu on the IDE?

GeniusPro: No access to a list file after compilation, just the target .hex file.

Again, not configurable through the IDE? Does AVR-GCC produce such files?

GeniusPro: Compiler will not report that compilation has stopped at a point in code if a programming error caused by roll-over of a variable causes an endless loop...instead it compiles seemingly without error and produces the same .hex file without changes, even after any program change beyond the point in the program that caused an infinite loop. Compiler reports no problem...successful compilation.

Does AVR-GCC do that? For that matter, does any of the microcontroller compilers do that?

GeniusPro: Studio5 requires an expensive debugger card to even begin any type of debugging, such as simply stepping into the compiled program to look at program flow.

The JTAG interface? I actually think it is a cheap debugger card. A card of that type for Siemens PLCs runs at around 400 euro. Plus, a few years ago, it was more expensive.

GeniusPro: Otherwise, I don't know how to bitwise address port pins.

You can always create a macro to change pins or, if this bothers you so much, you can always download a shareware version of Codevision AVR and use the limited amount of code and examples, or buy a license for the whole thing. However, from previous experience, I didn't manage to run code compiled from it with the bootloader. Only on a bare chip. That one will have the "." notation for the registers and a setup interface menu (ahhh, that is actually good) for you to setup the microcontrollers hardware.

The Studio5 behaviors I have stated above have been verified by me by careful examination and testing.

If there is a comprehensive guide to the C compiler in Studio5 I haven't found it...one that addresses the issues I stated above in my posting.

After spending 7 minutes watching the how to videos about AVRStudio 5 I found out that:

It uses AVR-GCC... so the manuals for it are in http://www.nongnu.org/avr-libc/user-manual/index.html .

I also noticed that it is possible to configure the output files of the compiler and from the video there are 4 files that can come out of the compile process. Not just .hex.

There is a menu to setup the compile process. AVRStudio is, after all, an IDE. So I don't quite get why you'd want to use command line settings. There is also a help section about configuring the build options for the project. However, if you want, you can use an external Makefile.

Here's the link for the videos: http://www.atmel.com/microsite/avr_studio_5/default.asp?source=redirect

I think you can buy some JTAG interface knock-offs from China in eBay too. Not sure if they are good or not, never used them and normally troubleshoot the old hard way.