• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 可以將變數的某bit指向實體io嗎?
#2
版主
版主


查看用戶資訊
不是很了解你的用法,我覺得 myPort 的 union 的定義是可以省略的。

參照:
我是想說把分散在各PORT的IO能用一個變數來改變各IO值

只要直接用 PORTF 就可以了。在該元件的H檔裡,PORTF & LATFBITS 都是宣告再同一個 union 的。

extern volatile unsigned int  PORTF __attribute__((__sfr__));
typedef struct tagPORTFBITS {
  
unsigned RF0:1;
  
unsigned RF1:1;
  
unsigned RF2:1;
  
unsigned RF3:1;
  
unsigned RF4:1;
  
unsigned RF5:1;
  
unsigned RF6:1;
  
unsigned RF7:1;
  
unsigned RF8:1;
  
unsigned :3;
  
unsigned RF12:1;
  
unsigned RF13:1;
PORTFBITS;
extern volatile PORTFBITS PORTFbits __attribute__((__sfr__));

extern volatile unsigned int  LATF __attribute__((__sfr__));
typedef struct tagLATFBITS {
  
unsigned LATF0:1;
  
unsigned LATF1:1;
  
unsigned LATF2:1;
  
unsigned LATF3:1;
  
unsigned LATF4:1;
  
unsigned LATF5:1;
  
unsigned LATF6:1;
  
unsigned LATF7:1;
  
unsigned LATF8:1;
  
unsigned :3;
  
unsigned LATF12:1;
  
unsigned LATF13:1;
LATFBITS;
extern volatile LATFBITS LATFbits __attribute__((__sfr__));

發表於: 2007/11/19 10:11
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


可以將變數的某bit指向實體io嗎?
#1
初級會員
初級會員


查看用戶資訊
我是想把實體io對應到myPort這個變數的bit,程式碼如下:

union {
struct {
unsigned b0: 1;
unsigned b1: 1;
unsigned b2: 1;
unsigned b3: 1;
unsigned b4: 1;
unsigned b5: 1;
unsigned B6: 1;
unsigned B7: 1;
} oneBit;
unsigned char allBits;
} myPort;

#define myPort.oneBit.b1 LATDbits.LATF0;
#define myPort.oneBit.b2 LATDbits.LATF1;
#define myPort.oneBit.b3 LATDbits.LATF2;
#define myPort.oneBit.b4 LATDbits.LATF3;
#define myPort.oneBit.b5 LATDbits.LATF4;
#define myPort.oneBit.b6 LATDbits.LATF5;

很不幸的編譯在上面define的時候會有warning,而且不能使用
不知道有沒有辦法處理??
我是想說把分散在各PORT的IO能用一個變數來改變各IO值

發表於: 2007/11/16 10:12
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... ]

教育訓練中心

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