|
From: | Dave Hansen |
Subject: | RE: Fw: [avr-gcc-list] AVR UART as ANSI Terminal Interface |
Date: | Mon, 01 Nov 2004 08:50:14 -0500 |
From: "Royce & Sharal Pereira" <address@hidden> [...]
I had a similar issue when I tried to port some code written for SDCC & the AT89c51 to an ATMega8. for example, the declaration "bit flg_key, flg_ZCD;" & consequently "flg_key=1;" and "flg_key=0", etc had to be converted to avr-gcc format.Besides, AVR has no 'bit' storage space like AT89c51. So I did this: replaced "bit flg_key;" with unsigned char flags; #define flg_key (1<<0) #define flg_ZCD (1<<1) //etc etc, Then using my editors search/replace tool I replaced all instances of "flg_key=1;" with "flags |= flg_key" and "flg_key=0;" with "flags &= ~flg_key;" Also logical stuff like "if(flg_key)" etc was replaced with "if(flags & flg_key);"
An alternative that has worked well for me (for this particular transformation) is to use bit field structures along with the preprocessor. For example:
struct flag_bits { unsigned key: 1; unsigned ZCD: 1; } flg; #define flg_key flg.key #define flg_ZCD flg.ZCD This way, the syntax of the code using the bits doesn't have to change. flg_key = 1; if (flg_ZCD) /* etc. */The declarations get a little hairier if you need to make some bits local and others global, but it can still be done so only the declaration has to change, and the code remains the same.
Regards, -=Dave
[Prev in Thread] | Current Thread | [Next in Thread] |