• 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: 請問C18函式的&與|有何不同?
#7
版主
版主


查看用戶資訊
剛看到新版的 C18 裡 Timer.h 檔裡多了一些 OR 的定義,所以要使用 OR 的方式計算 OpenTimer ( ) 裡的常數值揪需將 #define USE_OR_MASK 的定義加入到 Timer.h 裡的第一行。如果沒加入此定義的話Timer的函數裡的設定常數運算就會採用 AND 方式。

Timer.h 裡的片斷:
#ifdef USE_OR_MASKS
#define TIMER_INT_OFF          0b00000000  // Interrupts disabled
#define TIMER_INT_ON           0b10000000  // Interrupts enabled
#define TIMER_INT_MASK        (~TIMER_INT_ON)
:
:
:
//---------------AND MASK--------------------------------
#else //!USE_OR_MASKS
#define TIMER_INT_OFF  0b01111111  // Interrupts disabled
#define TIMER_INT_ON   0b11111111  // Interrupts enabled

/* ***** TIMER0 ***** */

發表於: 2008/7/9 15:12
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問C18函式的&與|有何不同?
#6
版主
版主


查看用戶資訊
1. 看一下 Timer.h 裡的定義:
/* Timer1 Control Register (T1CON) Bit Defines */

#define T1_ON               0xffff      /* Timer1 ON */
#define T1_OFF              0x7fff      /* Timer1 OFF */

#define T1_IDLE_CON         0xdfff      /* operate during sleep */
#define T1_IDLE_STOP        0xffff      /* stop operation during sleep */

#define T1_GATE_ON          0xffff      /* Timer Gate time accumulation enabled */


2. 看一下 C:\MCC18\doc\periph-lib\timer.htm 裡的說明,因為在 h 檔裡的定義關係,所以就要使用&做常數的運算:
Function:
 
Configure and enable timer0.
 
Include:
 
timers.h
 
Prototype
:
 
void OpenTimer0unsigned char config );
 
Arguments:
 
config

A bitmask that is created by performing either a bitwise 
AND operation (&) or bitwise OR operation (|) ,
 
which is user configurablewith a value from each of the categories listed below
These values are defined in the file timers.h.
 
 
 
Enable Timer0 Interrupt:

            
TIMER_INT_ON             Interrupt enabled

            TIMER_INT_OFF           Interrupt disabled

Timer Width
:

            
T0_8BIT                       8-bit mode

            T0_16BIT                     16
-bit mode

Clock Source
:

            
T0_SOURCE_EXT           External clock source (I/O pin)

            
T0_SOURCE_INT           Internal clock source (Tosc)

External Clock Trigger (for T0_SOURCE_EXT):

            
T0_EDGE_FALL             External clock on falling edge

            T0_EDGE_RISE             External clock on rising edge
 
 
 Prescale Value
:

            
T0_PS_1_1                   1:1 prescale

            T0_PS_1_2                   1
:2 prescale

            T0_PS_1_4                   1
:4 prescale

            T0_PS_1_8                   1
:8 prescale

            T0_PS_1_16                 1
:16 prescale

            T0_PS_1_32                 1
:32 prescale

            T0_PS_1_64                 1
:64 prescale

            T0_PS_1_128               1
:128 prescale

            T0_PS_1_256               1
:256 prescale
 
Remarks
:
 
This function configures timer0 according to the options specified and then enables it.
 
File Name:
 
t0open.c
 
Code Example
:
 
With bitwise AND (&mask:

OpenTimer0TIMER_INT_OFF &

            
T0_8BIT       &

            
T0_SOURCE_INT &

            
T0_PS_1_32 );

 

With bitwise OR (|mask:

OpenTimer0TIMER_INT_OFF |

            
T0_8BIT       |

            
T0_SOURCE_INT |

            
T0_PS_1_32 );

發表於: 2008/6/27 14:44
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問C18函式的&與|有何不同?
#5
資深會員
資深會員


查看用戶資訊
大家好:
OpenTimer0( TIMER_INT_OFF|T0_8BIT|T0_SOURCE_INT|T0_PS_1_32
);
Nop();//斷點一
OpenTimer0( TIMER_INT_OFF&T0_8BIT&T0_SOURCE_INT&T0_PS_1_32 );
Nop();//斷點二

我用軟體模擬時|不正確而&正確,
在timer.h中有一USE_OR_MASKS是要使用|或&功能,
而我不知該USE_OR_MASKS是在那一檔案已有define.
不知各位先進有何看法,煩請告知.
Thanks.

發表於: 2008/6/26 9:44
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問C18函式的&與|有何不同?
#4
資深會員
資深會員


查看用戶資訊
引言:<div class="xoopsQuote"><blockquote><br />jlian 寫到:<br />大家好:<br />我想我知道了,應該是一樣的結果,只是用&或|的方式而已.<br />當然&與|也應該不可混合使用才對吧!<br />Thanks.</blockquote></div><br /><br />兩者概念上就差很多了。單就邏輯觀念對應到單晶片來說。&是用來關閉某些東西,|是用來啟用某些東西。在C18函式庫中使用|就是把這些功能"Open"起來。<br /><br />你把函式定義的Marco用二進位表示來看就一目了然了。

發表於: 2008/6/24 20:00
不要問我哪裡來,我只是個流浪天涯的工程師
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問C18函式的&與|有何不同?
#3
資深會員
資深會員


查看用戶資訊
結果應該完全不一樣ㄛ

建議先開啟timer.h
把裡面各參數定義值看一下
應該就會明白為什麼要用 & 才對



發表於: 2008/6/24 17:32
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問C18函式的&與|有何不同?
#2
資深會員
資深會員


查看用戶資訊
大家好:
我想我知道了,應該是一樣的結果,只是用&或|的方式而已.
當然&與|也應該不可混合使用才對吧!
Thanks.

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


請問C18函式的&與|有何不同?
#1
資深會員
資深會員


查看用戶資訊
大家好:
OpenTimer0( TIMER_INT_OFF &
T0_SOURCE_INT &
T0_PS_1_32 );

OpenTimer0( TIMER_INT_OFF |
T0_SOURCE_INT |
T0_PS_1_32 );
請問上面兩個這樣設到底有何差別?
煩請告知.
Thanks.


發表於: 2008/6/24 16:40
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... ]

教育訓練中心

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