找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3556|回复: 0
打印 上一主题 下一主题
收起左侧

基于单片机的TDC-GP2热量表的程序设计

[复制链接]
跳转到指定楼层
楼主
ID:121142 发表于 2016-5-16 12:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


  1. //TDC-GP2与MSP430F413通讯C程序
  2. //========================================
  3. #include <msp430x43x.h>
  4. #include <math.h>
  5. //#include "heat_meter.h"
  6. //========================================
  7. #define Init_GP2                 0x70 //初始化TDC
  8. #define Start_Cycle              0x01 //脉冲发送
  9. #define Start_Temp               0x02 //开始温度测量
  10. #define Start_Cal_Resonator      0x03 //校准晶振时钟
  11. #define Start_Cal_TDC            0x04 //校准TDC

  12. //定义各管脚工作状态名称
  13. #define PVCCOn        P4OUT |= BIT0
  14. #define PVCCOff       P4OUT = 0;
  15. #define SSNEn         P3OUT &=~BIT0          // GP2 R/W enable
  16. #define SSNDs         P3OUT |= BIT0          // GP2 R/W disable
  17. #define RSTNHigh      P3OUT |= BIT4
  18. #define RSTNLow       P3OUT &=~BIT4
  19. #define StartEn       P1OUT |= BIT6          // GP2 En_Start
  20. #define StartDs       P1OUT &=~BIT6
  21. #define StopEn        P1OUT |= BIT7          // GP2 En_Stop
  22. #define StopDs        P1OUT &=~BIT7
  23. #define Up            P1OUT |= BIT2
  24. #define Down          P1OUT |= BIT3
  25. #define Close         P1OUT &=~(BIT2 + BIT3)
  26. //配置GP2流量测量
  27. //const unsigned char ConfigGP2[23] = {0x50,0x80,0x37,0x8A,0x68,0x81,0x21,0x44,0x00,0x82,0xE0,0x32,0x00,0x83,0x08,0x33,0x00,0x84,0x20,0x34,0x00,0x70,0x01};
  28. const unsigned char ReadGP2STAT[3] = {0xB4,0x55,0x55};
  29. const unsigned char ReadRes0[5] = {0xB0,0x55,0x55,0x55,0x55};
  30. const unsigned char ReadRes1[5] = {0xB1,0x55,0x55,0x55,0x55};
  31. const unsigned char ReadRes2[5] = {0xB2,0x55,0x55,0x55,0x55};
  32. const unsigned char ReadRes3[5] = {0xB3,0x55,0x55,0x55,0x55};
  33. //=========================================
  34. //以下为初始化函数
  35. void InitialPort(void);//初始化端口
  36. //以下为内部函数定义,详细说明见函数部分
  37. //=======================================
  38. void InitialGP2(void);//初始化GP2
  39. void OpCodeGP2 (unsigned char opcode); // 写1 Byte op-codes 到 GP2
  40. void ConfigGP2 (unsigned long data); // 配置GP2寄存器
  41. void MeasureTemp(void);//温度测量
  42. void ReadGP2ST(void);//读GP2状态寄存器
  43. void ReadData(unsigned char Count,volatile unsigned char * point,volatile unsigned char * point_d);//读GP2结果寄存器数据
  44. void FireStart(void);// 发送点火脉冲
  45. void CalStart(void);//校准时钟测量
  46. void HXOn(void);//切换校准时钟时高速晶振状态到开启
  47. void HXOff(void);//切换校准时钟时高速晶振状态到关闭
  48. void NOP10(void);// 10_NOP()机器周期延迟
  49. void TempCal(void);//温度校准测量
  50. //=======================================
  51. #pragma memory = no_init
  52. unsigned long DisplayData[8];//0:heat,1:cool,2:volume,3:heatKwh,4:volumeL,5:workTime,6:LCDDate,7:LCDTime
  53. #pragma memory = default
  54. unsigned char SPITxCount,SPIRxCount;
  55. unsigned char SPIMaskBuf[5];
  56. unsigned char Res0[4];
  57. unsigned char Res1[4];
  58. unsigned char Res2[4];
  59. unsigned char Res3[4];
  60. unsigned int GP2ST;
  61. unsigned long T1,T2,T3,T4;
  62. unsigned long PT1,PT2;
  63. float CorrectFactor;
  64. const float A = 3.862314E-3;
  65. const float B = -6.531493E-7;
  66. //=======================================
  67. union longValue
  68. {
  69. unsigned long uWord;
  70. unsigned char lByte[4];
  71. };
  72. union intValue
  73. {
  74. unsigned int uInt;
  75. unsigned char lByte[2];
  76. };
  77. //=======================================
  78. void main(void)
  79. {
  80. InitialPort();
  81. _EINT();
  82. SPIRxCount = 0;
  83. Delay(50000);

  84. _NOP();

  85. PVCCOn;
  86. InitialGP2(); //初始化GP2

  87. while(1)
  88. {
  89.   //HXOn();
  90.   //Delay(5000);
  91.   CalStart();   //时钟校准
  92.   //HXOff();
  93.   //MeasureTemp();
  94.   //_NOP();
  95.   //TempCal();
  96.   //Display(PT1);
  97.   //LCDRAM[3] |= 0x80;
  98.   //StopWTD();
  99.   //AdjustLCD();
  100.   //RunLCD();
  101.   Close;
  102.   Up;
  103.   FireStart();
  104.   Close;
  105.   Down;
  106.   LPM0;
  107.   ReadGP2ST();
  108.   ReadData(5,(unsigned char *)ReadRes0,(unsigned char *)Res0);
  109.   ReadData(5,(unsigned char *)ReadRes1,(unsigned char *)Res1);
  110.   ReadData(5,(unsigned char *)ReadRes2,(unsigned char *)Res2);
  111.   ReadData(5,(unsigned char *)ReadRes3,(unsigned char *)Res3);
  112.   _NOP();
  113.   StopWTD();
  114.   LPM3;
  115.   /*InitialGP2();
  116.   Close;
  117.   Down;
  118.   FireStart();
  119.   Close;
  120.   Up;
  121.   //LPM0;
  122.   StopWTD();
  123.   LPM3;
  124.   */
  125. }
  126. }
  127. //=======================================
  128. //端口初始化
  129. void InitialPort(void)
  130. {
  131. WDTCTL = WDTPW + WDTHOLD;    // Stop WDT
  132. //FLL_CTL0 = XCAP14PF;         //set load capacitance for 32k xtal

  133. //SCFQCTL = SCFQ_4M;

  134. //LCDCTL = LCDON + LCD4MUX + LCDP1;        // STK LCD 4Mux, S0-S19
  135. //BTCTL = BTFRFQ0;          // STK LCD freq
  136. P5SEL = 0xFC;                            // Common and Rxx all selected
  137. P4DIR |= BIT0;           //PVCC

  138. P1SEL |= BIT5;
  139. P1DIR |= BIT2 + BIT3 + BIT5 + BIT6 + BIT7;        //P1.2 SW2,P1.3 SW1
  140.                                                    //P1.5 32.768kHz Output as GP2 Clock
  141.                                                    //P1.6 as GP2 En_Start,P1.7 as GP2 En_Stop
  142. P2DIR |= BIT2 + BIT3;
  143. P2IE |= BIT7;
  144. P2IES |= BIT7;


  145. TACTL = TASSEL_1 + MC_2 + TACLR;    //ACLK, continous mode
  146. ME1 |= USPIE0;                            // Enable USART0 SPI mode
  147. UCTL0 |= CHAR + SYNC + MM;                // 8-bit SPI Master **SWRST**
  148. UTCTL0 |= /*CKPH + */SSEL1 + SSEL0 + STC;     // SMCLK, 3-pin mode
  149. UBR00 = 0x02;                             // UCLK/2
  150. UBR10 = 0x00;                             // 0
  151. UMCTL0 = 0x00;                            // no modulation
  152. UCTL0 &= ~SWRST;                          // Initalize USART state machine
  153. IE1 |= URXIE0;                            // Receive interrupt enable
  154. P3SEL |= 0x0E;                            // P3.1-3 SPI option select
  155. P3DIR |= BIT0 + BIT4;                     // P3.0 output direction
  156. TBCTL = TBSSEL_1 + ID_2 + TBCLR;          //Setup Timer_B
  157. TBCCR1 = 16384;
  158. TBCCTL1 =CCIE;
  159. TBCTL |= MC_2;
  160. }
  161. //========================================
  162. //GP2 寄存器配置
  163. void InitialGP2(void)
  164. {
  165. unsigned char i = 0;
  166. SSNDs;
  167. _NOP();
  168. RSTNHigh;
  169. _NOP();
  170. RSTNLow;
  171. _NOP();
  172. RSTNHigh;
  173. StartEn;  //开启start_en
  174. StopEn; //开启stop_en
  175. OpCodeGP2(0x50); // GP2复位
  176. _NOP();
  177. ConfigGP2(0x80338468);//内部不分频,fire脉冲频率为1MHz,发送3个fire脉冲。对于4MHz时钟校准是基于8个周期的32K时钟,高速时钟持续工作,温度测量应用高速时钟128us周期时间,2次热身测量,4个温度测量端口(2个温度传感器,一个测冷水,一个测热水)。TDC自动校准,选择测量范围2
  178. _NOP();
  179. ConfigGP2(0x81214400);//ALU计算第一个stop - start
  180. _NOP();
  181. ConfigGP2(0x82E01900); //启动所有GP2中断源,设置第一个stop的使能窗口,在50us后允许接受第一个stop脉冲
  182. _NOP();
  183. ConfigGP2(0x83081A00);//设置第2个stop的使能窗口,在51us后允许接受第二个stop脉冲, 256us后未接到stop信号溢出
  184. _NOP();
  185. ConfigGP2(0x84201A80);//设置第3个stop德使能窗口,在52us后允许接受第三个stop脉冲
  186. _NOP();
  187. ConfigGP2(0x85000000);
  188. _NOP();
  189. }
  190. //-----------------------------------
  191. void FireStart(void)
  192. {
  193. OpCodeGP2(0x70);  //Init
  194. //Delay(4000);
  195. _NOP();
  196. OpCodeGP2(0x01);  //Start Cycle
  197. //ReadGP2ST();
  198. _NOP();
  199. }
  200. //-----------------------------------
  201. void MeasureTemp(void)
  202. {
  203. unsigned char i;
  204. union longValue vardata;
  205. Delay(500);
  206. OpCodeGP2(Start_Temp);
  207. Delay(500);        //wait for measurement finish

  208. ReadGP2ST();

  209. if(GP2ST & 0x1E00)
  210. {
  211.   T1 = 0;
  212.   T2 = 0;
  213.   T3 = 0;
  214.   T4 = 0;
  215.   return;
  216. }

  217. ReadData(5,(unsigned char *)ReadRes0,(unsigned char *)Res0);
  218. ReadData(5,(unsigned char *)ReadRes1,(unsigned char *)Res1);
  219. ReadData(5,(unsigned char *)ReadRes2,(unsigned char *)Res2);
  220. ReadData(5,(unsigned char *)ReadRes3,(unsigned char *)Res3);
  221. _NOP();

  222. for (i = 0;i < 4;i++)
  223. {
  224.   vardata.lByte[i] = Res0[i];
  225. }
  226. T1 = vardata.uWord;

  227. for (i = 0;i < 4;i++)
  228. {
  229.   vardata.lByte[i] = Res1[i];
  230. }
  231. T2 = vardata.uWord;

  232. for (i = 0;i < 4;i++)
  233. {
  234.   vardata.lByte[i] = Res2[i];
  235. }
  236. T3 = vardata.uWord;

  237. for (i = 0;i < 4;i++)
  238. {
  239.   vardata.lByte[i] = Res3[i];
  240. }
  241. T4 = vardata.uWord;

  242. _NOP();

  243. }
  244. //-----------------------------------
  245. void CalStart(void)
  246. {
  247. unsigned char i;
  248. unsigned int High16,Low16;
  249. float buf;
  250.   
  251. union longValue vardata;
  252. union intValue varint;
  253. OpCodeGP2(0x03);
  254. LPM0;

  255. ReadData(5,(unsigned char *)ReadRes0,(unsigned char *)Res0);

  256. for (i = 0;i < 4;i++)
  257. {
  258.   vardata.lByte[i] = Res0[i];
  259. }

  260. varint.lByte[0] = vardata.lByte[0];
  261. varint.lByte[1] = vardata.lByte[1];

  262. Low16 = varint.uInt;

  263. varint.lByte[0] = vardata.lByte[2];
  264. varint.lByte[1] = vardata.lByte[3];

  265. High16 = varint.uInt;

  266. buf = (float)Low16;

  267. CorrectFactor = buf/65536 + High16;
  268. CorrectFactor *=1000;

  269. Display(CorrectFactor);

  270. LCDRAM[4] |= 0x80;
  271. AdjustLCD();
  272. RunLCD();
  273. }
  274. //===================================
  275. void HXOn(void)
  276. {
  277. ConfigGP2(0x80324668);
  278. }
  279. //===================================
  280. void HXOff(void)
  281. {
  282. ConfigGP2(0x80324E68);
  283. }
  284. //===================================
  285. void OpCodeGP2 (unsigned char opcode)     // send a 1 Byte opcode to the TDC-GP2
  286. {
  287. SSNDs;
  288. _NOP();
  289. SSNEn;
  290. _NOP();
  291. IE1 &=~ URXIE0;                            // Receive interrupt disable
  292. TXBUF0 = opcode;
  293. while (!(IFG1 & UTXIFG0));
  294. NOP10();
  295. //LPM0;
  296. SSNDs;
  297. IFG1 &=~ URXIFG0;
  298. IE1 |= URXIE0;                            // Receive interrupt enable  
  299. }
  300. //========================================
  301. void ConfigGP2 (unsigned long data)   // 配置TDC-GP2 寄存器
  302. {
  303. unsigned char i;                                                                  
  304. union longValue vardata;

  305. vardata.uWord = data;
  306.   
  307. SSNDs;
  308. _NOP();
  309. SSNEn;
  310. _NOP();

  311. //TXBUF0 = vardata.lByte[3];
  312.   
  313. for (i = 0;i < 4;i++)
  314. {
  315.   //LPM0;
  316.   TXBUF0 = vardata.lByte[3-i];
  317.   LPM0;
  318. }
  319. SSNDs;
  320. }
  321. //========================================
  322. void ReadGP2ST(void)
  323. {
  324. unsigned char i = 0;
  325. SSNDs;
  326. SSNEn;
  327. SPIRxCount = 0;
  328. for(i = 0; i < 3;i++)
  329. {
  330.   TXBUF0 = ReadGP2STAT[i];
  331.   LPM0;
  332. }
  333. //NOP10();
  334. SSNDs;
  335. GP2ST = SPIMaskBuf[1];
  336. GP2ST <<= 8;
  337. GP2ST |= SPIMaskBuf[2];
  338. }
  339. //========================================
  340. void ReadData(unsigned char Count, volatile unsigned char * point,volatile unsigned char * point_d)
  341. {
  342. unsigned char i;
  343. SSNDs;
  344. SSNEn;
  345. SPIRxCount = 0;

  346. for(i = 0;i < Count;i++)
  347. {
  348.   TXBUF0 = *(point + i);
  349.   LPM0;
  350. }
  351. //NOP10();
  352. SSNDs;

  353. for(i = 1;i < 5;i++)
  354. {
  355.   * (point_d + i - 1) = SPIMaskBuf[5 - i];
  356. }
  357. }
  358. //========================================
  359. void TempCal(void)
  360. {
  361. float temp,temp1,tempref;
  362. temp1 = T4;
  363. tempref = T1;
  364. temp = temp1 / tempref;
  365. PT1 = temp * 100000;
  366. }
  367. //========================================
  368. interrupt[UART0RX_VECTOR] void s_receive(void)
  369. {
  370. while ((IFG1 & UTXIFG0) == 0);
  371. if (SPIRxCount < 5)
  372.   {
  373.    SPIMaskBuf[SPIRxCount] = RXBUF0;
  374.    SPIRxCount ++;
  375.    //SSNDs;
  376.   }
  377. else
  378.   {
  379.    SPIRxCount = 0;
  380.   }

  381. LPM0_EXIT;
  382. }
  383. //========================================
  384. void NOP10(void)
  385. {
  386. _NOP();
  387. _NOP();
  388. _NOP();
  389. _NOP();
  390. _NOP();
  391. _NOP();
  392. _NOP();
  393. _NOP();
  394. _NOP();
  395. _NOP();
  396. }
  397. //=========================================
  398. interrupt [TIMERB1_VECTOR] void timerb1_int(void)
  399. {
  400. TBCCR1 +=16384;
  401. TBCCTL1 &=~CCIFG;
  402. //ClearWTD();
  403. _BIC_SR_IRQ(LPM3_bits);
  404. }
  405. //===========================================
  406. interrupt [PORT2_VECTOR] void GP2_int(void)
  407. {
  408. P2IFG = 0;
  409. LPM0_EXIT;
  410. }



  411. <msp430x43x.h>

  412. /********************************************************************
  413. *
  414. * Standard register and bit definitions for the Texas Instruments
  415. * MSP430 microcontroller.
  416. *
  417. * This file supports assembler and C/EC++ development for
  418. * MSP430x43x devices.
  419. *
  420. * Version 2.0
  421. *
  422. ********************************************************************/

  423. #ifndef __msp430x43x
  424. #define __msp430x43x


  425. #if (((__TID__ >> 8) & 0x7F) != 0x2b)     /* 0x2b = 43 dec */
  426. #error MSP430X43X.H file for use with ICC430/A430 only
  427. #endif


  428. #ifdef __IAR_SYSTEMS_ICC__
  429. #include <in430.h>
  430. #pragma language=extended

  431. #define DEFC(name, address) __no_init volatile unsigned char name @ address;
  432. #define DEFW(name, address) __no_init volatile unsigned short name @ address;

  433. #endif  /* __IAR_SYSTEMS_ICC__  */


  434. #ifdef __IAR_SYSTEMS_ASM__
  435. #define DEFC(name, address) sfrb name = address;
  436. #define DEFW(name, address) sfrw name = address;

  437. #endif /* __IAR_SYSTEMS_ASM__*/

  438. #ifdef __cplusplus
  439. #define READ_ONLY
  440. #else
  441. #define READ_ONLY const
  442. #endif


  443. /************************************************************
  444. * STANDARD BITS
  445. ************************************************************/

  446. #define BIT0                (0x0001)
  447. #define BIT1                (0x0002)
  448. #define BIT2                (0x0004)
  449. #define BIT3                (0x0008)
  450. #define BIT4                (0x0010)
  451. #define BIT5                (0x0020)
  452. #define BIT6                (0x0040)
  453. #define BIT7                (0x0080)
  454. #define BIT8                (0x0100)
  455. #define BIT9                (0x0200)
  456. #define BITA                (0x0400)
  457. #define BITB                (0x0800)
  458. #define BITC                (0x1000)
  459. #define BITD                (0x2000)
  460. #define BITE                (0x4000)
  461. #define BITF                (0x8000)

  462. /************************************************************
  463. * STATUS REGISTER BITS
  464. ************************************************************/

  465. #define C                   (0x0001)
  466. #define Z                   (0x0002)
  467. #define N                   (0x0004)
  468. #define V                   (0x0100)
  469. #define GIE                 (0x0008)
  470. #define CPUOFF              (0x0010)
  471. #define OSCOFF              (0x0020)
  472. #define SCG0                (0x0040)
  473. #define SCG1                (0x0080)

  474. /* Low Power Modes coded with Bits 4-7 in SR */

  475. #ifndef __IAR_SYSTEMS_ICC /* Begin #defines for assembler */
  476. #define LPM0                (CPUOFF)
  477. #define LPM1                (SCG0+CPUOFF)
  478. #define LPM2                (SCG1+CPUOFF)
  479. #define LPM3                (SCG1+SCG0+CPUOFF)
  480. #define LPM4                (SCG1+SCG0+OSCOFF+CPUOFF)
  481. /* End #defines for assembler */

  482. #else /* Begin #defines for C */
  483. #define LPM0_bits           (CPUOFF)
  484. #define LPM1_bits           (SCG0+CPUOFF)
  485. #define LPM2_bits           (SCG1+CPUOFF)
  486. #define LPM3_bits           (SCG1+SCG0+CPUOFF)
  487. #define LPM4_bits           (SCG1+SCG0+OSCOFF+CPUOFF)


  488. #define LPM0      _BIS_SR(LPM0_bits)     /* Enter Low Power Mode 0 */
  489. #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
  490. #define LPM1      _BIS_SR(LPM1_bits)     /* Enter Low Power Mode 1 */
  491. #define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
  492. #define LPM2      _BIS_SR(LPM2_bits)     /* Enter Low Power Mode 2 */
  493. #define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
  494. #define LPM3      _BIS_SR(LPM3_bits)     /* Enter Low Power Mode 3 */
  495. #define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
  496. #define LPM4      _BIS_SR(LPM4_bits)     /* Enter Low Power Mode 4 */
  497. #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
  498. #endif /* End #defines for C */

  499. /************************************************************
  500. * PERIPHERAL FILE MAP
  501. ************************************************************/

  502. /************************************************************
  503. * SPECIAL FUNCTION REGISTER ADDRESSES + CONTROL BITS
  504. ************************************************************/

  505. #define IE1_                (0x0000)  /* Interrupt Enable 1 */
  506. DEFC(    IE1               , IE1_)
  507. #define U0IE_               (IE1_)    /* UART0 Interrupt Enable Register */
  508. DEFC(   U0IE              , U0IE_)
  509. #define WDTIE               (0x01)
  510. #define OFIE                (0x02)
  511. #define NMIIE               (0x10)
  512. #define ACCVIE              (0x20)
  513. #define URXIE0              (0x40)
  514. #define UTXIE0              (0x80)

  515. #define IFG1_               (0x0002)  /* Interrupt Flag 1 */
  516. DEFC(    IFG1              , IFG1_)
  517. #define U0IFG_              (IFG1_)   /* UART0 Interrupt Flag Register */
  518. DEFC(   U0IFG             , U0IFG_)
  519. #define WDTIFG              (0x01)
  520. #define OFIFG               (0x02)
  521. #define NMIIFG              (0x10)
  522. #define URXIFG0             (0x40)
  523. #define UTXIFG0             (0x80)

  524. #define ME1_                (0x0004)  /* Module Enable 1 */
  525. DEFC(    ME1               , ME1_)
  526. #define U0ME_               (ME1_)    /* UART0 Module Enable Register */
  527. DEFC(   U0ME              , U0ME_)
  528. #define URXE0               (0x40)
  529. #define USPIE0              (0x40)
  530. #define UTXE0               (0x80)

  531. #define IE2_                (0x0001)  /* Interrupt Enable 2 */
  532. DEFC(    IE2               , IE2_)
  533. #define BTIE                (0x80)

  534. #define IFG2_               (0x0003)  /* Interrupt Flag 2 */
  535. DEFC(    IFG2              , IFG2_)
  536. #define BTIFG               (0x80)

  537. /************************************************************
  538. * WATCHDOG TIMER
  539. ************************************************************/

  540. #define WDTCTL_             (0x0120)  /* Watchdog Timer Control */
  541. DEFW(    WDTCTL            , WDTCTL_)
  542. /* The bit names have been prefixed with "WDT" */
  543. #define WDTIS0              (0x0001)
  544. #define WDTIS1              (0x0002)
  545. #define WDTSSEL             (0x0004)
  546. #define WDTCNTCL            (0x0008)
  547. #define WDTTMSEL            (0x0010)
  548. #define WDTNMI              (0x0020)
  549. #define WDTNMIES            (0x0040)
  550. #define WDTHOLD             (0x0080)

  551. #define WDTPW               (0x5A00)

  552. /* WDT-interval times [1ms] coded with Bits 0-2 */
  553. /* WDT is clocked by fMCLK (assumed 1MHz) */
  554. #define WDT_MDLY_32         (WDTPW+WDTTMSEL+WDTCNTCL)                         /* 32ms interval (default) */
  555. #define WDT_MDLY_8          (WDTPW+WDTTMSEL+WDTCNTCL+WDTIS0)                  /* 8ms     " */
  556. #define WDT_MDLY_0_5        (WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1)                  /* 0.5ms   " */
  557. #define WDT_MDLY_0_064      (WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1+WDTIS0)           /* 0.064ms " */
  558. /* WDT is clocked by fACLK (assumed 32KHz) */
  559. #define WDT_ADLY_1000       (WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL)                 /* 1000ms  " */
  560. #define WDT_ADLY_250        (WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS0)          /* 250ms   " */
  561. #define WDT_ADLY_16         (WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1)          /* 16ms    " */
  562. #define WDT_ADLY_1_9        (WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0)   /* 1.9ms   " */
  563. /* Watchdog mode -> reset after expired time */
  564. /* WDT is clocked by fMCLK (assumed 1MHz) */
  565. #define WDT_MRST_32         (WDTPW+WDTCNTCL)                                  /* 32ms interval (default) */
  566. #define WDT_MRST_8          (WDTPW+WDTCNTCL+WDTIS0)                           /* 8ms     " */
  567. #define WDT_MRST_0_5        (WDTPW+WDTCNTCL+WDTIS1)                           /* 0.5ms   " */
  568. #define WDT_MRST_0_064      (WDTPW+WDTCNTCL+WDTIS1+WDTIS0)                    /* 0.064ms " */
  569. /* WDT is clocked by fACLK (assumed 32KHz) */
  570. #define WDT_ARST_1000       (WDTPW+WDTCNTCL+WDTSSEL)                          /* 1000ms  " */
  571. #define WDT_ARST_250        (WDTPW+WDTCNTCL+WDTSSEL+WDTIS0)                   /* 250ms   " */
  572. #define WDT_ARST_16         (WDTPW+WDTCNTCL+WDTSSEL+WDTIS1)                   /* 16ms    " */
  573. #define WDT_ARST_1_9        (WDTPW+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0)            /* 1.9ms   " */

  574. /* INTERRUPT CONTROL */
  575. /* These two bits are defined in the Special Function Registers */
  576. /* #define WDTIE               0x01 */
  577. /* #define WDTIFG              0x01 */

  578. /************************************************************
  579. * DIGITAL I/O Port1/2
  580. ************************************************************/

  581. #define P1IN_               (0x0020)  /* Port 1 Input */
  582. READ_ONLY DEFC( P1IN           , P1IN_)
  583. #define P1OUT_              (0x0021)  /* Port 1 Output */
  584. DEFC(    P1OUT             , P1OUT_)
  585. #define P1DIR_              (0x0022)  /* Port 1 Direction */
  586. DEFC(    P1DIR             , P1DIR_)
  587. #define P1IFG_              (0x0023)  /* Port 1 Interrupt Flag */
  588. DEFC(    P1IFG             , P1IFG_)
  589. #define P1IES_              (0x0024)  /* Port 1 Interrupt Edge Select */
  590. DEFC(    P1IES             , P1IES_)
  591. #define P1IE_               (0x0025)  /* Port 1 Interrupt Enable */
  592. DEFC(    P1IE              , P1IE_)
  593. #define P1SEL_              (0x0026)  /* Port 1 Selection */
  594. DEFC(    P1SEL             , P1SEL_)

  595. #define P2IN_               (0x0028)  /* Port 2 Input */
  596. READ_ONLY DEFC( P2IN           , P2IN_)
  597. #define P2OUT_              (0x0029)  /* Port 2 Output */
  598. DEFC(    P2OUT             , P2OUT_)
  599. #define P2DIR_              (0x002A)  /* Port 2 Direction */
  600. DEFC(    P2DIR             , P2DIR_)
  601. #define P2IFG_              (0x002B)  /* Port 2 Interrupt Flag */
  602. DEFC(    P2IFG             , P2IFG_)
  603. #define P2IES_              (0x002C)  /* Port 2 Interrupt Edge Select */
  604. DEFC(    P2IES             , P2IES_)
  605. #define P2IE_               (0x002D)  /* Port 2 Interrupt Enable */
  606. DEFC(    P2IE              , P2IE_)
  607. #define P2SEL_              (0x002E)  /* Port 2 Selection */
  608. DEFC(    P2SEL             , P2SEL_)

  609. /************************************************************
  610. * DIGITAL I/O Port3/4
  611. ************************************************************/

  612. #define P3IN_               (0x0018)  /* Port 3 Input */
  613. READ_ONLY DEFC( P3IN           , P3IN_)
  614. #define P3OUT_              (0x0019)  /* Port 3 Output */
  615. DEFC(    P3OUT             , P3OUT_)
  616. #define P3DIR_              (0x001A)  /* Port 3 Direction */
  617. DEFC(    P3DIR             , P3DIR_)
  618. #define P3SEL_              (0x001B)  /* Port 3 Selection */
  619. DEFC(    P3SEL             , P3SEL_)

  620. #define P4IN_               (0x001C)  /* Port 4 Input */
  621. READ_ONLY DEFC( P4IN           , P4IN_)
  622. #define P4OUT_              (0x001D)  /* Port 4 Output */
  623. DEFC(    P4OUT             , P4OUT_)
  624. #define P4DIR_              (0x001E)  /* Port 4 Direction */
  625. DEFC(    P4DIR             , P4DIR_)
  626. #define P4SEL_              (0x001F)  /* Port 4 Selection */
  627. DEFC(    P4SEL             , P4SEL_)

  628. /************************************************************
  629. * DIGITAL I/O Port5/6
  630. ************************************************************/

  631. #define P5IN_               (0x0030)  /* Port 5 Input */
  632. READ_ONLY DEFC( P5IN           , P5IN_)
  633. #define P5OUT_              (0x0031)  /* Port 5 Output */
  634. DEFC(    P5OUT             , P5OUT_)
  635. #define P5DIR_              (0x0032)  /* Port 5 Direction */
  636. DEFC(    P5DIR             , P5DIR_)
  637. #define P5SEL_              (0x0033)  /* Port 5 Selection */
  638. DEFC(    P5SEL             , P5SEL_)

  639. #define P6IN_               (0x0034)  /* Port 6 Input */
  640. READ_ONLY DEFC( P6IN           , P6IN_)
  641. #define P6OUT_              (0x0035)  /* Port 6 Output */
  642. DEFC(    P6OUT             , P6OUT_)
  643. #define P6DIR_              (0x0036)  /* Port 6 Direction */
  644. DEFC(    P6DIR             , P6DIR_)
  645. #define P6SEL_              (0x0037)  /* Port 6 Selection */
  646. DEFC(    P6SEL             , P6SEL_)

  647. /************************************************************
  648. * BASIC TIMER
  649. ************************************************************/

  650. #define BTCTL_              (0x0040)  /* Basic Timer Control */
  651. DEFC(    BTCTL             , BTCTL_)
  652. /* The bit names have been prefixed with "BT" */
  653. #define BTIP0               (0x01)
  654. #define BTIP1               (0x02)
  655. #define BTIP2               (0x04)
  656. #define BTFRFQ0             (0x08)
  657. #define BTFRFQ1             (0x10)
  658. #define BTDIV               (0x20)                     /* fCLK2 , ACLK:256 */
  659. /*#define BTRESET             (0x40)*/                 /* incorrect :BT is reset and BTIFG is reset if this bit is set */
  660. #define BTHOLD              (0x40)                     /* BT1 is held if this bit is set */
  661. #define BTSSEL              (0x80)                     /* fBT , fMCLK (main clock) */

  662. #define BTCNT1_             (0x0046)  /* Basic Timer Count 1 */
  663. DEFC(    BTCNT1            , BTCNT1_)
  664. #define BTCNT2_             (0x0047)  /* Basic Timer Count 2 */
  665. DEFC(    BTCNT2            , BTCNT2_)

  666. /* Frequency of the BTCNT2 coded with Bit 5 and 7 in BTCTL */
  667. #define BT_fCLK2_ACLK               (0x00)
  668. #define BT_fCLK2_ACLK_DIV256        (BTDIV)
  669. #define BT_fCLK2_MCLK               (BTSSEL)

  670. /* Interrupt interval time fINT coded with Bits 0-2 in BTCTL */
  671. #define BT_fCLK2_DIV2       (0x00)                    /* fINT , fCLK2:2 (default) */
  672. #define BT_fCLK2_DIV4       (BTIP0)                   /* fINT , fCLK2:4 */
  673. #define BT_fCLK2_DIV8       (BTIP1)                   /* fINT , fCLK2:8 */
  674. #define BT_fCLK2_DIV16      (BTIP1+BTIP0)             /* fINT , fCLK2:16 */
  675. #define BT_fCLK2_DIV32      (BTIP2)                   /* fINT , fCLK2:32 */
  676. #define BT_fCLK2_DIV64      (BTIP2+BTIP0)             /* fINT , fCLK2:64 */
  677. #define BT_fCLK2_DIV128     (BTIP2+BTIP1)             /* fINT , fCLK2:128 */
  678. #define BT_fCLK2_DIV256     (BTIP2+BTIP1+BTIP0)       /* fINT , fCLK2:256 */
  679. /* Frequency of LCD coded with Bits 3-4 */
  680. #define BT_fLCD_DIV32       (0x00)                    /* fLCD , fACLK:32 (default) */
  681. #define BT_fLCD_DIV64       (BTFRFQ0)                 /* fLCD , fACLK:64 */
  682. #define BT_fLCD_DIV128      (BTFRFQ1)                 /* fLCD , fACLK:128 */
  683. #define BT_fLCD_DIV256      (BTFRFQ1+BTFRFQ0)         /* fLCD , fACLK:256 */
  684. /* LCD frequency values with fBT,fACLK */
  685. #define BT_fLCD_1K          (0x00)                    /* fACLK:32 (default) */
  686. #define BT_fLCD_512         (BTFRFQ0)                 /* fACLK:64 */
  687. #define BT_fLCD_256         (BTFRFQ1)                 /* fACLK:128 */
  688. #define BT_fLCD_128         (BTFRFQ1+BTFRFQ0)         /* fACLK:256 */
  689. /* LCD frequency values with fBT,fMCLK */
  690. #define BT_fLCD_31K         (BTSSEL)                  /* fMCLK:32 */
  691. #define BT_fLCD_15_5K       (BTSSEL+BTFRFQ0)          /* fMCLK:64 */
  692. #define BT_fLCD_7_8K        (BTSSEL+BTFRFQ1+BTFRFQ0)  /* fMCLK:256 */
  693. /* with assumed vlues of fACLK,32KHz, fMCLK,1MHz */
  694. /* fBT,fACLK is thought for longer interval times */
  695. #define BT_ADLY_0_064       (0x00)                    /* 0.064ms interval (default) */
  696. #define BT_ADLY_0_125       (BTIP0)                   /* 0.125ms    " */
  697. #define BT_ADLY_0_25        (BTIP1)                   /* 0.25ms     " */
  698. #define BT_ADLY_0_5         (BTIP1+BTIP0)             /* 0.5ms      " */
  699. #define BT_ADLY_1           (BTIP2)                   /* 1ms        " */
  700. #define BT_ADLY_2           (BTIP2+BTIP0)             /* 2ms        " */
  701. #define BT_ADLY_4           (BTIP2+BTIP1)             /* 4ms        " */
  702. #define BT_ADLY_8           (BTIP2+BTIP1+BTIP0)       /* 8ms        " */
  703. #define BT_ADLY_16          (BTDIV)                   /* 16ms       " */
  704. #define BT_ADLY_32          (BTDIV+BTIP0)             /* 32ms       " */
  705. #define BT_ADLY_64          (BTDIV+BTIP1)             /* 64ms       " */
  706. #define BT_ADLY_125         (BTDIV+BTIP1+BTIP0)       /* 125ms      " */
  707. #define BT_ADLY_250         (BTDIV+BTIP2)             /* 250ms      " */
  708. #define BT_ADLY_500         (BTDIV+BTIP2+BTIP0)       /* 500ms      " */
  709. #define BT_ADLY_1000        (BTDIV+BTIP2+BTIP1)       /* 1000ms     " */
  710. #define BT_ADLY_2000        (BTDIV+BTIP2+BTIP1+BTIP0) /* 2000ms     " */
  711. /* fCLK2,fMCLK (1MHz) is thought for short interval times */
  712. /* the timing for short intervals is more precise than ACLK */
  713. /* NOTE */
  714. /* Be sure that the SCFQCTL-Register is set to 01Fh so that fMCLK,1MHz */
  715. /* Too low interval time results in interrupts too frequent for the processor to handle! */
  716. #define BT_MDLY_0_002       (BTSSEL)                  /* 0.002ms interval       *** interval times */
  717. #define BT_MDLY_0_004       (BTSSEL+BTIP0)            /* 0.004ms    "           *** too short for */
  718. #define BT_MDLY_0_008       (BTSSEL+BTIP1)            /* 0.008ms    "           *** interrupt */
  719. #define BT_MDLY_0_016       (BTSSEL+BTIP1+BTIP0)      /* 0.016ms    "           *** handling */
  720. #define BT_MDLY_0_032       (BTSSEL+BTIP2)            /* 0.032ms    " */
  721. #define BT_MDLY_0_064       (BTSSEL+BTIP2+BTIP0)      /* 0.064ms    " */
  722. #define BT_MDLY_0_125       (BTSSEL+BTIP2+BTIP1)      /* 0.125ms    " */
  723. #define BT_MDLY_0_25        (BTSSEL+BTIP2+BTIP1+BTIP0)/* 0.25ms     " */

  724. /* Reset/Hold coded with Bits 6-7 in BT(1)CTL */
  725. /* this is for BT */
  726. #define BTRESET_CNT1        (BTRESET)           /* BTCNT1 is reset while BTRESET is set */
  727. #define BTRESET_CNT1_2      (BTRESET+BTDIV)     /* BTCNT1 .AND. BTCNT2 are reset while ~ is set */
  728. /* this is for BT1 */
  729. #define BTHOLD_CNT1         (BTHOLD)            /* BTCNT1 is held while BTHOLD is set */
  730. #define BTHOLD_CNT1_2       (BTHOLD+BTDIV)      /* BT1CNT1 .AND. BT1CNT2 are held while ~ is set */

  731. /* INTERRUPT CONTROL BITS */
  732. /* #define BTIE                0x80 */
  733. /* #define BTIFG               0x80 */

  734. /************************************************************
  735. * SYSTEM CLOCK, FLL+
  736. ************************************************************/

  737. #define SCFI0_              (0x0050)  /* System Clock Frequency Integrator 0 */
  738. DEFC(    SCFI0             , SCFI0_)
  739. #define FN_2                (0x04)    /* fDCOCLK ,   2*fNominal */
  740. #define FN_3                (0x08)    /* fDCOCLK ,   3*fNominal */
  741. #define FN_4                (0x10)    /* fDCOCLK , 4.5*fNominal */
  742. #define FN_8                (0x20)    /* fDCOCLK ,  10*fNominal */
  743. #define FLLD0               (0x40)    /* Loop Divider Bit : 0 */
  744. #define FLLD1               (0x80)    /* Loop Divider Bit : 1 */

  745. #define FLLD_1              (0x00)    /* Multiply Selected Loop Freq. By 1 */
  746. #define FLLD_2              (0x40)    /* Multiply Selected Loop Freq. By 2 */
  747. #define FLLD_4              (0x80)    /* Multiply Selected Loop Freq. By 4 */
  748. #define FLLD_8              (0xC0)    /* Multiply Selected Loop Freq. By 8 */

  749. #define SCFI1_              (0x0051)  /* System Clock Frequency Integrator 1 */
  750. DEFC(    SCFI1             , SCFI1_)
  751. #define SCFQCTL_            (0x0052)  /* System Clock Frequency Control */
  752. DEFC(    SCFQCTL           , SCFQCTL_)
  753. /* System clock frequency values fMCLK coded with Bits 0-6 in SCFQCTL */
  754. /* #define SCFQ_32K            0x00                        fMCLK,1*fACLK       only a range from */
  755. #define SCFQ_64K            (0x01)                     /* fMCLK,2*fACLK          1+1 to 127+1 is possible */
  756. #define SCFQ_128K           (0x03)                     /* fMCLK,4*fACLK */
  757. #define SCFQ_256K           (0x07)                     /* fMCLK,8*fACLK */
  758. #define SCFQ_512K           (0x0F)                     /* fMCLK,16*fACLK */
  759. #define SCFQ_1M             (0x1F)                     /* fMCLK,32*fACLK */
  760. #define SCFQ_2M             (0x3F)                     /* fMCLK,64*fACLK */
  761. #define SCFQ_4M             (0x7F)                     /* fMCLK,128*fACLK */
  762. #define SCFQ_M              (0x80)                     /* Modulation Disable */

  763. #define FLL_CTL0_           (0x0053)  /* FLL+ Control 0 */
  764. DEFC(    FLL_CTL0          , FLL_CTL0_)
  765. #define DCOF                (0x01)                     /* DCO Fault Flag */
  766. #define LFOF                (0x02)                     /* Low Frequency Oscillator Fault Flag */
  767. #define XT1OF               (0x04)                     /* High Frequency Oscillator 1 Fault Flag */
  768. #define XT2OF               (0x08)                     /* High Frequency Oscillator 2 Fault Flag */
  769. #define OSCCAP0             (0x10)                     /* XIN/XOUT Cap 0 */
  770. #define OSCCAP1             (0x20)                     /* XIN/XOUT Cap 1 */
  771. #define XTS_FLL             (0x40)                     /* 1: Selects high-freq. oscillator */
  772. #define DCOPLUS             (0x80)                     /* DCO+ Enable */

  773. #define XCAP0PF             (0x00)                     /* XIN Cap = XOUT Cap = 0pf */
  774. #define XCAP10PF            (0x10)                     /* XIN Cap = XOUT Cap = 10pf */
  775. #define XCAP14PF            (0x20)                     /* XIN Cap = XOUT Cap = 14pf */
  776. #define XCAP18PF            (0x30)                     /* XIN Cap = XOUT Cap = 18pf */

  777. #define FLL_CTL1_           (0x0054)  /* FLL+ Control 1 */
  778. DEFC(    FLL_CTL1          , FLL_CTL1_)
  779. #define FLL_DIV0            (0x00)                     /* FLL+ Divide Px.x/ACLK 0 */
  780. #define FLL_DIV1            (0x01)                     /* FLL+ Divide Px.x/ACLK 1 */
  781. #define SELS                (0x04)                     /* Peripheral Module Clock Source (0: DCO, 1: XT2) */
  782. #define SELM0               (0x08)                     /* MCLK Source Select 0 */
  783. #define SELM1               (0x10)                     /* MCLK Source Select 1 */
  784. #define XT2OFF              (0x20)                     /* High Frequency Oscillator 2 (XT2) disable */

  785. #define FLL_DIV_1           (0x00)                     /* FLL+ Divide Px.x/ACLK By 1 */
  786. #define FLL_DIV_2           (0x01)                     /* FLL+ Divide Px.x/ACLK By 2 */
  787. #define FLL_DIV_4           (0x02)                     /* FLL+ Divide Px.x/ACLK By 4 */
  788. #define FLL_DIV_8           (0x03)                     /* FLL+ Divide Px.x/ACLK By 8 */

  789. #define SELM_DCO            (0x00)                     /* Select DCO for CPU MCLK */
  790. #define SELM_XT2            (0x10)                     /* Select XT2 for CPU MCLK */
  791. #define SELM_A              (0x18)                     /* Select A (from LFXT1) for CPU MCLK */
  792. #define SMCLKOFF            (0x40)                     /* Peripheral Module Clock (SMCLK) disable */

  793. /* INTERRUPT CONTROL BITS */
  794. /* These two bits are defined in the Special Function Registers */
  795. /* #define OFIFG               0x02 */
  796. /* #define OFIE                0x02 */

  797. /************************************************************
  798. * Brown-Out, Supply Voltage Supervision (SVS)
  799. ************************************************************/

  800. #define SVSCTL_             (0x0056)  /* SVS Control */
  801. DEFC(    SVSCTL            , SVSCTL_)
  802. #define SVSFG               (0x01)
  803. #define SVSOP               (0x02)
  804. #define SVSON               (0x04)
  805. #define PORON               (0x08)
  806. #define VLDOFF              (0x00)
  807. #define VLDON               (0x10)
  808. #define VLD_1_8V            (0x10)

  809. /************************************************************
  810. * LCD
  811. ************************************************************/

  812. #define LCDCTL_             (0x0090)  /* LCD Control */
  813. DEFC(    LCDCTL            , LCDCTL_)
  814. /* the names of the mode bits are different from the spec */
  815. #define LCDON               (0x01)
  816. #define LCDLOWR             (0x02)
  817. #define LCDSON              (0x04)
  818. #define LCDMX0              (0x08)
  819. #define LCDMX1              (0x10)
  820. #define LCDP0               (0x20)
  821. #define LCDP1               (0x40)
  822. #define LCDP2               (0x80)
  823. /* Display modes coded with Bits 2-4 */
  824. #define LCDSTATIC           (LCDSON)
  825. #define LCD2MUX             (LCDMX0+LCDSON)
  826. #define LCD3MUX             (LCDMX1+LCDSON)
  827. #define LCD4MUX             (LCDMX1+LCDMX0+LCDSON)
  828. /* Group select code with Bits 5-7                     Seg.lines   Dig.output */
  829. #define LCDSG0              (0x00)                    /* ---------   Port Only (default) */
  830. #define LCDSG0_1            (LCDP0)                   /* S0  - S15   see Datasheet */
  831. #define LCDSG0_2            (LCDP1)                   /* S0  - S19   see Datasheet */
  832. #define LCDSG0_3            (LCDP1+LCDP0)             /* S0  - S23   see Datasheet */
  833. #define LCDSG0_4            (LCDP2)                   /* S0  - S27   see Datasheet */
  834. #define LCDSG0_5            (LCDP2+LCDP0)             /* S0  - S31   see Datasheet */
  835. #define LCDSG0_6            (LCDP2+LCDP1)             /* S0  - S35   see Datasheet */
  836. #define LCDSG0_7            (LCDP2+LCDP1+LCDP0)       /* S0  - S39   see Datasheet */
  837. /* NOTE: YOU CAN ONLY USE THE 'S' OR 'G' DECLARATIONS FOR A COMMAND */
  838. /* MOV  #LCDSG0_3+LCDOG2_7,&LCDCTL ACTUALY MEANS MOV  #LCDP1,&LCDCTL! */
  839. #define LCDOG1_7            (0x00)                    /* ---------   Port Only (default) */
  840. #define LCDOG2_7            (LCDP0)                   /* S0  - S15   see Datasheet */
  841. #define LCDOG3_7            (LCDP1)                   /* S0  - S19   see Datasheet */
  842. #define LCDOG4_7            (LCDP1+LCDP0)             /* S0  - S23   see Datasheet */
  843. #define LCDOG5_7            (LCDP2)                   /* S0  - S27   see Datasheet */
  844. #define LCDOG6_7            (LCDP2+LCDP0)             /* S0  - S31   see Datasheet */
  845. #define LCDOG7              (LCDP2+LCDP1)             /* S0  - S35   see Datasheet */
  846. #define LCDOGOFF            (LCDP2+LCDP1+LCDP0)       /* S0  - S39   see Datasheet */

  847. #define LCDMEM_             (0x0091)  /* LCD Memory */
  848. #ifndef __IAR_SYSTEMS_ICC
  849. #define LCDMEM              (LCDMEM_) /* LCD Memory (for assembler) */
  850. #else
  851. #define LCDMEM              ((char*) LCDMEM_) /* LCD Memory (for C) */
  852. #endif
  853. #define LCDM1_              (LCDMEM_) /* LCD Memory 1 */
  854. DEFC(    LCDM1             , LCDM1_)
  855. #define LCDM2_              (0x0092)  /* LCD Memory 2 */
  856. DEFC(    LCDM2             , LCDM2_)
  857. #define LCDM3_              (0x0093)  /* LCD Memory 3 */
  858. DEFC(    LCDM3             , LCDM3_)
  859. #define LCDM4_              (0x0094)  /* LCD Memory 4 */
  860. DEFC(    LCDM4             , LCDM4_)
  861. #define LCDM5_              (0x0095)  /* LCD Memory 5 */
  862. DEFC(    LCDM5             , LCDM5_)
  863. #define LCDM6_              (0x0096)  /* LCD Memory 6 */
  864. DEFC(    LCDM6             , LCDM6_)
  865. #define LCDM7_              (0x0097)  /* LCD Memory 7 */
  866. DEFC(    LCDM7             , LCDM7_)
  867. #define LCDM8_              (0x0098)  /* LCD Memory 8 */
  868. DEFC(    LCDM8             , LCDM8_)
  869. #define LCDM9_              (0x0099)  /* LCD Memory 9 */
  870. DEFC(    LCDM9             , LCDM9_)
  871. #define LCDM10_             (0x009A)  /* LCD Memory 10 */
  872. DEFC(    LCDM10            , LCDM10_)
  873. #define LCDM11_             (0x009B)  /* LCD Memory 11 */
  874. DEFC(    LCDM11            , LCDM11_)
  875. #define LCDM12_             (0x009C)  /* LCD Memory 12 */
  876. DEFC(    LCDM12            , LCDM12_)
  877. #define LCDM13_             (0x009D)  /* LCD Memory 13 */
  878. DEFC(    LCDM13            , LCDM13_)
  879. #define LCDM14_             (0x009E)  /* LCD Memory 14 */
  880. DEFC(    LCDM14            , LCDM14_)
  881. #define LCDM15_             (0x009F)  /* LCD Memory 15 */
  882. DEFC(    LCDM15            , LCDM15_)
  883. #define LCDM16_             (0x00A0)  /* LCD Memory 16 */
  884. DEFC(    LCDM16            , LCDM16_)
  885. #define LCDM17_             (0x00A1)  /* LCD Memory 17 */
  886. DEFC(    LCDM17            , LCDM17_)
  887. #define LCDM18_             (0x00A2)  /* LCD Memory 18 */
  888. DEFC(    LCDM18            , LCDM18_)
  889. #define LCDM19_             (0x00A3)  /* LCD Memory 19 */
  890. DEFC(    LCDM19            , LCDM19_)
  891. #define LCDM20_             (0x00A4)  /* LCD Memory 20 */
  892. DEFC(    LCDM20            , LCDM20_)

  893. #define LCDMA_              (LCDM10_) /* LCD Memory A */
  894. DEFC(    LCDMA             , LCDMA_)
  895. #define LCDMB_              (LCDM11_) /* LCD Memory B */
  896. DEFC(    LCDMB             , LCDMB_)
  897. #define LCDMC_              (LCDM12_) /* LCD Memory C */
  898. DEFC(    LCDMC             , LCDMC_)
  899. #define LCDMD_              (LCDM13_) /* LCD Memory D */
  900. DEFC(    LCDMD             , LCDMD_)
  901. #define LCDME_              (LCDM14_) /* LCD Memory E */
  902. DEFC(    LCDME             , LCDME_)
  903. #define LCDMF_              (LCDM15_) /* LCD Memory F */
  904. DEFC(    LCDMF             , LCDMF_)

  905. /************************************************************
  906. * USART
  907. ************************************************************/

  908. #define PENA                (0x80)        /* UCTL */
  909. #define PEV                 (0x40)
  910. #define SPB                 (0x20)        /* to distinguish from stackpointer SP */
  911. #define CHAR                (0x10)
  912. #define LISTEN              (0x08)
  913. #define SYNC                (0x04)
  914. #define MM                  (0x02)
  915. #define SWRST               (0x01)

  916. #define CKPH                (0x80)        /* UTCTL */
  917. #define CKPL                (0x40)
  918. #define SSEL1               (0x20)
  919. #define SSEL0               (0x10)
  920. #define URXSE               (0x08)
  921. #define TXWAKE              (0x04)
  922. #define STC                 (0x02)
  923. #define TXEPT               (0x01)

  924. #define FE                  (0x80)        /* URCTL */
  925. #define PE                  (0x40)
  926. #define OE                  (0x20)
  927. #define BRK                 (0x10)
  928. #define URXEIE              (0x08)
  929. #define URXWIE              (0x04)
  930. #define RXWAKE              (0x02)
  931. #define RXERR               (0x01)

  932. /************************************************************
  933. * USART 0
  934. ************************************************************/

  935. #define U0CTL_              (0x0070)  /* USART 0 Control */
  936. DEFC(    U0CTL             , U0CTL_)
  937. #define U0TCTL_             (0x0071)  /* USART 0 Transmit Control */
  938. DEFC(    U0TCTL            , U0TCTL_)
  939. #define U0RCTL_             (0x0072)  /* USART 0 Receive Control */
  940. DEFC(    U0RCTL            , U0RCTL_)
  941. #define U0MCTL_             (0x0073)  /* USART 0 Modulation Control */
  942. DEFC(    U0MCTL            , U0MCTL_)
  943. #define U0BR0_              (0x0074)  /* USART 0 Baud Rate 0 */
  944. DEFC(    U0BR0             , U0BR0_)
  945. #define U0BR1_              (0x0075)  /* USART 0 Baud Rate 1 */
  946. DEFC(    U0BR1             , U0BR1_)
  947. #define U0RXBUF_            (0x0076)  /* USART 0 Receive Buffer */
  948. READ_ONLY DEFC( U0RXBUF        , U0RXBUF_)
  949. #define U0TXBUF_            (0x0077)  /* USART 0 Transmit Buffer */
  950. DEFC(    U0TXBUF           , U0TXBUF_)

  951. /* Alternate register names */

  952. #define UCTL0_              U0CTL_    /* USART 0 Control */
  953. DEFC(    UCTL0             , UCTL0_)
  954. #define UTCTL0_             U0TCTL_   /* USART 0 Transmit Control */
  955. DEFC(    UTCTL0            , UTCTL0_)
  956. #define URCTL0_             U0RCTL_   /* USART 0 Receive Control */
  957. DEFC(    URCTL0            , URCTL0_)
  958. #define UMCTL0_             U0MCTL_   /* USART 0 Modulation Control */
  959. DEFC(    UMCTL0            , UMCTL0_)
  960. #define UBR00_              U0BR0_    /* USART 0 Baud Rate 0 */
  961. DEFC(    UBR00             , UBR00_)
  962. #define UBR10_              U0BR1_    /* USART 0 Baud Rate 1 */
  963. DEFC(    UBR10             , UBR10_)
  964. #define RXBUF0_             U0RXBUF_  /* USART 0 Receive Buffer */
  965. READ_ONLY DEFC( RXBUF0         , RXBUF0_)
  966. #define TXBUF0_             U0TXBUF_  /* USART 0 Transmit Buffer */
  967. DEFC(    TXBUF0            , TXBUF0_)

  968. #define UCTL_0_             U0CTL_    /* USART 0 Control */
  969. DEFC(    UCTL_0            , UCTL_0_)
  970. #define UTCTL_0_            U0TCTL_   /* USART 0 Transmit Control */
  971. DEFC(    UTCTL_0           , UTCTL_0_)
  972. #define URCTL_0_            U0RCTL_   /* USART 0 Receive Control */
  973. DEFC(    URCTL_0           , URCTL_0_)
  974. #define UMCTL_0_            U0MCTL_   /* USART 0 Modulation Control */
  975. DEFC(    UMCTL_0           , UMCTL_0_)
  976. #define UBR0_0_             U0BR0_    /* USART 0 Baud Rate 0 */
  977. DEFC(    UBR0_0            , UBR0_0_)
  978. #define UBR1_0_             U0BR1_    /* USART 0 Baud Rate 1 */
  979. DEFC(    UBR1_0            , UBR1_0_)
  980. #define RXBUF_0_            U0RXBUF_  /* USART 0 Receive Buffer */
  981. READ_ONLY DEFC( RXBUF_0        , RXBUF_0_)
  982. #define TXBUF_0_            U0TXBUF_  /* USART 0 Transmit Buffer */
  983. DEFC(    TXBUF_0           , TXBUF_0_)

  984. /************************************************************
  985. * Timer A
  986. ************************************************************/

  987. #define TAIV_               (0x012E)  /* Timer A Interrupt Vector Word */
  988. READ_ONLY DEFW( TAIV           , TAIV_)
  989. #define TACTL_              (0x0160)  /* Timer A Control */
  990. DEFW(    TACTL             , TACTL_)
  991. #define TACCTL0_            (0x0162)  /* Timer A Capture/Compare Control 0 */
  992. DEFW(    TACCTL0           , TACCTL0_)
  993. #define TACCTL1_            (0x0164)  /* Timer A Capture/Compare Control 1 */
  994. DEFW(    TACCTL1           , TACCTL1_)
  995. #define TACCTL2_            (0x0166)  /* Timer A Capture/Compare Control 2 */
  996. DEFW(    TACCTL2           , TACCTL2_)
  997. #define TAR_                (0x0170)  /* Timer A */
  998. DEFW(    TAR               , TAR_)
  999. #define TACCR0_             (0x0172)  /* Timer A Capture/Compare 0 */
  1000. DEFW(    TACCR0            , TACCR0_)
  1001. #define TACCR1_             (0x0174)  /* Timer A Capture/Compare 1 */
  1002. DEFW(    TACCR1            , TACCR1_)
  1003. #define TACCR2_             (0x0176)  /* Timer A Capture/Compare 2 */
  1004. DEFW(    TACCR2            , TACCR2_)

  1005. /* Alternate register names */
  1006. #define CCTL0_              TACCTL0_    /* Timer A Capture/Compare Control 0 */
  1007. DEFW(    CCTL0 , CCTL0_)
  1008. #define CCTL1_              TACCTL1_    /* Timer A Capture/Compare Control 1 */
  1009. DEFW(    CCTL1 , CCTL1_)
  1010. #define CCTL2_              TACCTL2_    /* Timer A Capture/Compare Control 2 */
  1011. DEFW(    CCTL2 , CCTL2_)
  1012. #define CCR0_               TACCR0_     /* Timer A Capture/Compare 0 */
  1013. DEFW(    CCR0 , CCR0_)
  1014. #define CCR1_               TACCR1_     /* Timer A Capture/Compare 1 */
  1015. DEFW(    CCR1 , CCR1_)
  1016. #define CCR2_               TACCR2_     /* Timer A Capture/Compare 2 */
  1017. DEFW(    CCR2 , CCR2_)

  1018. #define TASSEL2             (0x0400)  /* unused */        /* to distinguish from USART SSELx */
  1019. #define TASSEL1             (0x0200)  /* Timer A clock source select 0 */
  1020. #define TASSEL0             (0x0100)  /* Timer A clock source select 1 */
  1021. #define ID1                 (0x0080)  /* Timer A clock input devider 1 */
  1022. #define ID0                 (0x0040)  /* Timer A clock input devider 0 */
  1023. #define MC1                 (0x0020)  /* Timer A mode control 1 */
  1024. #define MC0                 (0x0010)  /* Timer A mode control 0 */
  1025. #define TACLR               (0x0004)  /* Timer A counter clear */
  1026. #define TAIE                (0x0002)  /* Timer A counter interrupt enable */
  1027. #define TAIFG               (0x0001)  /* Timer A counter interrupt flag */

  1028. #define MC_0                (0*0x10)  /* Timer A mode control: 0 - Stop */
  1029. #define MC_1                (1*0x10)  /* Timer A mode control: 1 - Up to CCR0 */
  1030. #define MC_2                (2*0x10)  /* Timer A mode control: 2 - Continous up */
  1031. #define MC_3                (3*0x10)  /* Timer A mode control: 3 - Up/Down */
  1032. #define ID_0                (0*0x40)  /* Timer A input divider: 0 - /1 */
  1033. #define ID_1                (1*0x40)  /* Timer A input divider: 1 - /2 */
  1034. #define ID_2                (2*0x40)  /* Timer A input divider: 2 - /4 */
  1035. #define ID_3                (3*0x40)  /* Timer A input divider: 3 - /8 */
  1036. #define TASSEL_0            (0*0x100) /* Timer A clock source select: 0 - TACLK */
  1037. #define TASSEL_1            (1*0x100) /* Timer A clock source select: 1 - ACLK  */
  1038. #define TASSEL_2            (2*0x100) /* Timer A clock source select: 2 - SMCLK */
  1039. #define TASSEL_3            (3*0x100) /* Timer A clock source select: 3 - INCLK */

  1040. #define CM1                 (0x8000)  /* Capture mode 1 */
  1041. #define CM0                 (0x4000)  /* Capture mode 0 */
  1042. #define CCIS1               (0x2000)  /* Capture input select 1 */
  1043. #define CCIS0               (0x1000)  /* Capture input select 0 */
  1044. #define SCS                 (0x0800)  /* Capture sychronize */
  1045. #define SCCI                (0x0400)  /* Latched capture signal (read) */
  1046. #define CAP                 (0x0100)  /* Capture mode: 1 /Compare mode : 0 */
  1047. #define OUTMOD2             (0x0080)  /* Output mode 2 */
  1048. #define OUTMOD1             (0x0040)  /* Output mode 1 */
  1049. #define OUTMOD0             (0x0020)  /* Output mode 0 */
  1050. #define CCIE                (0x0010)  /* Capture/compare interrupt enable */
  1051. #define CCI                 (0x0008)  /* Capture input signal (read) */
  1052. #define OUT                 (0x0004)  /* PWM Output signal if output mode 0 */
  1053. #define COV                 (0x0002)  /* Capture/compare overflow flag */
  1054. #define CCIFG               (0x0001)  /* Capture/compare interrupt flag */

  1055. #define OUTMOD_0            (0*0x20)  /* PWM output mode: 0 - output only */
  1056. #define OUTMOD_1            (1*0x20)  /* PWM output mode: 1 - set */
  1057. #define OUTMOD_2            (2*0x20)  /* PWM output mode: 2 - PWM toggle/reset */
  1058. #define OUTMOD_3            (3*0x20)  /* PWM output mode: 3 - PWM set/reset */
  1059. #define OUTMOD_4            (4*0x20)  /* PWM output mode: 4 - toggle */
  1060. #define OUTMOD_5            (5*0x20)  /* PWM output mode: 5 - Reset */
  1061. #define OUTMOD_6            (6*0x20)  /* PWM output mode: 6 - PWM toggle/set */
  1062. #define OUTMOD_7            (7*0x20)  /* PWM output mode: 7 - PWM reset/set */
  1063. #define CCIS_0              (0*0x1000) /* Capture input select: 0 - CCIxA */
  1064. #define CCIS_1              (1*0x1000) /* Capture input select: 1 - CCIxB */
  1065. #define CCIS_2              (2*0x1000) /* Capture input select: 2 - GND */
  1066. #define CCIS_3              (3*0x1000) /* Capture input select: 3 - Vcc */
  1067. #define CM_0                (0*0x4000u) /* Capture mode: 0 - disabled */
  1068. #define CM_1                (1*0x4000u) /* Capture mode: 1 - pos. edge */
  1069. #define CM_2                (2*0x4000u) /* Capture mode: 1 - neg. edge */
  1070. #define CM_3                (3*0x4000u) /* Capture mode: 1 - both edges */

  1071. /************************************************************
  1072. * Timer B
  1073. ************************************************************/

  1074. #define TBIV_               (0x011E)  /* Timer B Interrupt Vector Word */
  1075. READ_ONLY DEFW( TBIV           , TBIV_)
  1076. #define TBCTL_              (0x0180)  /* Timer B Control */
  1077. DEFW(    TBCTL             , TBCTL_)
  1078. #define TBCCTL0_            (0x0182)  /* Timer B Capture/Compare Control 0 */
  1079. DEFW(    TBCCTL0           , TBCCTL0_)
  1080. #define TBCCTL1_            (0x0184)  /* Timer B Capture/Compare Control 1 */
  1081. DEFW(    TBCCTL1           , TBCCTL1_)
  1082. #define TBCCTL2_            (0x0186)  /* Timer B Capture/Compare Control 2 */
  1083. DEFW(    TBCCTL2           , TBCCTL2_)
  1084. #define TBR_                (0x0190)  /* Timer B */
  1085. DEFW(    TBR               , TBR_)
  1086. #define TBCCR0_             (0x0192)  /* Timer B Capture/Compare 0 */
  1087. DEFW(    TBCCR0            , TBCCR0_)
  1088. #define TBCCR1_             (0x0194)  /* Timer B Capture/Compare 1 */
  1089. DEFW(    TBCCR1            , TBCCR1_)
  1090. #define TBCCR2_             (0x0196)  /* Timer B Capture/Compare 2 */
  1091. DEFW(    TBCCR2            , TBCCR2_)

  1092. #define SHR1                (0x4000)  /* Timer B Compare latch load group 1 */
  1093. #define SHR0                (0x2000)  /* Timer B Compare latch load group 0 */
  1094. #define TBCLGRP1            (0x4000)  /* Timer B Compare latch load group 1 */
  1095. #define TBCLGRP0            (0x2000)  /* Timer B Compare latch load group 0 */
  1096. #define CNTL1               (0x1000)  /* Counter lenght 1 */
  1097. #define CNTL0               (0x0800)  /* Counter lenght 0 */
  1098. #define TBSSEL2             (0x0400)  /* unused */
  1099. #define TBSSEL1             (0x0200)  /* Clock source 1 */
  1100. #define TBSSEL0             (0x0100)  /* Clock source 0 */
  1101. #define TBCLR               (0x0004)  /* Timer B counter clear */
  1102. #define TBIE                (0x0002)  /* Timer B interrupt enable */
  1103. #define TBIFG               (0x0001)  /* Timer B interrupt flag */

  1104. #define TBSSEL_0            (0*0x0100)  /* Clock Source: TBCLK */
  1105. #define TBSSEL_1            (1*0x0100)  /* Clock Source: ACLK  */
  1106. #define TBSSEL_2            (2*0x0100)  /* Clock Source: SMCLK */
  1107. #define TBSSEL_3            (3*0x0100)  /* Clock Source: INCLK */
  1108. #define CNTL_0              (0*0x0800)  /* Counter lenght: 16 bit */
  1109. #define CNTL_1              (1*0x0800)  /* Counter lenght: 12 bit */
  1110. #define CNTL_2              (2*0x0800)  /* Counter lenght: 10 bit */
  1111. #define CNTL_3              (3*0x0800)  /* Counter lenght:  8 bit */
  1112. #define SHR_0               (0*0x2000)  /* Timer B Group: 0 - individually */
  1113. #define SHR_1               (1*0x2000)  /* Timer B Group: 1 - 3 groups (1-2, 3-4, 5-6) */
  1114. #define SHR_2               (2*0x2000)  /* Timer B Group: 2 - 2 groups (1-3, 4-6)*/
  1115. #define SHR_3               (3*0x2000)  /* Timer B Group: 3 - 1 group (all) */
  1116. #define TBCLGRP_0           (0*0x2000)  /* Timer B Group: 0 - individually */
  1117. #define TBCLGRP_1           (1*0x2000)  /* Timer B Group: 1 - 3 groups (1-2, 3-4, 5-6) */
  1118. #define TBCLGRP_2           (2*0x2000)  /* Timer B Group: 2 - 2 groups (1-3, 4-6)*/
  1119. #define TBCLGRP_3           (3*0x2000)  /* Timer B Group: 3 - 1 group (all) */

  1120. /* Additional Timer B Control Register bits are defined in Timer A */

  1121. #define SLSHR1              (0x0400)  /* Compare latch load source 1 */
  1122. #define SLSHR0              (0x0200)  /* Compare latch load source 0 */
  1123. #define CLLD1               (0x0400)  /* Compare latch load source 1 */
  1124. #define CLLD0               (0x0200)  /* Compare latch load source 0 */

  1125. #define SLSHR_0             (0*0x0200)  /* Compare latch load sourec : 0 - immediate */
  1126. #define SLSHR_1             (1*0x0200)  /* Compare latch load sourec : 1 - TBR counts to 0 */
  1127. #define SLSHR_2             (2*0x0200)  /* Compare latch load sourec : 2 - up/down */
  1128. #define SLSHR_3             (3*0x0200)  /* Compare latch load sourec : 3 - TBR counts to TBCTL0 */

  1129. #define CLLD_0              (0*0x0200)  /* Compare latch load sourec : 0 - immediate */
  1130. #define CLLD_1              (1*0x0200)  /* Compare latch load sourec : 1 - TBR counts to 0 */
  1131. #define CLLD_2              (2*0x0200)  /* Compare latch load sourec : 2 - up/down */
  1132. #define CLLD_3              (3*0x0200)  /* Compare latch load sourec : 3 - TBR counts to TBCTL0 */

  1133. /*************************************************************
  1134. * Flash Memory
  1135. *************************************************************/

  1136. #define FCTL1_              (0x0128)  /* FLASH Control 1 */
  1137. DEFW(    FCTL1             , FCTL1_)
  1138. #define FCTL2_              (0x012A)  /* FLASH Control 2 */
  1139. DEFW(    FCTL2             , FCTL2_)
  1140. #define FCTL3_              (0x012C)  /* FLASH Control 3 */
  1141. DEFW(    FCTL3             , FCTL3_)

  1142. #define FRKEY               (0x9600)  /* Flash key returned by read */
  1143. #define FWKEY               (0xA500)  /* Flash key for write */
  1144. #define FXKEY               (0x3300)  /* for use with XOR instruction */

  1145. #define ERASE               (0x0002)  /* Enable bit for Flash segment erase */
  1146. #define MERAS               (0x0004)  /* Enable bit for Flash mass erase */
  1147. #define WRT                 (0x0040)  /* Enable bit for Flash write */
  1148. #define BLKWRT              (0x0080)  /* Enable bit for Flash segment write */
  1149. #define SEGWRT              (0x0080)  /* old definition */ /* Enable bit for Flash segment write */

  1150. #define FN0                 (0x0001)  /* Devide Flash clock by 1 to 64 using FN0 to FN5 according to: */
  1151. #define FN1                 (0x0002)  /*  32*FN5 + 16*FN4 + 8*FN3 + 4*FN2 + 2*FN1 + FN0 + 1 */
  1152. #define FN2                 (0x0004)
  1153. #define FN3                 (0x0008)
  1154. #define FN4                 (0x0010)
  1155. #define FN5                 (0x0020)
  1156. #define FSSEL0              (0x0040)  /* Flash clock select 0 */        /* to distinguish from USART SSELx */
  1157. #define FSSEL1              (0x0080)  /* Flash clock select 1 */

  1158. #define FSSEL_0             (0x0000)  /* Flash clock select: 0 - ACLK */
  1159. #define FSSEL_1             (0x0040)  /* Flash clock select: 1 - MCLK */
  1160. #define FSSEL_2             (0x0080)  /* Flash clock select: 2 - SMCLK */
  1161. #define FSSEL_3             (0x00C0)  /* Flash clock select: 3 - SMCLK */

  1162. #define BUSY                (0x0001)  /* Flash busy: 1 */
  1163. #define KEYV                (0x0002)  /* Flash Key violation flag */
  1164. #define ACCVIFG             (0x0004)  /* Flash Access violation flag */
  1165. #define WAIT                (0x0008)  /* Wait flag for segment write */
  1166. #define LOCK                (0x0010)  /* Lock bit: 1 - Flash is locked (read only) */
  1167. #define EMEX                (0x0020)  /* Flash Emergency Exit */

  1168. /************************************************************
  1169. * Comparator A
  1170. ************************************************************/

  1171. #define CACTL1_             (0x0059)  /* Comparator A Control 1 */
  1172. DEFC(    CACTL1            , CACTL1_)
  1173. #define CACTL2_             (0x005A)  /* Comparator A Control 2 */
  1174. DEFC(    CACTL2            , CACTL2_)
  1175. #define CAPD_               (0x005B)  /* Comparator A Port Disable */
  1176. DEFC(    CAPD              , CAPD_)

  1177. #define CAIFG               (0x01)    /* Comp. A Interrupt Flag */
  1178. #define CAIE                (0x02)    /* Comp. A Interrupt Enable */
  1179. #define CAIES               (0x04)    /* Comp. A Int. Edge Select: 0:rising / 1:falling */
  1180. #define CAON                (0x08)    /* Comp. A enable */
  1181. #define CAREF0              (0x10)    /* Comp. A Internal Reference Select 0 */
  1182. #define CAREF1              (0x20)    /* Comp. A Internal Reference Select 1 */
  1183. #define CARSEL              (0x40)    /* Comp. A Internal Reference Enable */
  1184. #define CAEX                (0x80)    /* Comp. A Exchange Inputs */

  1185. #define CAREF_0             (0x00)    /* Comp. A Int. Ref. Select 0 : Off */
  1186. #define CAREF_1             (0x10)    /* Comp. A Int. Ref. Select 1 : 0.25*Vcc */
  1187. #define CAREF_2             (0x20)    /* Comp. A Int. Ref. Select 2 : 0.5*Vcc */
  1188. #define CAREF_3             (0x30)    /* Comp. A Int. Ref. Select 3 : Vt*/

  1189. #define CAOUT               (0x01)    /* Comp. A Output */
  1190. #define CAF                 (0x02)    /* Comp. A Enable Output Filter */
  1191. #define P2CA0               (0x04)    /* Comp. A Connect External Signal to CA0 : 1 */
  1192. #define P2CA1               (0x08)    /* Comp. A Connect External Signal to CA1 : 1 */
  1193. #define CACTL24             (0x10)
  1194. #define CACTL25             (0x20)
  1195. #define CACTL26             (0x40)
  1196. #define CACTL27             (0x80)

  1197. #define CAPD0               (0x01)    /* Comp. A Disable Input Buffer of Port Register .0 */
  1198. #define CAPD1               (0x02)    /* Comp. A Disable Input Buffer of Port Register .1 */
  1199. #define CAPD2               (0x04)    /* Comp. A Disable Input Buffer of Port Register .2 */
  1200. #define CAPD3               (0x08)    /* Comp. A Disable Input Buffer of Port Register .3 */
  1201. #define CAPD4               (0x10)    /* Comp. A Disable Input Buffer of Port Register .4 */
  1202. #define CAPD5               (0x20)    /* Comp. A Disable Input Buffer of Port Register .5 */
  1203. #define CAPD6               (0x40)    /* Comp. A Disable Input Buffer of Port Register .6 */
  1204. #define CAPD7               (0x80)    /* Comp. A Disable Input Buffer of Port Register .7 */

  1205. /************************************************************
  1206. * ADC12
  1207. ************************************************************/

  1208. #define ADC12CTL0_          (0x01A0)  /* ADC12 Control 0 */
  1209. DEFW(    ADC12CTL0         , ADC12CTL0_)
  1210. #define ADC12CTL1_          (0x01A2)  /* ADC12 Control 1 */
  1211. DEFW(    ADC12CTL1         , ADC12CTL1_)
  1212. #define ADC12IFG_           (0x01A4)  /* ADC12 Interrupt Flag */
  1213. DEFW(    ADC12IFG          , ADC12IFG_)
  1214. #define ADC12IE_            (0x01A6)  /* ADC12 Interrupt Enable */
  1215. DEFW(    ADC12IE           , ADC12IE_)
  1216. #define ADC12IV_            (0x01A8)  /* ADC12 Interrupt Vector Word */
  1217. DEFW(    ADC12IV           , ADC12IV_)

  1218. #define ADC12MEM_           (0x0140)  /* ADC12 Conversion Memory */
  1219. #ifndef __IAR_SYSTEMS_ICC
  1220. #define ADC12MEM            (ADC12MEM_) /* ADC12 Conversion Memory (for assembler) */
  1221. #else
  1222. #define ADC12MEM            ((int*) ADC12MEM_) /* ADC12 Conversion Memory (for C) */
  1223. #endif
  1224. #define ADC12MEM0_          (ADC12MEM_) /* ADC12 Conversion Memory 0 */
  1225. DEFW(    ADC12MEM0         , ADC12MEM0_)
  1226. #define ADC12MEM1_          (0x0142)  /* ADC12 Conversion Memory 1 */
  1227. DEFW(    ADC12MEM1         , ADC12MEM1_)
  1228. #define ADC12MEM2_          (0x0144)  /* ADC12 Conversion Memory 2 */
  1229. DEFW(    ADC12MEM2         , ADC12MEM2_)
  1230. #define ADC12MEM3_          (0x0146)  /* ADC12 Conversion Memory 3 */
  1231. DEFW(    ADC12MEM3         , ADC12MEM3_)
  1232. #define ADC12MEM4_          (0x0148)  /* ADC12 Conversion Memory 4 */
  1233. DEFW(    ADC12MEM4         , ADC12MEM4_)
  1234. #define ADC12MEM5_          (0x014A)  /* ADC12 Conversion Memory 5 */
  1235. DEFW(    ADC12MEM5         , ADC12MEM5_)
  1236. #define ADC12MEM6_          (0x014C)  /* ADC12 Conversion Memory 6 */
  1237. DEFW(    ADC12MEM6         , ADC12MEM6_)
  1238. #define ADC12MEM7_          (0x014E)  /* ADC12 Conversion Memory 7 */
  1239. DEFW(    ADC12MEM7         , ADC12MEM7_)
  1240. #define ADC12MEM8_          (0x0150)  /* ADC12 Conversion Memory 8 */
  1241. DEFW(    ADC12MEM8         , ADC12MEM8_)
  1242. #define ADC12MEM9_          (0x0152)  /* ADC12 Conversion Memory 9 */
  1243. DEFW(    ADC12MEM9         , ADC12MEM9_)
  1244. #define ADC12MEM10_         (0x0154)  /* ADC12 Conversion Memory 10 */
  1245. DEFW(    ADC12MEM10        , ADC12MEM10_)
  1246. #define ADC12MEM11_         (0x0156)  /* ADC12 Conversion Memory 11 */
  1247. DEFW(    ADC12MEM11        , ADC12MEM11_)
  1248. #define ADC12MEM12_         (0x0158)  /* ADC12 Conversion Memory 12 */
  1249. DEFW(    ADC12MEM12        , ADC12MEM12_)
  1250. #define ADC12MEM13_         (0x015A)  /* ADC12 Conversion Memory 13 */
  1251. DEFW(    ADC12MEM13        , ADC12MEM13_)
  1252. #define ADC12MEM14_         (0x015C)  /* ADC12 Conversion Memory 14 */
  1253. DEFW(    ADC12MEM14        , ADC12MEM14_)
  1254. #define ADC12MEM15_         (0x015E)  /* ADC12 Conversion Memory 15 */
  1255. DEFW(    ADC12MEM15        , ADC12MEM15_)

  1256. #define ADC12MCTL_          (0x0080)  /* ADC12 Memory Control */
  1257. #ifndef __IAR_SYSTEMS_ICC
  1258. #define ADC12MCTL           (ADC12MCTL_) /* ADC12 Memory Control (for assembler) */
  1259. #else
  1260. #define ADC12MCTL           ((char*) ADC12MCTL_) /* ADC12 Memory Control (for C) */
  1261. #endif
  1262. #define ADC12MCTL0_         (ADC12MCTL_) /* ADC12 Memory Control 0 */
  1263. DEFC(    ADC12MCTL0        , ADC12MCTL0_)
  1264. #define ADC12MCTL1_         (0x0081)  /* ADC12 Memory Control 1 */
  1265. DEFC(    ADC12MCTL1        , ADC12MCTL1_)
  1266. #define ADC12MCTL2_         (0x0082)  /* ADC12 Memory Control 2 */
  1267. DEFC(    ADC12MCTL2        , ADC12MCTL2_)
  1268. #define ADC12MCTL3_         (0x0083)  /* ADC12 Memory Control 3 */
  1269. DEFC(    ADC12MCTL3        , ADC12MCTL3_)
  1270. #define ADC12MCTL4_         (0x0084)  /* ADC12 Memory Control 4 */
  1271. DEFC(    ADC12MCTL4        , ADC12MCTL4_)
  1272. #define ADC12MCTL5_         (0x0085)  /* ADC12 Memory Control 5 */
  1273. DEFC(    ADC12MCTL5        , ADC12MCTL5_)
  1274. #define ADC12MCTL6_         (0x0086)  /* ADC12 Memory Control 6 */
  1275. DEFC(    ADC12MCTL6        , ADC12MCTL6_)
  1276. #define ADC12MCTL7_         (0x0087)  /* ADC12 Memory Control 7 */
  1277. DEFC(    ADC12MCTL7        , ADC12MCTL7_)
  1278. #define ADC12MCTL8_         (0x0088)  /* ADC12 Memory Control 8 */
  1279. DEFC(    ADC12MCTL8        , ADC12MCTL8_)
  1280. #define ADC12MCTL9_         (0x0089)  /* ADC12 Memory Control 9 */
  1281. DEFC(    ADC12MCTL9        , ADC12MCTL9_)
  1282. #define ADC12MCTL10_        (0x008A)  /* ADC12 Memory Control 10 */
  1283. DEFC(    ADC12MCTL10       , ADC12MCTL10_)
  1284. #define ADC12MCTL11_        (0x008B)  /* ADC12 Memory Control 11 */
  1285. DEFC(    ADC12MCTL11       , ADC12MCTL11_)
  1286. #define ADC12MCTL12_        (0x008C)  /* ADC12 Memory Control 12 */
  1287. DEFC(    ADC12MCTL12       , ADC12MCTL12_)
  1288. #define ADC12MCTL13_        (0x008D)  /* ADC12 Memory Control 13 */
  1289. DEFC(    ADC12MCTL13       , ADC12MCTL13_)
  1290. #define ADC12MCTL14_        (0x008E)  /* ADC12 Memory Control 14 */
  1291. DEFC(    ADC12MCTL14       , ADC12MCTL14_)
  1292. #define ADC12MCTL15_        (0x008F)  /* ADC12 Memory Control 15 */
  1293. DEFC(    ADC12MCTL15       , ADC12MCTL15_)

  1294. #define ADC12SC             (0x001) /* ADC12CTL0 */
  1295. #define ENC                 (0x002)
  1296. #define ADC12TOVIE          (0x004)
  1297. #define ADC12OVIE           (0x008)
  1298. #define ADC12ON             (0x010)
  1299. #define REFON               (0x020)
  1300. #define REF2_5V             (0x040)
  1301. #define MSH                 (0x080)
  1302. #define MSC                 (0x080)

  1303. #define SHT0_0               (0*0x100)
  1304. #define SHT0_1               (1*0x100)
  1305. #define SHT0_2               (2*0x100)
  1306. #define SHT0_3               (3*0x100)
  1307. #define SHT0_4               (4*0x100)
  1308. #define SHT0_5               (5*0x100)
  1309. #define SHT0_6               (6*0x100)
  1310. #define SHT0_7               (7*0x100)
  1311. #define SHT0_8               (8*0x100)
  1312. #define SHT0_9               (9*0x100)
  1313. #define SHT0_10             (10*0x100)
  1314. #define SHT0_11             (11*0x100)
  1315. #define SHT0_12             (12*0x100)
  1316. #define SHT0_13             (13*0x100)
  1317. #define SHT0_14             (14*0x100)
  1318. #define SHT0_15             (15*0x100)

  1319. #define SHT1_0               (0*0x1000)
  1320. #define SHT1_1               (1*0x1000)
  1321. #define SHT1_2               (2*0x1000)
  1322. #define SHT1_3               (3*0x1000)
  1323. #define SHT1_4               (4*0x1000)
  1324. #define SHT1_5               (5*0x1000)
  1325. #define SHT1_6               (6*0x1000)
  1326. #define SHT1_7               (7*0x1000)
  1327. #define SHT1_8               (8*0x1000)
  1328. #define SHT1_9               (9*0x1000)
  1329. #define SHT1_10             (10*0x1000)
  1330. #define SHT1_11             (11*0x1000)
  1331. #define SHT1_12             (12*0x1000)
  1332. #define SHT1_13             (13*0x1000)
  1333. #define SHT1_14             (14*0x1000)
  1334. #define SHT1_15             (15*0x1000)

  1335. #define ADC12BUSY           (0x0001) /* ADC12CTL1 */
  1336. #define CONSEQ_0             (0*2)
  1337. #define CONSEQ_1             (1*2)
  1338. #define CONSEQ_2             (2*2)
  1339. #define CONSEQ_3             (3*2)
  1340. #define ADC12SSEL_0          (0*8)
  1341. #define ADC12SSEL_1          (1*8)
  1342. #define ADC12SSEL_2          (2*8)
  1343. #define ADC12SSEL_3          (3*8)
  1344. #define ADC12DIV_0           (0*0x20)
  1345. #define ADC12DIV_1           (1*0x20)
  1346. #define ADC12DIV_2           (2*0x20)
  1347. #define ADC12DIV_3           (3*0x20)
  1348. #define ADC12DIV_4           (4*0x20)
  1349. #define ADC12DIV_5           (5*0x20)
  1350. #define ADC12DIV_6           (6*0x20)
  1351. #define ADC12DIV_7           (7*0x20)
  1352. #define ISSH                (0x0100)
  1353. #define SHP                 (0x0200)
  1354. #define SHS_0                (0*0x400)
  1355. #define SHS_1                (1*0x400)
  1356. #define SHS_2                (2*0x400)
  1357. #define SHS_3                (3*0x400)

  1358. #define CSTARTADD_0          (0*0x1000)
  1359. #define CSTARTADD_1          (1*0x1000)
  1360. #define CSTARTADD_2          (2*0x1000)
  1361. #define CSTARTADD_3          (3*0x1000)
  1362. #define CSTARTADD_4          (4*0x1000)
  1363. #define CSTARTADD_5          (5*0x1000)
  1364. #define CSTARTADD_6          (6*0x1000)
  1365. #define CSTARTADD_7          (7*0x1000)
  1366. #define CSTARTADD_8          (8*0x1000)
  1367. #define CSTARTADD_9          (9*0x1000)
  1368. #define CSTARTADD_10        (10*0x1000)
  1369. #define CSTARTADD_11        (11*0x1000)
  1370. #define CSTARTADD_12        (12*0x1000)
  1371. #define CSTARTADD_13        (13*0x1000)
  1372. #define CSTARTADD_14        (14*0x1000)
  1373. #define CSTARTADD_15        (15*0x1000)

  1374. #define INCH_0               (0) /* ADC12MCTLx */
  1375. #define INCH_1               (1)
  1376. #define INCH_2               (2)
  1377. #define INCH_3               (3)
  1378. #define INCH_4               (4)
  1379. #define INCH_5               (5)
  1380. #define INCH_6               (6)
  1381. #define INCH_7               (7)
  1382. #define INCH_8               (8)
  1383. #define INCH_9               (9)
  1384. #define INCH_10             (10)
  1385. #define INCH_11             (11)
  1386. #define INCH_12             (12)
  1387. #define INCH_13             (13)
  1388. #define INCH_14             (14)
  1389. #define INCH_15             (15)

  1390. #define SREF_0               (0*0x10)
  1391. #define SREF_1               (1*0x10)
  1392. #define SREF_2               (2*0x10)
  1393. #define SREF_3               (3*0x10)
  1394. #define SREF_4               (4*0x10)
  1395. #define SREF_5               (5*0x10)
  1396. #define SREF_6               (6*0x10)
  1397. #define SREF_7               (7*0x10)
  1398. #define EOS                 (0x80)

  1399. /************************************************************
  1400. * Interrupt Vectors (offset from 0xFFE0)
  1401. ************************************************************/

  1402. #define BASICTIMER_VECTOR   (0 * 2)  /* 0xFFE0 Basic Timer */
  1403. #define PORT2_VECTOR        (1 * 2)  /* 0xFFE2 Port 2 */
  1404. #define PORT1_VECTOR        (4 * 2)  /* 0xFFE8 Port 1 */
  1405. #define TIMERA1_VECTOR      (5 * 2)  /* 0xFFEA Timer A CC1-2, TA */
  1406. #define TIMERA0_VECTOR      (6 * 2)  /* 0xFFEC Timer A CC0 */
  1407. #define ADC_VECTOR          (7 * 2)  /* 0xFFEE ADC */
  1408. #define USART0TX_VECTOR     (8 * 2)  /* 0xFFF0 USART 0 Transmit */
  1409. #define USART0RX_VECTOR     (9 * 2)  /* 0xFFF2 USART 0 Receive */
  1410. #define WDT_VECTOR          (10 * 2) /* 0xFFF4 Watchdog Timer */
  1411. #define COMPARATORA_VECTOR  (11 * 2) /* 0xFFF6 Comparator A */
  1412. #define TIMERB1_VECTOR      (12 * 2) /* 0xFFF8 Timer B 1-2 */
  1413. #define TIMERB0_VECTOR      (13 * 2) /* 0xFFFA Timer B 0 */
  1414. #define NMI_VECTOR          (14 * 2) /* 0xFFFC Non-maskable */
  1415. #define RESET_VECTOR        (15 * 2) /* 0xFFFE Reset [Highest Priority] */

  1416. #define UART0TX_VECTOR      USART0TX_VECTOR
  1417. #define UART0RX_VECTOR      USART0RX_VECTOR

  1418. /************************************************************
  1419. * End of Module
  1420. ************************************************************/

  1421. #pragma language=default

  1422. #endif /* #ifndef __msp430x43x */

复制代码


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表