• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   2 Anonymous Users






Re: 請教如何重新定義一次控制16Bit呢?
#7
資深會員
資深會員


查看用戶資訊
參照:

BMW937 寫到:
目前試的結果,我設的LATD0~15對MCU而言只是個變數,
但並沒有對MCU IO pin控制,不知如何才可以對LATD實際
address控制呢??    ......嗚......

會想這麼設定是希望在寫程式時可以更容易,
我會再試看看@@,若前輩有任何建議,煩請不吝指教~



寫個小副程式,將變數的值輸出到port去
每次運算完後,都呼叫一次該副程式即可
至於該程式怎麼寫
方法很多
可以 byte +AND/OR,也可以 bit to bit
很容易, 相信你會的

至於版主說的, 是必須先注意的事項, 有時是很容易忽略的工作


發表於: 2007/4/26 14:36
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教如何重新定義一次控制16Bit呢?
#6
版主
版主


查看用戶資訊
TRISD 設為輸出了嗎?

發表於: 2007/4/26 9:27
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教如何重新定義一次控制16Bit呢?
#5
新會員
新會員


查看用戶資訊
感謝前輩指點^^
目前試的結果,我設的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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教如何重新定義一次控制16Bit呢?
#4
資深會員
資深會員


查看用戶資訊
1.
既然是用16bit, 變數當然也要是16bit的
所以 unsigned char IOAccess ;
要改成 unsigned int IOAccess ;


2.
union 的操作,要指定是其中的哪個變數(成員)

所以對 IOAccess 的操作要改成
SystemIO.IOAccess = 0x1234;

要針對其中某個bit 操作時則為
SystemIO.LATD0 = 1;

發表於: 2007/4/25 16:26
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教如何重新定義一次控制16Bit呢?
#3
新會員
新會員


查看用戶資訊
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教如何重新定義一次控制16Bit呢?
#2
資深會員
資深會員


查看用戶資訊
使用union 即可

發表於: 2007/4/24 20:22
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請教如何重新定義一次控制16Bit呢?
#1
新會員
新會員


查看用戶資訊
各位前輩,
我使用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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------