這句話定義了一個位域,bit0是該位域的域名,並且bit0只佔用一個位。
位域是指信息在存儲時,並不須要佔用一個完整的字節, 而只需佔幾個或一個二進制位。爲了節省存儲空間,並使處理簡便,C語言提供了一種數據結構,稱爲「位域」或「位段」。所謂「位域」是把一個字節中的二進位劃分爲幾個不一樣的區域, 並說明每一個區域的位數。每一個域有一個域名,容許在程序中按域名進行操做。 這樣就能夠把幾個不一樣的對象用一個字節的二進制位域來表示。編程
#define Uint unsigned int typedef struct { Uint bit0 : 1; Uint bit1 : 1; Uint bit2 : 1; Uint bit3 : 1; Uint bit4 : 1; Uint bit5 : 1; Uint bit6 : 1; Uint bit7 : 1; Uint bit8 : 1; Uint bit9 : 1; Uint bit10 : 1; Uint bit11 : 1; Uint bit12 : 1; Uint bit13 : 1; Uint bit14 : 1; Uint bit15 : 1; }Bit; typedef struct { Uint bytel : 8; Uint byteh : 8; }Byte; typedef union { Bit bit; Byte byte; Uint port; }UNport; #define PA ((volatile UNport *)(0x7000)) #define PA_Buffer ((volatile UNport *)(0x7001)) #define PA_Dir ((volatile UNport *)(0x7002)) #define PA_Attrib ((volatile UNport *)(0x7003)) #define PA_Latch ((volatile UNport *)(0x7004)) #define PB ((volatile UNport *)(0x7005)) #define PB_Buffer ((volatile UNport *)(0x7006)) #define PB_Dir ((volatile UNport *)(0x7007)) #define PB_Attrib ((volatile UNport *)(0x7008)) #define Poscu ((volatile UNport *)(0x7013)) #define Ptbu ((volatile UNport *)(0x700e)) #define Ptbc ((volatile UNport *)(0x700f)) #define Pt0 ((volatile UNport *)(0x700a)) #define Pt1 ((volatile UNport *)(0x700c)) #define Pt0u ((volatile UNport *)(0x700b)) #define Pt1u ((volatile UNport *)(0x700d)) #define Pintu ((volatile UNport *)(0x7010)) #define Pintc ((volatile UNport *)(0x7011)) #define Padm ((volatile UNport *)(0x7014)) #define Padl ((volatile UNport *)(0x702c)) #define Padu ((volatile UNport *)(0x7015)) #define Padmuxu ((volatile UNport *)(0x702b)) #define Pda0 ((volatile UNport *)(0x7017)) #define Pda1 ((volatile UNport *)(0x7016)) #define Pdau ((volatile UNport *)(0x702a)) #define Pwdogc ((volatile UNport *)(0x7012)) #define Pflashu ((volatile UNport *)(0x7555)) //------------------------------------------------------------------------------------------------------- //如下部分在編程中直接調用使用; #define Watchdog_Clear Pwdogc->port #define P0_0 PA->bit.bit0 #define P0_1 PA->bit.bit1 #define P0_2 PA->bit.bit2 #define P0_3 PA->bit.bit3 #define P0_4 PA->bit.bit4 #define P0_5 PA->bit.bit5 這種結構體定義方式書上沒有解釋?不明白什麼意思?Uint bit: 1; : 1?沒見過?爲何這樣能夠將凌陽單片機的接口進行位定義?
回答:數據結構
一.code
二.對象