Re: Byte資料個別定義
|
||||
---|---|---|---|---|
初級會員
|
不好意思,再次請教。
C18不支援8bit以上。 C18是用在PIC18 ? 那PIC18以上的晶片,是否有支援到8bit以上呢??(好像是C30?) 另外C18最大能訂到多大的DATA呢?? 下面是應該是PR為兩個BYTE資料?? 不知道能否訂到 unsigned long?? (4 Byte) 又再一次請教,謝謝大家 -====================== union{ unsigned int byte; struct{ unsigned x:2; unsigned o:6; unsigned w:2; unsigned a:2; unsigned e:4; } bit; }PR;
發表於: 2009/4/3 23:00
|
|||
|
Re: Byte資料個別定義
|
||||
---|---|---|---|---|
資深會員
|
因為C18不支援到8bit以上
發表於: 2009/4/3 17:13
|
|||
|
Re: Byte資料個別定義
|
||||
---|---|---|---|---|
初級會員
|
請問不能超過8 bits主要是因為??
MCU的關係??還是COMPILE的關係?? 還是無法一次定2 BYTE ?? 感謝解答
發表於: 2009/4/3 16:39
|
|||
|
Re: Byte資料個別定義
|
||||
---|---|---|---|---|
資深會員
|
不能超過8bit
unsigned o:9; //錯誤 真需要9bit, 只能先用int變數來運算,然後再想辦法轉換到bit裡面去
發表於: 2009/4/3 9:19
|
|||
|
Re: Byte資料個別定義
|
||||
---|---|---|---|---|
初級會員
|
謝謝 nicecookie 的詳細解惑。
不過又有一個問題又想請教。 如果我有兩個BYTE 資料。 分別為 2bits 9 bits 2bits 2 bits 1bit xxoooooo ooowwaae 由於那9bits是要做計算 0x000 ~ 0x1FF 又不要影響到 其他bits資料。 不知道該如何定義?(下面的定義不知道是否正確) 再一次謝謝大家 =============================== union{ unsigned int byte; struct{ unsigned x:2; unsigned o:9; unsigned w:2; unsigned a:2; unsigned e:1; } bit; }PR; PR.bit.x = 2; PR.bit.o = 511; PR.bit.w = 1; PR.bit.a = 0; PR.bit.e = 1; PR.byte = 0xBFE9;
發表於: 2009/4/2 22:22
|
|||
|
Re: Byte資料個別定義
|
||||
---|---|---|---|---|
版主
|
當然可以,多看一下 相關元件的 H 裡的定義。
nicecookie 提供了很好的範例說明。
發表於: 2009/4/2 10:10
Edited by Ryang on 2009年04月03日 14:38:20
|
|||
|
Re: Byte資料個別定義
|
||||
---|---|---|---|---|
資深會員
|
union{
unsigned char byte; struct{ unsigned a:3; unsigned b:4; unsigned c:1; }; }RR; RR.a=5; RR.b=0xA; RR.c=1; RR.byte=0x66;
發表於: 2009/4/2 0:25
|
|||
|
Byte資料個別定義
|
||||
---|---|---|---|---|
初級會員
|
一個Byte有8個bits
在C18定義變數時,可以把一個變數設定byte也可以定義bit 但不知道有沒有辦法把1個byte設定不同的bits ? 如我有3個變數。我想設定他們在同一個byte.. 但a 有3 bits b有 4 bits c 有1 bit 不知道在c18下能不能這樣設定? 謝謝大家~
發表於: 2009/4/2 0:12
|
|||
|