Mikrokontroller C-ASM
Papp Zoltán
zombi at c2.hu
Sun Dec 11 23:55:48 CET 2005
2005.12.11. 21:54:34 dátumon Fuzesi Arnold <arno at externet.hu> írta:
> Vannak C-ben un bitmezők...
>
> Ez tulkeppen egy struktura aminek a byte bitjei az elemei.
> Miutan definialja a forditohoz adott fejlec file altalaban, Neked csak
> ennyi a dolgod:
>
> #define LED PORTB_Bit0
>
> Azaz a portb 0. bitje lesz a LED tulkeppen.
>
> Periferiaknal meg szokott lenni ez a definicio alapbol.
>
> Ha sajat byte valtozot akarsz igy szetbontani majd 8 bitkent kezelni,
> arra is van megoldas...de inkabb attol most megkimelnelek... :)
Ne kíméld, IAR proci definícióban van ez:
/****************************************************************************
* An example showing the SFR_B() macro call,
* the expanded result and usage of this result:
*
* SFR_B_R(0x1F, AVR) Expands to:
* __io union {
* unsigned char AVR; // The sfrb as 1 byte
* struct { // The sfrb as 8 bits
* unsigned char AVR_Bit0:1,
* AVR_Bit1:1,
* AVR_Bit2:1,
* AVR_Bit3:1,
* AVR_Bit4:1,
* AVR_Bit5:1,
* AVR_Bit6:1,
* AVR_Bit7:1;
* };
* } @ 0x1F;
* Examples of how to use the expanded result:
* AVR |= (1<<5);
* or like this:
* AVR_Bit5 = 1;
*
*
*
* An example showing the SFR_B_N() macro call,
* the expanded result and usage of this result:
* SFR_B_N(0x25, TCCR2, FOC2, WGM20, COM21, COM20, WGM21, CS22, CS21,
CS20)
* Expands to:
* __io union {
* unsigned char TCCR2;
* struct {
* unsigned char TCCR2_Bit0:1,
* TCCR2_Bit1:1,
* TCCR2_Bit2:1,
* TCCR2_Bit3:1,
* TCCR2_Bit4:1,
* TCCR2_Bit5:1,
* TCCR2_Bit6:1,
* TCCR2_Bit7:1;
* };
* struct {
* unsigned char TCCR2_CS20:1,
* TCCR2_CS21:1,
* TCCR2_CS22:1,
* TCCR2_WGM21:1,
* TCCR2_COM20:1,
* TCCR2_COM21:1,
* TCCR2_WGM20:1,
* TCCR2_FOC2:1;
* };
* } @ 0x25;
* Examples of how to use the expanded result:
* TCCR2 |= (1<<5);
* or if ENABLE_BIT_DEFINITIONS is defined
* TCCR2 |= (1<<COM21);
* or like this:
* TCCR2_Bit5 = 1;
* or like this:
* TCCR2_COM21 = 1;
***************************************************************************/
Üdv
--
Papp Zoltán
OneWay Electronics
More information about the Elektro
mailing list