/* Timer A ,Timer B 可公用 捕获/比较控制寄存器X */
#define CM1 0x8000 /* 捕获模式选择位1 */
#define CM0 0x4000 /* 捕获模式选择位0 */
#define CCIS1 0x2000 /* 捕获输入信号源选择位1 */
#define CCIS0 0x1000 /* 捕获输入信号源选择位0 */
#define SCS 0x0800 /* 信号同步位 0:异步捕获;1:同步捕获 */
#define SCCI 0x0400 /* 锁存输入信号 */
#define CAP 0x0100 /* 模式选择: 0:比较模式;1:捕获模式 */
#define OUTMOD2 0x0080 /* 输出模式选择位2 */
#define OUTMOD1 0x0040 /* 输出模式选择位1 */
#define OUTMOD0 0x0020 /* 输出模式选择位0 */
#define CCIE 0x0010 /* 中断允许位 */
#define CCI 0x0008 /* 读出输入信号源位ccis0\1 */
#define OUT 0x0004 /* 输出信号(选择输出模式0) */
#define COV 0x0002 /* 捕获溢出标志 */
#define CCIFG 0x0001 /* 中断标志 */
#define OUTMOD_0 0*0x20 /* 输出模式 */
#define OUTMOD_1 1*0x20 /* 置位模式 */
#define OUTMOD_2 2*0x20 /* 翻转/复位模式 */
#define OUTMOD_3 3*0x20 /* 置位/复位模式 */
#define OUTMOD_4 4*0x20 /* 翻转模式 */
#define OUTMOD_5 5*0x20 /* 复位模式 */
#define OUTMOD_6 6*0x20 /* 翻转/置位模式 */
#define OUTMOD_7 7*0x20 /* 复位/置位模式*/
#define CCIS_0 0*0x1000 /* 选择CCIXA为捕获事件的输入信号源 */
#define CCIS_1 1*0x1000 /* 选择CCIXB为捕获事件的输入信号源 */
#define CCIS_2 2*0x1000 /* 选择GND为捕获事件的输入信号源 */
#define CCIS_3 3*0x1000 /* 选择VCC为捕获事件的输入信号源 */
#define CM_0 0*0x4000 /* 禁止捕获模式 */
#define CM_1 1*0x4000 /* 上升延捕获模式 */
#define CM_2 2*0x4000 /* 下降沿捕获模式 */
#define CM_3 3*0x4000 /* 上升沿和下降沿都捕获模式 */
/************************************************************
* Timer B 定时器B寄存器定义
************************************************************/
#define TBIV_ 0x011E /* 中断向量寄存器:BIT1-BIT3有效 */
sfrw TBIV = TBIV_;
#define TBCTL_ 0x0180 /* 定时器B控制寄存器:全部控制都集中在这 */
sfrw TBCTL = TBCTL_;
#define TBCCTL0_ 0x0182 /* 定时器B捕获/比较控制寄存器0*/
sfrw TBCCTL0 = TBCCTL0_;
#define TBCCTL1_ 0x0184 /* 定时器B捕获/比较控制寄存器1 */
sfrw TBCCTL1 = TBCCTL1_;
#define TBCCTL2_ 0x0186 /* 定时器B捕获/比较控制寄存器2 */
sfrw TBCCTL2 = TBCCTL2_;
#define TBCCTL3_ 0x0188 /* 定时器B捕获/比较控制寄存器3 */
sfrw TBCCTL3 = TBCCTL3_;
#define TBCCTL4_ 0x018A /* 定时器B捕获/比较控制寄存器4 */
sfrw TBCCTL4 = TBCCTL4_;
#define TBCCTL5_ 0x018C /* 定时器B捕获/比较控制寄存器5 */
sfrw TBCCTL5 = TBCCTL5_;
#define TBCCTL6_ 0x018E /* 定时器B捕获/比较控制寄存器6 */
sfrw TBCCTL6 = TBCCTL6_;
#define TBR_ 0x0190 /* 计数器 */
sfrw TBR = TBR_;
#define TBCCR0_ 0x0192 /* 定时器B捕获/比较寄存器0 */
sfrw TBCCR0 = TBCCR0_;
#define TBCCR1_ 0x0194 /* 定时器B捕获/比较寄存器1 */
sfrw TBCCR1 = TBCCR1_;
#define TBCCR2_ 0x0196 /* 定时器B捕获/比较寄存器2 */
sfrw TBCCR2 = TBCCR2_;
#define TBCCR3_ 0x0198 /* 定时器B捕获/比较寄存器3 */
sfrw TBCCR3 = TBCCR3_;
#define TBCCR4_ 0x019A /* 定时器B捕获/比较寄存器4 */
sfrw TBCCR4 = TBCCR4_;
#define TBCCR5_ 0x019C /* 定时器B捕获/比较寄存器5 */
sfrw TBCCR5 = TBCCR5_;
#define TBCCR6_ 0x019E /* 定时器B捕获/比较寄存器6 */
sfrw TBCCR6 = TBCCR6_;
/* 定时器B控制寄存器:全部控制都集中在这 */
#define SHR1 0x4000 /* 装载比较锁存器控制位1 :受TBCCTLx中的CCLDx位控制 */
#define SHR0 0x2000 /* 装载比较锁存器控制位0 :受TBCCTLx中的CCLDx位控制*/
#define TBCLGRP1 0x4000 /* 装载比较锁存器控制位1 :受TBCCTLx中的CCLDx位控制*/
#define TBCLGRP0 0x2000 /* 装载比较锁存器控制位0 :受TBCCTLx中的CCLDx位控制*/
#define CNTL1 0x1000 /* 定时器位数长度控制位1 */
#define CNTL0 0x0800 /* 定时器位数长度控制位0 */
#define TBSSEL2 0x0400 /* 未用 */
#define TBSSEL1 0x0200 /* 时钟输入源控制位1 */
#define TBSSEL0 0x0100 /* 时钟输入源控制位0 */
#define TBCLR 0x0004 /* 置1清除定时器 */
#define TBIE 0x0002 /* 中断允许 */
#define TBIFG 0x0001 /* 中断标志 */
#define TBSSEL_0 0*0x0100 /* 时钟源为:TBCLK */
#define TBSSEL_1 1*0x0100 /* 时钟源为: ACLK */
#define TBSSEL_2 2*0x0100 /* 时钟源为:SMCLK */
#define TBSSEL_3 3*0x0100 /* 时钟源为:INCLK */
#define CNTL_0 0*0x0800 /* 16 位计数模式*/
#define CNTL_1 1*0x0800 /* 12 位计数模式*/
#define CNTL_2 2*0x0800 /* 10 位计数模式 */
#define CNTL_3 3*0x0800 /* 8 位计数模式 */
#define SHR_0 0*0x2000 /* 单独装载(初始值) */
#define SHR_1 1*0x2000 /* 分三组装载: 1 - 3 groups (1-2, 3-4, 5-6) */
#define SHR_2 2*0x2000 /* 分二组装载: 2 - 2 groups (1-3, 4-6)*/
#define SHR_3 3*0x2000 /* 不分组装载: 3 - 1 group (all) */
#define TBCLGRP_0 0*0x2000 /* 单独装载(初始值) */
#define TBCLGRP_1 1*0x2000 /* 分三组装载: 1 - 3 groups (1-2, 3-4, 5-6) */
#define TBCLGRP_2 2*0x2000 /* 分二组装载: 2 - 2 groups (1-3, 4-6)*/
#define TBCLGRP_3 3*0x2000 /* 不分组装载: 3 - 1 group (all) */
/* Additional Timer B Control Register bits are defined in Timer A */
#define SLSHR1 0x0400 /* Compare latch load source 1 */
#define SLSHR0 0x0200 /* Compare latch load source 0 */
#define CLLD1 0x0400 /* 定义比较锁存器TBCLx的装载方式控制位1 */
#define CLLD0 0x0200 /* 定义比较锁存器TBCLx的装载方式控制位0 */
#define SLSHR_0 0*0x0200 /* 立即装载 */
#define SLSHR_1 1*0x0200 /* TBR 计数到0时装载 */
#define SLSHR_2 2*0x0200 /* 在增减模式下,计数到TBCLx或0时装载; 在连续计数模式下,计数到0时装载 */
#define SLSHR_3 3*0x0200 /* 当计数到TBCL0时装载*/
#define CLLD_0 0*0x0200 /* 立即装载 */
#define CLLD_1 1*0x0200 /* TBR 计数到0时装载 */
#define CLLD_2 2*0x0200 /* 在增减模式下,计数到TBCLx或0时装载; 在连续计数模式下,计数到0时装载 */
#define CLLD_3 3*0x0200 /* 当计数到TBCL0时装载 */
/************************************************************
* Basic Clock Module
************************************************************/
#define DCOCTL_ 0x0056 /* DCO 时钟频率控制寄存器 :复位后的值位060h*/
sfrb DCOCTL = DCOCTL_;
#define BCSCTL1_ 0x0057 /* 系统时钟控制寄存器1 :复位后的值位084h*/
sfrb BCSCTL1 = BCSCTL1_;
#define BCSCTL2_ 0x0058 /* 系统时钟控制寄存器2 :复位后的值位000h*/
sfrb BCSCTL2 = BCSCTL2_;
/* DCO 时钟频率控制寄存器 */
#define MOD0 0x01 /* DCO插入周期控制位0 */
#define MOD1 0x02 /* DCO插入周期控制位1 */
#define MOD2 0x04 /* DCO插入周期控制位2 */
#define MOD3 0x08 /* DCO插入周期控制位3 */
#define MOD4 0x10 /* DCO插入周期控制位4 */
#define DCO0 0x20 /* 8种频率控制位0 */
#define DCO1 0x40 /* 8种频率控制位1 */
#define DCO2 0x80 /* 8种频率控制位2 */
/* 系统时钟控制寄存器1 :复位后的值位084h*/
#define RSEL0 0x01 /* 选择内部电阻控制位0 */
#define RSEL1 0x02 /* 选择内部电阻控制位1 */
#define RSEL2 0x04 /* 选择内部电阻控制位2 */
#define XT5V 0x08 /* 必须为0*/
#define DIVA0 0x10 /* ACLK分频系数控制位0*/
#define DIVA1 0x20 /* ACLK分频系数控制位1 */
#define XTS 0x40 /* LFXT1工作模式控制位 0:低频模式. / 1: 高频模式. */
#define XT2OFF 0x80 /* XT2CLK 使能控制位 0:开启; 1:关闭 */
#define DIVA_0 0x00 /* ACLK分频系数为: 1 */
#define DIVA_1 0x10 /* ACLK分频系数为: 2 */
#define DIVA_2 0x20 /* ACLK分频系数为: 4 */
#define DIVA_3 0x30 /* ACLK分频系数为: 8 */
/* 系统时钟控制寄存器2 :复位后的值位000h*/
#define DCOR 0x01 /* 内外电阻选择控制位 */
#define DIVS0 0x02 /* SMCLK分频控制位0*/
#define DIVS1 0x04 /* SMCLK分频控制位1 */
#define SELS 0x08 /* SMCLK 时钟源选择位t 0:DCOCLK / 1:XT2CLK/LFXTCLK */
#define DIVM0 0x10 /* MCLK分频控制位0 */
#define DIVM1 0x20 /* MCLK分频控制位1 */
#define SELM0 0x40 /* MCLK 时钟输入源选择位0 */
#define SELM1 0x80 /* MCLK 时钟输入源选择位1 */
#define DIVS_0 0x00 /* SMCLK 分频系数为: 1 */
#define DIVS_1 0x02 /* SMCLK 分频系数为: 2 */
#define DIVS_2 0x04 /* SMCLK 分频系数为: 4 */
#define DIVS_3 0x06 /* SMCLK 分频系数为: 8 */
#define DIVM_0 0x00 /* MCLK 分频系数为: 1 */
#define DIVM_1 0x10 /* MCLK 分频系数为: 2 */
#define DIVM_2 0x20 /* MCLK 分频系数为: 4 */
#define DIVM_3 0x30 /* MCLK 分频系数为: 8 */
#define SELM_0 0x00 /* MCLK 时钟输入源: DCOCLK */
#define SELM_1 0x40 /* MCLK 时钟输入源: DCOCLK */
#define SELM_2 0x80 /* MCLK 时钟输入源: XT2CLK/LFXTCLK */
#define SELM_3 0xC0 /* MCLK 时钟输入源: LFXTCLK */
/*************************************************************
* Flash Memory FLASH操作寄存器定义
*************************************************************/
#define FCTL1_ 0x0128 /* FLASH控制寄存器1:控制编程、擦除 */
sfrw FCTL1 = FCTL1_;
#define FCTL2_ 0x012A /* FLASH 控制寄存器2 :控制时钟分频*/
sfrw FCTL2 = FCTL2_;
#define FCTL3_ 0x012C /* FLASH 控制寄存器3: 状态标志 */
sfrw FCTL3 = FCTL3_;
#define FRKEY 0x9600 /* 读FLASH 密码 */
#define FWKEY 0xA500 /* 写FLASH 密码 */
#define FXKEY 0x3300 /* for use with XOR instruction */
/* FLASH控制寄存器1:控制编程、擦除 */
#define ERASE 0x0002 /* 擦除段使能 */
#define MERAS 0x0004 /* 主存擦除使能 */
#define WRT 0x0040 /* 编程使能 */
#define BLKWRT 0x0080 /* 段编程使能 */
/* FLASH 控制寄存器2 :控制时钟分频*/
#define FN_0 0x0000 /*直通 */
#define FN_1 0x0001 /*2分频 */
#define FN_2 0x0002 /*3分频*/
#define FN_3 0x0003 /*4分频 */
#define FN_4 0x0004 /*5分频 */
#define FN_5 0x0005 /*6分频*/
#define FN_6 0x0006 /*7分频 */
#define FN_7 0x0007 /*8分频*/
#define FN_8 0x0008 /*9分频 */
#define FN_9 0x0009 /*10分频 */
#define FN_10 0x000A /*11分频*/
#define FN_11 0x000B /*12分频 */
#define FN_12 0x000C /*13分频*/
#define FN_13 0x000D /*14分频 */
#define FN_14 0x000E /*15分频 */
#define FN_15 0x000F /*16分频*/
#define FN_16 0x0010 /*17分频 */
#define FN_17 0x0011 /*18分频*/
#define FN_18 0x0012 /*19分频 */
#define FN_19 0x0013 /*20分频 */
#define FN_20 0x0014 /*21分频*/
#define FN_21 0x0015 /*22分频 */
#define FN_22 0x0016 /*23分频*/
#define FN_23 0x0017 /*24分频 */
#define FN_24 0x0018 /*25分频 */
#define FN_25 0x0019 /*26分频*/
#define FN_26 0x001A /*27分频 */
#define FN_27 0x001B /*28分频*/
#define FN_28 0x001C /*29分频 */
#define FN_29 0x001D /*30分频 */
#define FN_30 0x001E /*31分频*/
#define FN_31 0x001F /*32分频 */
#define FN_32 0x0020 /*33分频*/
#define FN_33 0x0021 /*34分频 */
#define FN_34 0x0022 /*35分频 */
#define FN_35 0x0023 /*36分频*/
#define FN_36 0x0024 /*37分频 */
#define FN_37 0x0025 /*38分频*/
#define FN_38 0x0026 /*39分频 */
#define FN_39 0x0027 /*40分频 */
#define FN_40 0x0028 /*41分频*/
#define FN_41 0x0029 /*42分频 */
#define FN_42 0x002A /*43分频*/
#define FN_43 0x002B /*44分频 */
#define FN_44 0x002C /*45分频 */
#define FN_45 0x002D /*46分频*/
#define FN_46 0x002E /*47分频 */
#define FN_47 0x002F /*48分频*/
#define FN_48 0x0030 /*49分频 */
#define FN_49 0x0031 /*50分频 */
#define FN_50 0x0032 /*51分频*/
#define FN_51 0x0033 /*52分频 */
#define FN_52 0x0034 /*53分频*/
#define FN_53 0x0035 /*54分频 */
#define FN_54 0x0036 /*55分频 */
#define FN_55 0x0037 /*56分频*/
#define FN_56 0x0038 /*57分频 */
#define FN_57 0x0039 /*58分频*/
#define FN_58 0x003A /*59分频 */
#define FN_59 0x003B /*60分频 */
#define FN_60 0x003C /*61分频*/
#define FN_61 0x003D /*62分频 */
#define FN_62 0x003E /*63分频*/
#define FN_63 0x003F /*64分频 */
#define FSSEL_0 0x0000 /* Flash时钟选择: ACLK */
#define FSSEL_1 0x0040 /* Flash时钟选择: MCLK */
#define FSSEL_2 0x0080 /* Flash时钟选择: SMCLK */
#define FSSEL_3 0x00C0 /* Flash时钟选择: SMCLK */
/* FLASH 控制寄存器3: 状态标志 */
#define BUSY 0x0001 /* Flash忙标志*/
#define KEYV 0x0002 /* Flash安全键值出错标志 */
#define ACCVIFG 0x0004 /* Flash非法访问中断标志*/
#define WAIT 0x0008 /* 等待指示信号位*/
#define LOCK 0x0010 /* 锁定位 */
#define EMEX 0x0020 /* 紧急退出位 */
/************************************************************
* Comparator A 比较器A寄存器定义
************************************************************/
#define CACTL1_ 0x0059 /* 比较器A控制寄存器1 */
sfrb CACTL1 = CACTL1_;
#define CACTL2_ 0x005A /* 比较器A控制寄存器2 */
sfrb CACTL2 = CACTL2_;
#define CAPD_ 0x005B /*比较器A端口禁止寄存器*/
sfrb CAPD = CAPD_;
/* 比较器A控制寄存器1 */
#define CAIFG 0x01 /*比较器A中断标志*/
#define CAIE 0x02 /* 比较器A中断使能 */
#define CAIES 0x04 /* 比较器A中断边沿触发选择 0:上升延 1:下降延 */
#define CAON 0x08 /* 比较器电源开关*/
#define CAREF0 0x10 /* 选择参考源位0 */
#define CAREF1 0x20 /* 选择参考源位1 */
#define CARSEL 0x40 /* 选择内部参考源加到比较器的正端或负端 */
#define CAEX 0x80 /* 交换比较器的输入端 */
#define CAREF_0 0x00 /* 选择参考源0 : Off 使用外部参考源*/
#define CAREF_1 0x10 /* 选择参考源1 : 0.25*Vcc为参考源 */
#define CAREF_2 0x20 /* 选择参考源2 : 0.5*Vcc为参考源 */
#define CAREF_3 0x30 /* 选择参考源3 : Vt*/
/* 比较器A控制寄存器2 */
#define CAOUT 0x01 /* 比较器输出 */
#define CAF 0x02 /* 选择比较器是否经过RC低通滤波器 */
#define P2CA0 0x04 /* 外部引脚信号连接到比较器A的CA0 */
#define P2CA1 0x08 /* 外部引脚信号连接到比较器A的CA1 */
#define CACTL24 0x10
#define CACTL25 0x20
#define CACTL26 0x40
#define CACTL27 0x80
#define CAPD0 0x01 /* Comp. A Disable Input Buffer of Port Register .0 */
#define CAPD1 0x02 /* Comp. A Disable Input Buffer of Port Register .1 */
#define CAPD2 0x04 /* Comp. A Disable Input Buffer of Port Register .2 */
#define CAPD3 0x08 /* Comp. A Disable Input Buffer of Port Register .3 */
#define CAPD4 0x10 /* Comp. A Disable Input Buffer of Port Register .4 */
#define CAPD5 0x20 /* Comp. A Disable Input Buffer of Port Register .5 */
#define CAPD6 0x40 /* Comp. A Disable Input Buffer of Port Register .6 */
#define CAPD7 0x80 /* Comp. A Disable Input Buffer of Port Register .7 */
文章评论(0条评论)
登录后参与讨论