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


Browsing this Thread:   1 Anonymous Users






Re: 請教一個觀念,關於ADRESH+ADRESL
#2
高級會員
高級會員


查看用戶資訊
可以試試union(共同空間)它是ANSI C的語法.用起來很方便.
union AD_TAG { int i; char ch[2];};
union AD_TAG A_MAX;
A_MAX.ch[0]=ADRESH;//將AD的HI byte 放到共同空間的HI BYTE
A_MAX.ch[1]=ADRESL;//將AD的LOW byte 放到共同空間的LowBYTE
A_MAX.i 就是A_MAX.ch[0]與A_MAX.ch[1]兩個Byte複合起來的int型別.如果要運算時,直接拿A_MAX.i 來用就是int,當要各別運算Hi Byte或Low時,就是A_MAX.ch[0]或A_MAX.ch[1]

我沒有用HI_TECH C,可參考HI_TECH C語法的說明(不要照抄去Compile又來問為甚麼Compile不會過)做做看.

發表於: 2008/8/28 17:42
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請教一個觀念,關於ADRESH+ADRESL
#1
新會員
新會員


查看用戶資訊
請教各位版友,

目前小弟採用PIC12F675,採用10BIT AD轉換後靠右將值放置在ADRESH及ADRESL~
但小弟想將這二個值合在一起運算,即~
ADRESULT(16bits) = ADRESH(8bits)+ADRESL(8bits)
小弟的程式寫法如下~
int ADRESULT ;
ADRESULT=ADRESH;
ADRESULT<<8;
ADRESULT|=ADRESL;

這樣的寫法對嗎?個人很懷疑~所以上來請教,若遇到這樣的問題,程式要如何寫才是正確的?

曾有搜尋過相關的題目,有版友是用以下方式完成

word temp;
temp =((word)(ADRESH<<8));
temp |=(word)(ADRESL);

我曾經寫在程式試過,但complier時發生錯誤,訊息好像是指沒有定義word指令,complier我是用hi-tech c

發表於: 2008/8/28 15:14
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... ]

教育訓練中心

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