I'm trying to understand this embedded c code. I think it means it is connecting port bits to some register in a bus. Correct me if I'm wrong. And what ever changes we make to the ports will be reflected on the bus registers. Here is the snippet of the code. Thanks.
/*--------------------------------------------------------------------------
开发者_StackOverflowLocal Variables
--------------------------------------------------------------------------*/
// Port bits assigned to Amba Peripheral Bus (APB)
// P0^7..P0^0 // output=reg_addr, input=data_in (APB prdata)
sbit APB_SEL = P1^7; // select a bus transaction
sbit APB_EN = P1^6; // enable/activate a component 0 = disable, 1 = enable
The code is defining bit positions to be read from registers. sbit
defines a bit within a special function register (SFR).
sbit APB_SEL = P1^7;
Here P1
is a previously defined SFR. The line defines APB_SEL as bit 7 (zero-based numbering) of P1
.
This link has additional details on the syntax.
The sbit type defines a bit within a special function register (SFR). It is used in one of the following ways:
sbit name = sfr-name ^ bit-position;
sbit name = sfr-address ^ bit-position;
sbit name = sbit-address;
Where
name is the name of the SFR bit.
sfr-name is the name of a previously-defined SFR.
bit-position is the position of the bit within the SFR.
sfr-address is the address of an SFR.
sbit-address is the address of the SFR bit.
With typical 8051 applications, it is often necessary to access individual bits within an SFR. The sbit type provides access to bit-addressable SFRs and other bit-addressable objects. For example:
sbit EA = 0xAF;
This declaration defines EA as the SFR bit at address 0xAF. On the 8051, this is the enable all bit in the interrupt enable register.
精彩评论