• 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: 在header檔中定義全域的struct變數
#5
資深會員
資深會員


查看用戶資訊
感謝您的回覆,已拜讀兩份說明,的確是相當實用的文件

發表於: 2008/4/17 12:11
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 在header檔中定義全域的struct變數
#4
版主
版主


查看用戶資訊
可以參考 W401 的第七章說明與練習,也可以參考更進階的 WAP002 教材。
以上兩份教材都可以在左邊下載中心找到。

發表於: 2008/4/15 11:22
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 在header檔中定義全域的struct變數
#3
資深會員
資深會員


查看用戶資訊
感謝指教

小弟最近接觸的程式因行數較多,想拆成多個檔案方便管理,但突然發現自己對於header的定義及使用方式不太熟悉,整理程式碼時又遇到許多全域變數,造成想拆都不知如何下手

不知各位前輩能否提供一些有關自訂header使用上的相關經驗?又該如何尋找相關的說明資料?

發表於: 2008/4/14 22:03
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 在header檔中定義全域的struct變數
#2
版主
版主


查看用戶資訊
如果每個程式都用 extern struct 的宣告,那誰是真正的主人? 所以最後一定要有人將 extern 拿掉告訴其他要使用此結構的人說我在這裡宣告此結構,你們都要以我為參考。

extern 只是宣告說 : 此變數已在其他地方宣告過,叫 Linker 自己去找這個變數最後的位址在哪? 同名稱的變數只能唯一,要共用就必須用 extern 宣告。

發表於: 2008/4/14 10:54
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


在header檔中定義全域的struct變數
#1
資深會員
資深會員


查看用戶資訊
小弟使用的是MPLAB+C18

mcc18目錄下的p18f6722.h中,看到如下定義:
extern volatile near union {
struct {
unsigned ABDEN:1;
unsigned WUE:1;
unsigned :1;
unsigned BRG16:1;
unsigned SCKP:1;
unsigned :1;
unsigned RCIDL:1;
unsigned ABDOVF:1;
};
struct {
unsigned :6;
unsigned RCMT:1;
};
} BAUDCON1bits;


只要include <p18f6722.h>,在程式中可以直接使用
BAUDCON1bits.BRG16=1;

----------------------------------------------------------------
想請教各位前輩,BAUDCON1bits.BRG16 代表的是一個全域變數嗎?即是說,只要多個程式檔中各自include<p18f6722.h>,便能共用BAUDCON1bits.BRG16的值嗎?

小弟試著自訂一個utility.h檔,並於其內宣告一個struct,希望只要include "utility.h"後,便可直接在main.c與utility.c內,使用PData.name[0]='a';的語法

但實際使用時,main.c檔內若沒有定義該struct,便無法操作PData的值。

小弟希望能夠在多個.c檔中共用PData,是否能夠只要在header中定義一次,以後便不必再宣告呢?

在mcc目錄中,p18f6722的副檔有.h、.inc、.asm、.lib,是否與此有關?

在多個程式檔中多次以extern struct宣告結構,會覺得程式碼有些冗長。

還請各位前輩提示小弟一些可行的作法

下面是小弟使用的檔案及宣告的struct:
-------------------------------------------------------------
main.c
utility.c
utility.h
--------------------------------------------------------------

extern struct
{
char name[16]; //Unit Name[0]
char status[2]; //Status[16]
char date[7]; //Date[18]
char utct[7]; //UTC Time[25]
char lat[11]; //Latitude[32]
char lon[12]; //Longitude[43]
char speed[10]; //Speed Over
}PData;

-------------------------------------------------------------------------






發表於: 2008/4/13 17:54
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... ]

教育訓練中心

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