中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > MSP430單片機(jī)學(xué)習(xí)小記1--基礎(chǔ)定時(shí)器

        MSP430單片機(jī)學(xué)習(xí)小記1--基礎(chǔ)定時(shí)器

        作者: 時(shí)間:2016-08-23 來(lái)源:網(wǎng)絡(luò) 收藏

          基于單片機(jī),公司采用的是模塊化的內(nèi)部結(jié)構(gòu),每個(gè)模塊,在各個(gè)不同型號(hào)的單片機(jī)內(nèi)都是相同的,相同的尋址,相同的操作方式,模塊有限,于是一個(gè)一個(gè)開始進(jìn)行整理。

        本文引用地址:http://www.antipu.com.cn/article/201608/295905.htm

          第一個(gè)模塊:基礎(chǔ)定時(shí)器

          參考資料:數(shù)據(jù)手冊(cè) ,使用手冊(cè) ,示例程序,以及那份特別特別有用的頭文件。

          Exampli Code:

          進(jìn)入中斷示例程序

          /************************************************************/

          1;時(shí)鐘源為ACLK,為單片機(jī)提供1/4S定時(shí)中斷,LCD提供512HZ刷新頻率

          BTCTL=BT_ADLY_250+BT_fLCD_512; //250MS延時(shí)加512HZ刷新頻率。

          備注:上電復(fù)位后,BT的寄存器值并不會(huì)恢復(fù)成一個(gè)默認(rèn)值

          而是保持不變,因此,每次上電的時(shí),均要進(jìn)行配置,而且最好直接采用賦值

          語(yǔ)句。一條語(yǔ)句足矣

          /************************************************************/

          /************************************************************/

          /************************************************************/

          /************************************************************/

          Void main(void)

          {

          WDTCTL=WDTPW+WDTHOLD; //close the wdtdog

          FLL_CTL0&= ~XTS_FLL; //可省略,默認(rèn)選擇低頻晶振

          FLL_CTL0|=XCAP18PF; //配置內(nèi)部晶振

          P1DIR|=BIT0; //OUTPUT

          BTCTL=BT_ADLY_250+BT_fLCD_512; //250MS延時(shí)加512HZ刷新頻率。

          IE2|=BE; //打開中斷

          __EINT();

          While(1)

          {;}

          }

          /************************************************************/

          #pragma vector=BASICMER_VECTOR

          __interrupt void basic_timer_ISR(void)

          {

          P1OUT ^= 0x01; // Toggle P1.0

          }

          /************************************************************

          參考的頭文件:

          * BASIC TIMER 基礎(chǔ)定時(shí)器的功能概述

          BASIC TIMER 能在無(wú)需CPU干擾的情況下產(chǎn)生2的N次方個(gè)定時(shí)周期

          如果我們采用32768KHZ =1/2^15次方,所以,最長(zhǎng)的定時(shí)時(shí)間可以達(dá)到

          2S鐘

          ************************************************************/

          #define ___HAS_BT__ /* Definition to show that Module is available */

          #define BTCTL_ (0x0040u) /* Basic Timer Control * /SFR

          DEFC( BTCTL , BTCTL_)

          /* 位定義The bit names have been prefixed with "BT" */

          #define BTIP0 (0x01)

          #define BTIP1 (0x02)

          #define BTIP2 (0x04)

          #define BTFRFQ0 (0x08)

          #define BTFRFQ1 (0x10)

          #define BTDIV (0x20) /* fCLK2 = ACLK:256 */

          #define BTHOLD (0x40) /* BT1 is held if this bit is set *,如果這個(gè)位置1,則暫停/

          利用 BTCTL|=BTHOLD; //可以使其暫停。

          #define BTSSEL (0x80) /* fBT = fMCLK (main clock) 位定義*/

          備注:BTSSEL ,與BTDIV 確定是否對(duì)信號(hào)源進(jìn)行分頻。分頻后它的最長(zhǎng)延時(shí)如果使用32768KHZ的話,可以達(dá)到2S

          注:為L(zhǎng)CD提供的刷新頻率沒有使用分頻。

          快捷定義:

          #define BTCNT1_ (0x0046u) /* Basic Timer Count 1 */

          DEFC( BTCNT1 , BTCNT1_)

          #define BTCNT2_ (0x0047u) /* Basic Timer Count 2 */

          DEFC( BTCNT2 , BTCNT2_)

          /* Frequency of the BTCNT2 coded with Bit 5 and 7 in BTCTL */

          #define BT_fCLK2_ACLK (0x00)

          #define BT_fCLK2_ACLK_DIV256 (BTDIV)

          #define BT_fCLK2_MCLK (BTSSEL)

          /* Interrupt interval time fINT coded with Bits 0-2 in BTCTL */

          #define BT_fCLK2_DIV2 (0x00) /* fINT = fCLK2:2 (default) */

          #define BT_fCLK2_DIV4 (BTIP0) /* fINT = fCLK2:4 */

          #define BT_fCLK2_DIV8 (BTIP1) /* fINT = fCLK2:8 */

          #define BT_fCLK2_DIV16 (BTIP1+BTIP0) /* fINT = fCLK2:16 */

          #define BT_fCLK2_DIV32 (BTIP2) /* fINT = fCLK2:32 */

          #define BT_fCLK2_DIV64 (BTIP2+BTIP0) /* fINT = fCLK2:64 */

          #define BT_fCLK2_DIV128 (BTIP2+BTIP1) /* fINT = fCLK2:128 */

          #define BT_fCLK2_DIV256 (BTIP2+BTIP1+BTIP0) /* fINT = fCLK2:256 */

          /* Frequency of LCD coded with Bits 3-4 */

          #define BT_fLCD_DIV32 (0x00) /* fLCD = fACLK:32 (default) */

          #define BT_fLCD_DIV64 (BTFRFQ0) /* fLCD = fACLK:64 */

          #define BT_fLCD_DIV128 (BTFRFQ1) /* fLCD = fACLK:128 */

          #define BT_fLCD_DIV256 (BTFRFQ1+BTFRFQ0) /* fLCD = fACLK:256 */

          /* LCD frequency values with fBT=fACLK */

          #define BT_fLCD_1K (0x00) /* fACLK:32 (default) */

          #define BT_fLCD_512 (BTFRFQ0) /* fACLK:64 */

          #define BT_fLCD_256 (BTFRFQ1) /* fACLK:128 */

          #define BT_fLCD_128 (BTFRFQ1+BTFRFQ0) /* fACLK:256 */

          //ACLK提供時(shí)鐘源,來(lái)提供LCD的刷新頻率。

          /* LCD frequency values with fBT=fMCLK */

          #define BT_fLCD_31K (BTSSEL) /* fMCLK:32 */

          #define BT_fLCD_15_5K (BTSSEL+BTFRFQ0) /* fMCLK:64 */

          #define BT_fLCD_7_8K (BTSSEL+BTFRFQ1+BTFRFQ0) /* fMCLK:256 */

          ////MCLK提供時(shí)鐘源,來(lái)提供LCD的刷新頻率。

          /* with assumed vlues of fACLK=32KHz, fMCLK=1MHz */

          /* fBT=fACLK is thought for longer interval times */

          #define BT_ADLY_0_064 (0x00) /* 0.064ms interval (default) */

          #define BT_ADLY_0_125 (BTIP0) /* 0.125ms " */

          #define BT_ADLY_0_25 (BTIP1) /* 0.25ms " */

          #define BT_ADLY_0_5 (BTIP1+BTIP0) /* 0.5ms " */

          #define BT_ADLY_1 (BTIP2) /* 1ms " */

          #define BT_ADLY_2 (BTIP2+BTIP0) /* 2ms " */

          #define BT_ADLY_4 (BTIP2+BTIP1) /* 4ms " */

          #define BT_ADLY_8 (BTIP2+BTIP1+BTIP0) /* 8ms " */

          #define BT_ADLY_16 (BTDIV) /* 16ms " */

          #define BT_ADLY_32 (BTDIV+BTIP0) /* 32ms " */

          #define BT_ADLY_64 (BTDIV+BTIP1) /* 64ms " */

          #define BT_ADLY_125 (BTDIV+BTIP1+BTIP0) /* 125ms " */

          #define BT_ADLY_250 (BTDIV+BTIP2) /* 250ms " */

          #define BT_ADLY_500 (BTDIV+BTIP2+BTIP0) /* 500ms " */

          #define BT_ADLY_1000 (BTDIV+BTIP2+BTIP1) /* 1000ms " */

          #define BT_ADLY_2000 (BTDIV+BTIP2+BTIP1+BTIP0) /* 2000ms " */

          //注:ACLK提供定時(shí)頻率,利用宏定義進(jìn)行設(shè)置延時(shí)。

          /* fCLK2=fMCLK (1MHz) is thought for short interval times */

          /* the timing for short intervals is more precise than ACLK */

          /* NOTE */

          /* Be sure that the SCFQCTL-Register is set to 01Fh so that fMCLK=1MHz */

          /* Too low interval time results in interrupts too frequent for the processor to handle! */

          #define BT_MDLY_0_002 (BTSSEL) /* 0.002ms interval *** interval times */

          #define BT_MDLY_0_004 (BTSSEL+BTIP0) /* 0.004ms " *** too short for */

          #define BT_MDLY_0_008 (BTSSEL+BTIP1) /* 0.008ms " *** interrupt */

          #define BT_MDLY_0_016 (BTSSEL+BTIP1+BTIP0) /* 0.016ms " *** handling */

          #define BT_MDLY_0_032 (BTSSEL+BTIP2) /* 0.032ms " */

          #define BT_MDLY_0_064 (BTSSEL+BTIP2+BTIP0) /* 0.064ms " */

          #define BT_MDLY_0_125 (BTSSEL+BTIP2+BTIP1) /* 0.125ms " */

          #define BT_MDLY_0_25 (BTSSEL+BTIP2+BTIP1+BTIP0)/* 0.25ms " */

          //選擇fCLK2=fMCLK (1MHz)來(lái)提供時(shí)鐘源而產(chǎn)生的時(shí)鐘延時(shí)。適合比較短的延時(shí)。但是單片機(jī)就不能進(jìn)入LPM3狀態(tài)了。

          /* Reset/Hold coded with Bits 6-7 in BT(1)CTL */

          /* this is for BT */

          //#define BTRESET_CNT1 (BTRESET) /* BTCNT1 is reset while BTRESET is set */

          //#define BTRESET_CNT1_2 (BTRESET+BTDIV) /* BTCNT1 .AND. BTCNT2 are reset while ~ is set */

          /* this is for BT1 */

          #define BTHOLD_CNT1 (BTHOLD) /* BTCNT1 is held while BTHOLD is set */

          #define BTHOLD_CNT1_2 (BTHOLD+BTDIV) /* BT1CNT1 .AND. BT1CNT2 are held while ~ is set */

          /* INTERRUPT CONTROL BITS */

          /* #define BTIE 0x80 */ 位于IE2中斷控制位

          /* #define BTIFG 0x80 */



        關(guān)鍵詞: TI MSP430

        評(píng)論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉