Re: 請教如何重新定義一次控制16Bit呢?
|
||||
---|---|---|---|---|
版主
|
TRISD 設為輸出了嗎?
發表於: 2007/4/26 9:27
|
|||
|
Re: 請教如何重新定義一次控制16Bit呢?
|
||||
---|---|---|---|---|
新會員
|
感謝前輩指點^^
目前試的結果,我設的LATD0~15對MCU而言只是個變數, 但並沒有對MCU IO pin控制,不知如何才可以對LATD實際 address控制呢?? ......嗚...... 會想這麼設定是希望在寫程式時可以更容易, 我會再試看看@@,若前輩有任何建議,煩請不吝指教~ union { unsigned int IOAccess; struct tagLATDBITS { unsigned LATD0:1; unsigned LATD1:1; unsigned LATD2:1; unsigned LATD3:1; unsigned LATD4:1; unsigned LATD5:1; unsigned LATD6:1; unsigned LATD7:1; unsigned LATD8:1; unsigned LATD9:1; unsigned LATD10:1; unsigned LATD11:1; unsigned LATD12:1; unsigned LATD13:1; unsigned LATD14:1; unsigned LATD15:1; } LATDBITS; }SystemIO ; while(1) { SystemIO.LATDBITS.LATD7=1; SystemIO.LATDBITS.LATD7=0; SystemIO.IOAccess = 0xFFFF; SystemIO.IOAccess = 0x0000; }
發表於: 2007/4/26 2:32
|
|||
|
Re: 請教如何重新定義一次控制16Bit呢?
|
||||
---|---|---|---|---|
資深會員
|
1.
既然是用16bit, 變數當然也要是16bit的 所以 unsigned char IOAccess ; 要改成 unsigned int IOAccess ; 2. union 的操作,要指定是其中的哪個變數(成員) 所以對 IOAccess 的操作要改成 SystemIO.IOAccess = 0x1234; 要針對其中某個bit 操作時則為 SystemIO.LATD0 = 1;
發表於: 2007/4/25 16:26
|
|||
|
Re: 請教如何重新定義一次控制16Bit呢?
|
||||
---|---|---|---|---|
新會員
|
Dear 前輩,
因為小弟是第一次使用union & struct,有上網參考其他前輩的寫法,以下是我重新定義的部分,可是Build會錯誤,還請前輩指教, while(1) { SystemIO = 0x00; //----error DelayX1ms(100); SystemIO = 0xFF; //----error DelayX1ms(100); } union { unsigned char IOAccess ; struct { unsigned LATD0:1; unsigned LATD1:1; unsigned LATD2:1; unsigned LATD3:1; unsigned LATD4:1; unsigned LATD5:1; unsigned LATD6:1; unsigned LATD7:1; unsigned LATD8:1; unsigned LATD9:1; unsigned LATD10:1; unsigned LATD11:1; unsigned LATC12:1; unsigned LATC13:1; unsigned LATC14:1; unsigned LATC15:1; }; } SystemIO ;
發表於: 2007/4/25 14:38
|
|||
|
Re: 請教如何重新定義一次控制16Bit呢?
|
||||
---|---|---|---|---|
資深會員
|
使用union 即可
發表於: 2007/4/24 20:22
|
|||
|
請教如何重新定義一次控制16Bit呢?
|
||||
---|---|---|---|---|
新會員
|
各位前輩,
我使用PIC24,I/O要一次控制16bit,但只剩port C 4bit(12~15),port D 12BIT(0~11),該如何定義呢?? 請各位前輩多多指教~ //以下是我重新定義: typedef struct tagLATXBITS { unsigned LATD0:1; unsigned LATD1:1; unsigned LATD2:1; unsigned LATD3:1; unsigned LATD4:1; unsigned LATD5:1; unsigned LATD6:1; unsigned LATD7:1; unsigned LATD8:1; unsigned LATD9:1; unsigned LATD10:1; unsigned LATD11:1; unsigned LATC12:1; unsigned LATC13:1; unsigned LATC14:1; unsigned LATC15:1; } LATXBITS; int main(void) { DelayX1ms(200); init_PIC24FJ128GA010(); while(1) { LATXBITS = 0XFFFF; //compiler時會錯誤 LATXBITS = 0X0000; //compiler時會錯誤 } }
發表於: 2007/4/24 16:53
|
|||
|