MSP430G2553_官方例程(加注释版)

合集下载

ADXL-MSP430G2553

ADXL-MSP430G2553

#ifndef ADXL_G2553_H_#define ADXL_G2553_H_#define WORD unsigned short#define uchar unsigned char#define uint unsigned int/*#define SCL_1 P1OUT|=BIT5 //IIC时钟引脚定义#define SCL_0 P1OUT&=~BIT5#define SCL_OUT P1DIR|=BIT5#define SDA P1IN&BIT4#define SDA_1 P1OUT|=BIT4 //IIC数据引脚定义#define SDA_0 P1OUT&=~BIT4#define SDA_IN P1DIR&=~BIT4#define SDA_OUT P1DIR|=BIT4*/#define SCL_1 P1OUT|=BIT0 //IIC时钟引脚定义#define SCL_0 P1OUT&=~BIT0#define SCL_OUT P1DIR|=BIT0#define SDA P1IN&BIT1#define SDA_1 P1OUT|=BIT1 //IIC数据引脚定义#define SDA_0 P1OUT&=~BIT1#define SDA_IN P1DIR&=~BIT1#define SDA_OUT P1DIR|=BIT1#define SlaveAddress 0xA6 //定义器件在IIC总线中的从地址,根据ALT ADDRESS地址引脚不同修改//ALT ADDRESS引脚接地时地址为0xA6,接电源时地址为0x3A//接收数据缓存区//====================器件宏定义======================#define DEVID 0xe5 //器件ID#define THRESH_TAP 0x1d //敲击阈值#define OFSX 0x1e //X轴偏移#define OFSY 0x1f //Y轴偏移#define OFSZ 0x20 //Z轴偏移#define DUR 0x21 //敲击持续时间#define Latent 0x22 //敲击延迟#define Window 0x23 //敲击窗口#define THRESH_ACT 0x24 //活动阈值#define THRESH_INACT 0x25 //静止阈值#define TIME_INACT 0x26 //静止时间#define ACT_INACT_CTL 0x27 //轴使能控制活动和静止检测#define THRESH_FF 0x28 //自由落体阈值#define TIME_FF 0x29 //自由落体时间#define TAP_AXES 0x2a //单击/双击轴控制#define ACT_TAP_STATUS 0x2b //单机/双击源#define BW_RATE 0x2c //数据速率及功率模式控制#define POWER_CTL 0x2d //省电特性控制#define INT_ENABLE 0x2e //中断使能控制#define INT_MAP 0x2f //中断映射控制#define INT_SOURCE 0x30 //中断源#define DATA_FORMATE 0x31 //数据格式控制#define DATAX0 0x32 //X轴数据-低八位#define DATAX1 0x33 //X轴数据-高八位#define DATAY0 0x34 //Y轴数据-低八位#define DATAY1 0x35 //Y轴数据-高八位#define DATAZ0 0x36 //Z轴数据-低八位#define DATAZ1 0x37 //Z轴数据-高八位#define FIFO_CTL 0x38 //FIFO控制#define FIFO_STATUS 0x39 //FIFO状态extern void first_Angle(void);extern void Angle(void);extern void display_Angle(void);extern void display_XYZ(void);extern void Init_ADXL345();extern void Multiple_Read_ADXL345(void);#endif /* ADXL_G2553_H_ */#include"msp430g2553.h"#include <math.h>#include"ADXL345-G2553.h"#include "HT1621IO.h"char BUF[8];uchar ge,shi,bai,qian,wan; //显示变量int data_xyz[3];void delay_ADXL345(unsigned int k);void Init_ADXL345(void); //初始化ADXL345void conversion(uint temp_data);void Single_Write_ADXL345(uchar REG_Address,uchar REG_data); //单个写入数据uchar Single_Read_ADXL345(uchar REG_Address); //单个读取内部寄存器数据void Multiple_Read_ADXL345(void); //连续的读取内部寄存器数据void Delay5us();void Delay5ms();void ADXL345_Start();void ADXL345_Stop();void ADXL345_SendACK(char ack);char ADXL345_RecvACK();void ADXL345_SendByte(char dat);char ADXL345_RecvByte();//void ADXL345_ReadPage();//void ADXL345_WritePage();//*********************************************************void conversion(uint temp_data){temp_data=temp_data%10000; //取余运算qian=temp_data/1000;temp_data=temp_data%1000; //取余运算bai=temp_data/100;temp_data=temp_data%100; //取余运算shi=temp_data/10;/* if(qian==1){bai=9;shi=9;}*/}/*******************************/void delay_ADXL345(unsigned int k){unsigned int i,j;for(i=0;i<k;i++){for(j=0;j<12;j++){;}}}/**************************************延时5微秒(STC90C52RC@12M)不同的工作环境,需要调整此函数,注意时钟过快时需要修改当改用1T的MCU时,请调整此延时函数**************************************/void Delay5us(){__delay_cycles(60);}/**************************************延时5毫秒(STC90C52RC@12M)不同的工作环境,需要调整此函数当改用1T的MCU时,请调整此延时函数**************************************/void Delay5ms(){__delay_cycles(6000);}/**************************************起始信号**************************************/ void ADXL345_Start(){SCL_OUT;SDA_OUT;SDA_1; //拉高数据线_NOP();SCL_1; //拉高时钟线Delay5us(); //延时SDA_0; //产生下降沿Delay5us(); //延时SCL_0; //拉低时钟线}/**************************************停止信号**************************************/ void ADXL345_Stop(){SDA_OUT;SDA_0; //拉低数据线_NOP();SCL_1; //拉高时钟线Delay5us(); //延时SDA_1; //产生上升沿Delay5us(); //延时}/**************************************发送应答信号入口参数:ack (0:ACK 1:NAK)**************************************/ void ADXL345_SendACK(char ack){SDA_OUT;if(ack)SDA_1;elseSDA_0;_NOP();SCL_1; //拉高时钟线Delay5us(); //延时SCL_0; //拉低时钟线// Delay5us(); //延时SDA_1;}/**************************************接收应答信号**************************************/char ADXL345_RecvACK(){char ack;SDA_IN;SCL_0; //拉高时钟线Delay5us(); //延时SCL_1;if(SDA)ack=0; //读应答信号elseack=1;SCL_0; //拉低时钟线Delay5us(); //延时SDA_OUT;return ack ;}/**************************************向IIC总线发送一个字节数据**************************************/void ADXL345_SendByte(char dat){char i;SDA_OUT;for (i=0; i<8; i++) //8位计数器{Delay5us(); //延时if((dat&0x80)==0x80) //发送数据的最高位{SDA_1;}else{SDA_0;}//送数据口_NOP();SCL_1; //拉高时钟线Delay5us(); //延时SCL_0; //拉低时钟线dat<<=1;}ADXL345_RecvACK();}/**************************************从IIC总线接收一个字节数据**************************************/char ADXL345_RecvByte(){char i;char dat = 0;SDA_IN;_NOP();for (i=0; i<8; i++) //8位计数器{dat <<= 1;SCL_1; //拉高时钟线Delay5us(); //延时if(SDA)dat++;SCL_0; //拉低时钟线Delay5us(); //延时}return dat;}//******单字节写入*******************************************void Single_Write_ADXL345(uchar REG_Address,uchar REG_data){ADXL345_Start(); //起始信号ADXL345_SendByte(SlaveAddress); //发送设备地址+写信号ADXL345_SendByte(REG_Address); //内部寄存器地址,请参考中文pdf22页ADXL345_SendByte(REG_data); //内部寄存器数据,请参考中文pdf22页ADXL345_Stop(); //发送停止信号}//********单字节读取*****************************************uchar Single_Read_ADXL345(uchar REG_Address){ uchar REG_data;ADXL345_Start(); //起始信号ADXL345_SendByte(SlaveAddress); //发送设备地址+写信号ADXL345_SendByte(REG_Address); //发送存储单元地址,从0开始ADXL345_Start(); //起始信号ADXL345_SendByte(SlaveAddress+1); //发送设备地址+读信号REG_data=ADXL345_RecvByte(); //读出寄存器数据ADXL345_SendACK(1);ADXL345_Stop(); //停止信号return REG_data;}//*********************************************************////连续读出ADXL345内部加速度数据,地址范围0x32~0x37////*********************************************************//*********************************************************************** void Multiple_Read_ADXL345(void){uchar i;ADXL345_Start(); //起始信号ADXL345_SendByte(SlaveAddress); //发送设备地址+写信号ADXL345_SendByte(0x32); //发送存储单元地址,从0x32开始ADXL345_Start(); //起始信号ADXL345_SendByte(SlaveAddress+1); //发送设备地址+读信号for (i=0; i<6; i++) //连续读取6个地址数据,存储中BUF {BUF[i] = ADXL345_RecvByte(); //BUF[0]存储0x32地址中的数据if (i == 5){ADXL345_SendACK(1); //最后一个数据需要回NOACK }else{ADXL345_SendACK(0); //回应ACK}}ADXL345_Stop(); //停止信号Delay5ms();}//*****************************************************************//初始化ADXL345,根据需要请参考pdf进行修改************************void Init_ADXL345(){Single_Write_ADXL345(0x31,0x0B); //测量范围,正负16g,13位模式。

MSP430G2553红外线编码键盘

MSP430G2553红外线编码键盘
/*temp_time=TH1;
temp_time<<=8;
temp_time+=TL1;*/
if(temp_time>49)///数据位为1;
KEY_value|=0x01;
KEY_value<<=1;
if(I_count==34)
{
KEY_value>>=1;///
}
}
}
///定时时间到。归零;
#pragma vector=TIMER0_A1_VECTOR
__interrupt void time0()
{
switch(TA0IV)
{
case 2:break;
void inter_init();///P2.2红外线中断入口;
{
P2REN|=INIFG;///电阻控制;
P2OUT|=INIFG;///电阻上拉;
P2DIR&=~INIFG; //清除标志位
P2IES|=INIFG; //选择上跳沿中断
P2IE|=INIFG; //使能中断
_EINT(); //开总中断
}
#pragma vector=PORT2_VECTOR
__interrupt void cood_interrup()
{
if(P2IFG&INIFG==INIFG)
}
TAR=0;//TH1=0;TL1=0;///每一次检测定时器必须清零;
}
else
{
if(I_count==1)
//TACTL&=~MC0; //连码也会进入此函数;//但第三次

msp430g2553定时一秒的程序

msp430g2553定时一秒的程序

#include "msp430g2553.h"//定时一秒unsigned char num;void main(){WDTCTL = WDTPW + WDTHOLD;BCSCTL3 |= LFXT1S_2; // Set LFXT1为vol时钟即12kHZCCTL0|= CCIE; //设置捕获/比较控制寄存器,CCIE=0x0010,使能捕获比较中断CCR0 =12000; //设置捕获/比较寄存器,初始值为12000,对于ACLK时钟频率为12khz的频率,相当于1sTA0CTL = TASSEL_1 +TACLR+MC_1; // 设置定时器A控制寄存器,P1SEL&=~BIT6; //P1.6为I/O口P1DIR |=BIT6; //P1.6为输出_EINT(); //使能中断,这是一个C编译器支持的内部过程。

while(1); //无限次while循环}#pragma vector=TIMER0_A0_VECTOR//固定的格式__interrupt void Timer_A (void) //定时器A的CC0中断处理程序必须是没有返回值的{P1OUT ^= BIT6; //将P3.7引脚取反,就是使发光二极管闪烁}#include "msp430g2553.h"unsigned int times,time1;void TimerA_Init(void){TACTL = TASSEL_1 + ID0 + TACLR ;CCTL0 = CCIE;CCR0 = 16432;TACTL |= MC0;}int main( void ){WDTCTL = WDTPW + WDTHOLD; TimerA_Init(); //定时器初使化P1DIR=0x01;_EINT(); // interrupt enablefor(;;);}#pragma vector = TIMER0_A0_VECTOR __interrupt void Timer_A (void){times++;if(times == 2){times = 0;P1OUT^=BIT0;}。

msp430g2553数据手册中文版

msp430g2553数据手册中文版

28 引脚
24 TSSOP 封
LF,

-
1
DCO,
VLO
20 引脚
16 TSSOP 封

16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
28 引脚
24 TSSOP 封
LF,

-
1
DCO,
VLO
20 引脚
16 TSSOP 封

16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
28 引脚
3
MSP430G2x53 MSP430G2x13
ZHCS178E – APRIL 2011 – REVISED JANUARY 2012

器件引出脚配置、MSP430G2x13 和 MSP430G2x53、20 引脚器件、 TSSOP 和 PDIP 封装
DVCC 1 P1.0/TA0CLK/ACLK/A0/CA0 2 P1.1/TA0.0/UCA0RXD/UCA0SOMI/A1/CA1 3 P1.2/TA0.1/UCA0TXD/PUCA0SIMO/A2/CA2 4 P1.3/ADC10CLK/CAOUT/VREF-/VEREF-/A3/CA3 5 P1.4/SMCLK/UCB0STE/UCA0CLK/VREF+/VEREF+/A4/CA4/TCK 6 P1.5/TA0.0/UCB0CLK/UCA0STE/A5/CA5/TMS 7
P2.0/TA1.0 8 P2.1/TA1.1 9 P2.2/TA1.1 10
N20 PW20 (TOP VIEW)
20 DVSS 19 XIN/P2.6/TA0.1 18 XOUT/P2.7 17 TEST/SBWTCK 16 RST/NMI/SBWTDIO 15 P1.7/CAOUT/UCB0SIMO/UCB0SDA/A7/CA7/TDO/TDI 14 P1.6/TA0.1/UCB0SOMI/UCB0SCL/A6/CA6/TDI/TCLK 13 P2.5/TA1.2 12 P2.4/TA1.2 11 P2.3/TA1.0

MSP430G2553寄存器的中文注释

MSP430G2553寄存器的中文注释

MSP430寄存器中文注释---P1/2口(带中断功能)/************************************************************ * DIGITAL I/O Port1/2 寄存器定义有中断功能************************************************************/ #define P1IN_ 0x0020 /* P1 输入寄存器 */const sfrb P1IN = P1IN_;#define P1OUT_ 0x0021/* P1 输出寄存器 */ sfrb P1OUT = P1OUT_;#define P1DIR_ 0x0022 /* P1 方向选择寄存器 */sfrb P1DIR = P1DIR_;#define P1IFG_ 0x0023 /* P1 中断标志寄存器*/sfrb P1IFG = P1IFG_;#define P1IES_ 0x0024 /* P1 中断边沿选择寄存器*/ sfrb P1IES = P1IES_;#define P1IE_ 0x0025 /* P1 中断使能寄存器 */sfrb P1IE = P1IE_;#define P1SEL_ 0x0026 /* P1 功能选择寄存器*/sfrb P1SEL = P1SEL_;#define P2IN_ 0x0028 /* P2 输入寄存器 */const sfrb P2IN = P2IN_;#define P2OUT_ 0x0029 /* P2 输出寄存器*/sfrb P2OUT = P2OUT_;#define P2DIR_ 0x002A /* P2 方向选择寄存器*/ sfrb P2DIR = P2DIR_;#define P2IFG_ 0x002B /* P2 中断标志寄存器 */sfrb P2IFG = P2IFG_;#define P2IES_ 0x002C /* P2 中断边沿选择寄存器 */ sfrb P2IES = P2IES_;#define P2IE_ 0x002D /* P2 中断使能寄存器 */sfrb P2IE = P2IE_;#define P2SEL_ 0x002E /* P2 功能选择寄存器 */sfrb P2SEL = P2SEL_;MSP430寄存器中文注释---P3/4口(无中断功能)/************************************************************* DIGITAL I/O Port3/4寄存器定义无中断功能************************************************************/#define P3IN_ 0x0018 /* P3 输入寄存器 */const sfrb P3IN = P3IN_;#define P3OUT_ 0x0019 /* P3 输出寄存器 */sfrb P3OUT = P3OUT_;#define P3DIR_ 0x001A /* P3 方向选择寄存器 */sfrb P3DIR = P3DIR_;#define P3SEL_ 0x001B /* P3 功能选择寄存器*/sfrb P3SEL = P3SEL_;#define P4IN_ 0x001C /* P4 输入寄存器 */const sfrb P4IN = P4IN_;#define P4OUT_ 0x001D /* P4 输出寄存器 */sfrb P4OUT = P4OUT_;#define P4DIR_ 0x001E /* P4 方向选择寄存器 */sfrb P4DIR = P4DIR_;#define P4SEL_ 0x001F /* P4 功能选择寄存器 */sfrb P4SEL = P4SEL_;/************************************************************* DIGITAL I/O Port5/6 I/O口寄存器定义PORT5和6 无中断功能************************************************************/#define P5IN_ 0x0030 /* P5 输入寄存器 */const sfrb P5IN = P5IN_;#define P5OUT_ 0x0031 /* P5 输出寄存器*/sfrb P5OUT = P5OUT_;#define P5DIR_ 0x0032 /* P5 方向选择寄存器*/ sfrb P5DIR = P5DIR_;#define P5SEL_ 0x0033 /* P5 功能选择寄存器*/ sfrb P5SEL = P5SEL_;#define P6IN_ 0x0034 /* P6 输入寄存器 */const sfrb P6IN = P6IN_;#define P6OUT_ 0x0035 /* P6 输出寄存器*/sfrb P6OUT = P6OUT_;#define P6DIR_ 0x0036 /* P6 方向选择寄存器*/ sfrb P6DIR = P6DIR_;#define P6SEL_ 0x0037 /* P6 功能选择寄存器*/ sfrb P6SEL = P6SEL_;MSP430寄存器中文注释--- 硬件乘法器/************************************************************硬件乘法器的寄存器定义************************************************************/ #define MPY_ 0x0130 /* 无符号乘法 */sfrw MPY = MPY_;#define MPYS_ 0x0132 /* 有符号乘法*/sfrw MPYS = MPYS_;#define MAC_ 0x0134 /* 无符号乘加 */sfrw MAC = MAC_;#define MACS_ 0x0136 /* 有符号乘加 */sfrw MACS = MACS_;#define OP2_ 0x0138 /* 第二乘数 */sfrw OP2 = OP2_;#define RESLO_ 0x013A /* 低6位结果寄存器 */sfrw RESLO = RESLO_;#define RESHI_ 0x013C /* 高6位结果寄存器 */sfrw RESHI = RESHI_;#define SUMEXT_ 0x013E /*结果扩展寄存器*/const sfrw SUMEXT = SUMEXT_;MSP430寄存器中文注释---看门狗和定时器/************************************************************* 看门狗定时器的寄存器定义************************************************************/#define WDTCTL_ 0x0120sfrw WDTCTL = WDTCTL_;#define WDTIS0 0x0001 /*选择WDTCNT的四个输出端之一*/#define WDTIS1 0x0002 /*选择WDTCNT的四个输出端之一*/#define WDTSSEL 0x0004 /*选择WDTCNT的时钟源*/#define WDTCNTCL 0x0008 /*清除WDTCNT端: 为1时从0开始计数*/#define WDTTMSEL 0x0010 /*选择模式0: 看门狗模式; 1: 定时器模式*/#define WDTNMI 0x0020 /*选择NMI/RST 引脚功能 0:为 RST; 1:为NMI*/#define WDTNMIES 0x0040 /*WDTNMI=1时.选择触发延 0:为上升延 1:为下降延*/ #define WDTHOLD 0x0080 /*停止看门狗定时器工作 0:启动;1:停止*/#define WDTPW 0x5A00 /* 写密码:高八位*//* SMCLK= 1MHz定时器模式 */#define WDT_MDLY_32 WDTPW+WDTTMSEL+WDTCNTCL /*TSMCLK*2POWER15=32ms 复位状态 */#define WDT_MDLY_8 WDTPW+WDTTMSEL+WDTCNTCL+WDTIS0 /*TSMCLK*2POWER13=8.192ms " */#define WDT_MDLY_0_5 WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1 /*TSMCLK*2POWER9=0.512ms " */#define WDT_MDLY_0_064 WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1+WDTIS0 /*TSMCLK*2POWER6=0.512ms " *//* ACLK=32.768KHz 定时器模式*/#define WDT_ADLY_1000 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL /* TACLK*2POWER15=1000ms " */#define WDT_ADLY_250 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS0 /* TACLK*2POWER13=250ms " */#define WDT_ADLY_16 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1 /* TACLK*2POWER9=16ms " */#define WDT_ADLY_1_9 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0 /* TACLK*2POWER6=1.9ms " *//* SMCLK=1MHz看门狗模式 */#define WDT_MRST_32 WDTPW+WDTCNTCL /* TSMCLK*2POWER15=32ms 复位状态*/#define WDT_MRST_8 WDTPW+WDTCNTCL+WDTIS0 /* TSMCLK*2POWER13=8.192ms " */#define WDT_MRST_0_5 WDTPW+WDTCNTCL+WDTIS1 /* TSMCLK*2POWER9=0.512ms " */#define WDT_MRST_0_064 WDTPW+WDTCNTCL+WDTIS1+WDTIS0 /* TSMCLK*2POWER6=0.512ms " *//* ACLK=32KHz看门狗模式 */#define WDT_ARST_1000 WDTPW+WDTCNTCL+WDTSSEL /* TACLK*2POWER15=1000ms " */#define WDT_ARST_250 WDTPW+WDTCNTCL+WDTSSEL+WDTIS0 /* TACLK*2POWER13=250ms " */#define WDT_ARST_16 WDTPW+WDTCNTCL+WDTSSEL+WDTIS1 /* TACLK*2POWER9=16ms " */#define WDT_ARST_1_9 WDTPW+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0 /* TACLK*2POWER6=1.9ms " */MSP430寄存器中文注释---A/D采样寄存器定义/************************************************************* ADC12 A/D采样寄存器定义************************************************************//*ADC12转换控制类寄存器*/#define ADC12CTL0_ 0x0;' /* ADC12 Control 0 */sfrw ADC12CTL0 = ADC12CTL0_;#define ADC12CTL1_ 0x01A2 /* ADC12 Control 1 */sfrw ADC12CTL1 = ADC12CTL1_;/*ADC12中断控制类寄存器*/#define ADC12IFG_ 0x01A4 /* ADC12 Interrupt Flag */sfrw ADC12IFG = ADC12IFG_;#define ADC12IE_ 0x01A6 /* ADC12 Interrupt Enable */sfrw ADC12IE = ADC12IE_;#define ADC12IV_ 0x01A8 /* ADC12 Interrupt Vector Word */sfrw ADC12IV = ADC12IV_;/*ADC12存贮器类寄存器*/#define ADC12MEM_ 0x0140 /* ADC12 Conversion Memory */#ifndef __IAR_SYSTEMS_ICC#define ADC12MEM ADC12MEM_ /* ADC12 Conversion Memory (for assembler) */ #else#define ADC12MEM ((int*) ADC12MEM_) /* ADC12 Conversion Memory (for C) */ #endif#define ADC12MEM0_ ADC12MEM_ /* ADC12 Conversion Memory 0 */sfrw ADC12MEM0 = ADC12MEM0_;#define ADC12MEM1_ 0x0142 /* ADC12 Conversion Memory 1 */sfrw ADC12MEM1 = ADC12MEM1_;#define ADC12MEM2_ 0x0144 /* ADC12 Conversion Memory 2 */sfrw ADC12MEM2 = ADC12MEM2_;#define ADC12MEM3_ 0x0146 /* ADC12 Conversion Memory 3 */sfrw ADC12MEM3 = ADC12MEM3_;#define ADC12MEM4_ 0x0148 /* ADC12 Conversion Memory 4 */sfrw ADC12MEM4 = ADC12MEM4_;#define ADC12MEM5_ 0x014A /* ADC12 Conversion Memory 5 */sfrw ADC12MEM5 = ADC12MEM5_;#define ADC12MEM6_ 0x014C /* ADC12 Conversion Memory 6 */sfrw ADC12MEM6 = ADC12MEM6_;#define ADC12MEM7_ 0x014E /* ADC12 Conversion Memory 7 */sfrw ADC12MEM7 = ADC12MEM7_;#define ADC12MEM8_ 0x0150 /* ADC12 Conversion Memory 8 */sfrw ADC12MEM8 = ADC12MEM8_;#define ADC12MEM9_ 0x0152 /* ADC12 Conversion Memory 9 */sfrw ADC12MEM9 = ADC12MEM9_;#define ADC12MEM10_ 0x0154 /* ADC12 Conversion Memory 10 */sfrw ADC12MEM10 = ADC12MEM10_;#define ADC12MEM11_ 0x0156 /* ADC12 Conversion Memory 11 */sfrw ADC12MEM11 = ADC12MEM11_;#define ADC12MEM12_ 0x0158 /* ADC12 Conversion Memory 12 */sfrw ADC12MEM12 = ADC12MEM12_;#define ADC12MEM13_ 0x015A /* ADC12 Conversion Memory 13 */sfrw ADC12MEM13 = ADC12MEM13_;#define ADC12MEM14_ 0x015C /* ADC12 Conversion Memory 14 */sfrw ADC12MEM14 = ADC12MEM14_;#define ADC12MEM15_ 0x015E /* ADC12 Conversion Memory 15 */sfrw ADC12MEM15 = ADC12MEM15_;/*ADC12存贮控制类寄存器*/#define ADC12MCTL_ 0x0080 /* ADC12 Memory Control */#ifndef __IAR_SYSTEMS_ICC#define ADC12MCTL ADC12MCTL_ /* ADC12 Memory Control (for assembler) */#else#define ADC12MCTL ((char*) ADC12MCTL_) /* ADC12 Memory Control (for C) */ #endif#define ADC12MCTL0_ ADC12MCTL_ /* ADC12 Memory Control 0 */sfrb ADC12MCTL0 = ADC12MCTL0_;#define ADC12MCTL1_ 0x0081 /* ADC12 Memory Control 1 */sfrb ADC12MCTL1 = ADC12MCTL1_;#define ADC12MCTL2_ 0x0082 /* ADC12 Memory Control 2 */sfrb ADC12MCTL2 = ADC12MCTL2_;#define ADC12MCTL3_ 0x0083 /* ADC12 Memory Control 3 */sfrb ADC12MCTL3 = ADC12MCTL3_;#define ADC12MCTL4_ 0x0084 /* ADC12 Memory Control 4 */sfrb ADC12MCTL4 = ADC12MCTL4_;#define ADC12MCTL5_ 0x0085 /* ADC12 Memory Control 5 */sfrb ADC12MCTL5 = ADC12MCTL5_;#define ADC12MCTL6_ 0x0086 /* ADC12 Memory Control 6 */sfrb ADC12MCTL6 = ADC12MCTL6_;#define ADC12MCTL7_ 0x0087 /* ADC12 Memory Control 7 */sfrb ADC12MCTL7 = ADC12MCTL7_;#define ADC12MCTL8_ 0x0088 /* ADC12 Memory Control 8 */sfrb ADC12MCTL8 = ADC12MCTL8_;#define ADC12MCTL9_ 0x0089 /* ADC12 Memory Control 9 */sfrb ADC12MCTL9 = ADC12MCTL9_;#define ADC12MCTL10_ 0x008A /* ADC12 Memory Control 10 */sfrb ADC12MCTL10 = ADC12MCTL10_;#define ADC12MCTL11_ 0x008B /* ADC12 Memory Control 11 */sfrb ADC12MCTL11 = ADC12MCTL11_;#define ADC12MCTL12_ 0x008C /* ADC12 Memory Control 12 */sfrb ADC12MCTL12 = ADC12MCTL12_;#define ADC12MCTL13_ 0x008D /* ADC12 Memory Control 13 */sfrb ADC12MCTL13 = ADC12MCTL13_;#define ADC12MCTL14_ 0x008E /* ADC12 Memory Control 14 */sfrb ADC12MCTL14 = ADC12MCTL14_;#define ADC12MCTL15_ 0x008F /* ADC12 Memory Control 15 */sfrb ADC12MCTL15 = ADC12MCTL15_;/* ADC12CTL0 内8位控制寄存器位*/#define ADC12SC 0x001 /*采样/转换控制位*/#define ENC 0x002 /* 转换允许位*/#define ADC12TOVIE 0x004 /*转换时间溢出中断允许位*/#define ADC12OVIE 0x008 /*溢出中断允许位*/#define ADC12ON 0x010 /*ADC12内核控制位*/#define REFON 0x020 /*参考电压控制位*/#define REF2_5V 0x040 /*内部参考电压的电压值选择位 '0'为1.5V; '1'为2.5V*/ #define MSH 0x080 /*多次采样/转换位*/#define MSC 0x080 /*多次采样/转换位*//*SHT0 采样保持定时器0 控制ADC12的结果存贮器MEM0~MEM7的采样周期*/#define SHT0_0 0*0x100 /*采样周期=TADC12CLK*4 */#define SHT0_1 1*0x100 /*采样周期=TADC12CLK*8 */#define SHT0_2 2*0x100 /*采样周期=TADC12CLK*16 */#define SHT0_3 3*0x100 /*采样周期=TADC12CLK*32 */#define SHT0_4 4*0x100 /*采样周期=TADC12CLK*64 */#define SHT0_5 5*0x100 /*采样周期=TADC12CLK*96 */#define SHT0_6 6*0x100 /*采样周期=TADC12CLK*128 */#define SHT0_7 7*0x100 /*采样周期=TADC12CLK*192 */#define SHT0_8 8*0x100 /*采样周期=TADC12CLK*256 */#define SHT0_9 9*0x100 /*采样周期=TADC12CLK*384 */#define SHT0_10 10*0x100 /*采样周期=TADC12CLK*512 */#define SHT0_11 11*0x100 /*采样周期=TADC12CLK*768 */#define SHT0_12 12*0x100 /*采样周期=TADC12CLK*1024 */#define SHT0_13 13*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT0_14 14*0x100 /*采样周期=TADC12CLK*1024*/ #define SHT0_15 15*0x100 /*采样周期=TADC12CLK*1024 */ /*SHT1 采样保持定时器1 控制ADC12的结果存贮器MEM8~MEM15的采样周期*/#define SHT1_0 0*0x100 /*采样周期=TADC12CLK*4 */#define SHT1_1 1*0x100 /*采样周期=TADC12CLK*8 */#define SHT1_2 2*0x100 /*采样周期=TADC12CLK*16 */#define SHT1_3 3*0x100 /*采样周期=TADC12CLK*32 */#define SHT1_4 4*0x100 /*采样周期=TADC12CLK*64 */#define SHT1_5 5*0x100 /*采样周期=TADC12CLK*96 */#define SHT1_6 6*0x100 /*采样周期=TADC12CLK*128 */ #define SHT1_7 7*0x100 /*采样周期=TADC12CLK*192 */ #define SHT1_8 8*0x100 /*采样周期=TADC12CLK*256 */ #define SHT1_9 9*0x100 /*采样周期=TADC12CLK*384 */ #define SHT1_10 10*0x100 /*采样周期=TADC12CLK*512 */ #define SHT1_11 11*0x100 /*采样周期=TADC12CLK*768 */ #define SHT1_12 12*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT1_13 13*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT1_14 14*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT1_15 15*0x100 /*采样周期=TADC12CLK*1024 *//* ADC12CTL1 内8位控制寄存器位*/#define ADC12BUSY 0x0001 /*ADC12忙标志位*/#define CONSEQ_0 0*2 /*单通道单次转换*/#define CONSEQ_1 1*2 /*序列通道单次转换*/#define CONSEQ_2 2*2 /*单通道多次转换*/#define CONSEQ_3 3*2 /*序列通道多次转换*/#define ADC12SSEL_0 0*8 /*ADC12内部时钟源*/#define ADC12SSEL_1 1*8 /*ACLK*/#define ADC12SSEL_2 2*8 /*MCLK*/#define ADC12SSEL_3 3*8 /*SCLK*/#define ADC12DIV_0 0*0x20 /*1分频*/#define ADC12DIV_1 1*0x20 /*2分频*/#define ADC12DIV_2 2*0x20 /*3分频*/#define ADC12DIV_3 3*0x20 /*4分频*/#define ADC12DIV_4 4*0x20 /*5分频*/#define ADC12DIV_5 5*0x20 /*6分频*/#define ADC12DIV_6 6*0x20 /*7分频*/#define ADC12DIV_7 7*0x20 /*8分频*/#define ISSH 0x0100 /*采样输入信号反向与否控制位*/#define SHP 0x0200 /*采样信号(SAMPCON)选择控制位*/#define SHS_0 0*0x400 /*采样信号输入源选择控制位 ADC12SC*/#define SHS_1 1*0x400 /*采样信号输入源选择控制位 TIMER_A.OUT1*/ #define SHS_2 2*0x400 /*采样信号输入源选择控制位 TIMER_B.OUT0*/ #define SHS_3 3*0x400 /*采样信号输入源选择控制位 TIMER_B.OUT1*/ /*转换存贮器地址定义位*/#define CSTARTADD_0 0*0x1000 /*选择MEM0首地址*/#define CSTARTADD_1 1*0x1000 /*选择MEM1首地址*/#define CSTARTADD_2 2*0x1000 /*选择MEM2首地址*/#define CSTARTADD_3 3*0x1000 /*选择MEM3首地址*/#define CSTARTADD_4 4*0x1000 /*选择MEM4首地址*/#define CSTARTADD_5 5*0x1000 /*选择MEM5首地址*/#define CSTARTADD_6 6*0x1000 /*选择MEM6首地址*/#define CSTARTADD_7 7*0x1000 /*选择MEM7首地址*/#define CSTARTADD_8 8*0x1000 /*选择MEM8首地址*/#define CSTARTADD_9 9*0x1000 /*选择MEM9首地址*/#define CSTARTADD_10 10*0x1000 /*选择MEM10首地址*/#define CSTARTADD_11 11*0x1000 /*选择MEM11首地址*/#define CSTARTADD_12 12*0x1000 /*选择MEM12首地址*/#define CSTARTADD_13 13*0x1000 /*选择MEM13首地址*/#define CSTARTADD_14 14*0x1000 /*选择MEM14首地址*/#define CSTARTADD_15 15*0x1000 /*选择MEM15首地址*//* ADC12MCTLx */#define INCH_0 0 /*选择模拟量通道0 A0 */#define INCH_1 1 /*选择模拟量通道0 A1*/#define INCH_2 2 /*选择模拟量通道0 A2*/#define INCH_3 3 /*选择模拟量通道0 A3*/#define INCH_4 4 /*选择模拟量通道0 A4*/#define INCH_5 5 /*选择模拟量通道0 A5*/#define INCH_6 6 /*选择模拟量通道0 A6*/#define INCH_7 7 /*选择模拟量通道0 A7*/#define INCH_8 8 /*VEREF+*/#define INCH_9 9 /*VEREF-*/#define INCH_10 10 /*片内温度传感器的输出*/#define INCH_11 11 /*(AVCC-AVSS)/2*/#define INCH_12 12 /*(AVCC-AVSS)/2*/#define INCH_13 13 /*(AVCC-AVSS)/2*/#define INCH_14 14 /*(AVCC-AVSS)/2*/#define INCH_15 15 /*(AVCC-AVSS)/2*//*参考电压源选择位*/#define SREF_0 0*0x10 /*VR+ = AVCC; VR- = AVSS*/#define SREF_1 1*0x10 /*VR+ = VREF+; VR- = AVSS*/ #define SREF_2 2*0x10 /*VR+ = VEREF+; VR- = AVSS*/ #define SREF_3 3*0x10 /*VR+ = VEREF+; VR- = AVSS*/ #define SREF_4 4*0x10 /*VR+ = AVCC; VR- = VREF-*/ #define SREF_5 5*0x10 /*VR+ = VREF+; VR- = VREF-*/ #define SREF_6 6*0x10 /*VR+ = VEREF+; VR- = VREF-*/ #define SREF_7 7*0x10 /*VR+ = VEREF+; VR- = VREF-*/#define EOS 0x80 /*序列结束选择位*/MSP430寄存器中文注释----串口寄存器/************************************************************* USART 串口寄存器"UCTL","UTCTL","URCTL"定义的各个位可串口1 串口2公用************************************************************//* UCTL 串口控制寄存器*/#define PENA 0x80 /*校验允许位*/#define PEV 0x40 /*偶校验为0时为奇校验*/#define SPB 0x20 /*停止位为2 为0时停止位为1*/#define CHAR 0x10 /*数据位为8位为0时数据位为7位*/#define LISTEN 0x08 /*自环模式(发数据同时在把发的数据接收回来)*/#define SYNC 0x04 /*同步模式为0异步模式*/#define MM 0x02 /*为1时地址位多机协议(异步) 主机模式(同步);为0时线路空闲多机协议(异步) 从机模式(同步)*/#define SWRST 0x01 /*控制位*//* UTCTL 串口发送控制寄存器*/#define CKPH 0x80 /*时钟相位控制位(只同步方式用)为1时时钟UCLK延时半个周期*/#define CKPL 0x40 /*时钟极性控制位为1时异步与UCLK相反;同步下降延有效*/#define SSEL1 0x20 /*时钟源选择位:与SSEL0组合为0,1,2,3四种方式*/#define SSEL0 0x10 /*"0"选择外部时钟,"1"选择辅助时钟,"2","3"选择系统子时钟 */#define URXSE 0x08 /*接收触发延控制位(只在异步方式下用)*/#define TXWAKE 0x04 /*多处理器通信传送控制位(只在异步方式下用)*/#define STC 0x02 /*外部引脚STE选择位为0时为4线模式为1时为3线模式*/ #define TXEPT 0x01 /*发送器空标志*//* URCTL 串口接收控制寄存器同步模式下只用两位:FE和OE*/#define FE 0x80 /*帧错标志*/#define PE 0x40 /*校验错标志位*/#define OE 0x20 /*溢出标志位*/#define BRK 0x10 /*打断检测位*/#define URXEIE 0x08 /*接收出错中断允许位*/#define URXWIE 0x04 /*接收唤醒中断允许位*/#define RXWAKE 0x02 /*接收唤醒检测位*/#define RXERR 0x01 /*接收错误标志位*//************************************************************* USART 0 串口0寄存器定义************************************************************/#define U0CTL_ 0x0070 /* UART 0 Control */sfrb U0CTL = U0CTL_;#define U0TCTL_ 0x0071 /* UART 0 Transmit Control */ sfrb U0TCTL = U0TCTL_;#define U0RCTL_ 0x0072 /* UART 0 Receive Control */ sfrb U0RCTL = U0RCTL_;#define U0MCTL_ 0x0073 /* UART 0 Modulation Control */ sfrb U0MCTL = U0MCTL_;#define U0BR0_ 0x0074 /* UART 0 Baud Rate 0 */sfrb U0BR0 = U0BR0_;#define U0BR1_ 0x0075 /* UART 0 Baud Rate 1 */sfrb U0BR1 = U0BR1_;#define U0RXBUF_ 0x0076 /* UART 0 Receive Buffer */ const sfrb U0RXBUF = U0RXBUF_;#define U0TXBUF_ 0x0077 /* UART 0 Transmit Buffer */ sfrb U0TXBUF = U0TXBUF_;/* Alternate register names */#define UCTL0_ 0x0070 /* UART 0 Control */sfrb UCTL0 = UCTL0_;#define UTCTL0_ 0x0071 /* UART 0 Transmit Control */ sfrb UTCTL0 = UTCTL0_;#define URCTL0_ 0x0072 /* UART 0 Receive Control */ sfrb URCTL0 = URCTL0_;#define UMCTL0_ 0x0073 /* UART 0 Modulation Control */ sfrb UMCTL0 = UMCTL0_;#define UBR00_ 0x0074 /* UART 0 Baud Rate 0 */sfrb UBR00 = UBR00_;#define UBR10_ 0x0075 /* UART 0 Baud Rate 1 */sfrb UBR10 = UBR10_;#define RXBUF0_ 0x0076 /* UART 0 Receive Buffer */ const sfrb RXBUF0 = RXBUF0_;#define TXBUF0_ 0x0077 /* UART 0 Transmit Buffer */ sfrb TXBUF0 = TXBUF0_;#define UCTL_0_ 0x0070 /* UART 0 Control */sfrb UCTL_0 = UCTL_0_;#define UTCTL_0_ 0x0071 /* UART 0 Transmit Control */ sfrb UTCTL_0 = UTCTL_0_;#define URCTL_0_ 0x0072 /* UART 0 Receive Control */ sfrb URCTL_0 = URCTL_0_;#define UMCTL_0_ 0x0073 /* UART 0 Modulation Control */ sfrb UMCTL_0 = UMCTL_0_;#define UBR0_0_ 0x0074 /* UART 0 Baud Rate 0 */sfrb UBR0_0 = UBR0_0_;#define UBR1_0_ 0x0075 /* UART 0 Baud Rate 1 */sfrb UBR1_0 = UBR1_0_;#define RXBUF_0_ 0x0076 /* UART 0 Receive Buffer */ const sfrb RXBUF_0 = RXBUF_0_;#define TXBUF_0_ 0x0077 /* UART 0 Transmit Buffer *//************************************************************* USART 1 串口1寄存器定义************************************************************/#define U1CTL_ 0x0078 /* UART 1 Control */sfrb U1CTL = U1CTL_;#define U1TCTL_ 0x0079 /* UART 1 Transmit Control */ sfrb U1TCTL = U1TCTL_;#define U1RCTL_ 0x007A /* UART 1 Receive Control */ sfrb U1RCTL = U1RCTL_;#define U1MCTL_ 0x007B /* UART 1 Modulation Control */ sfrb U1MCTL = U1MCTL_;#define U1BR0_ 0x007C /* UART 1 Baud Rate 0 */sfrb U1BR0 = U1BR0_;#define U1BR1_ 0x007D /* UART 1 Baud Rate 1 */sfrb U1BR1 = U1BR1_;#define U1RXBUF_ 0x007E /* UART 1 Receive Buffer */ const sfrb U1RXBUF = U1RXBUF_;#define U1TXBUF_ 0x007F /* UART 1 Transmit Buffer */ sfrb U1TXBUF = U1TXBUF_;#define UCTL1_ 0x0078 /* UART 1 Control */sfrb UCTL1 = UCTL1_;#define UTCTL1_ 0x0079 /* UART 1 Transmit Control */ sfrb UTCTL1 = UTCTL1_;#define URCTL1_ 0x007A /* UART 1 Receive Control */ sfrb URCTL1 = URCTL1_;#define UMCTL1_ 0x007B /* UART 1 Modulation Control */ sfrb UMCTL1 = UMCTL1_;#define UBR01_ 0x007C /* UART 1 Baud Rate 0 */#define UBR11_ 0x007D /* UART 1 Baud Rate 1 */sfrb UBR11 = UBR11_;#define RXBUF1_ 0x007E /* UART 1 Receive Buffer */ const sfrb RXBUF1 = RXBUF1_;#define TXBUF1_ 0x007F /* UART 1 Transmit Buffer */ sfrb TXBUF1 = TXBUF1_;#define UCTL_1_ 0x0078 /* UART 1 Control */sfrb UCTL_1 = UCTL_1_;#define UTCTL_1_ 0x0079 /* UART 1 Transmit Control */ sfrb UTCTL_1 = UTCTL_1_;#define URCTL_1_ 0x007A /* UART 1 Receive Control */ sfrb URCTL_1 = URCTL_1_;#define UMCTL_1_ 0x007B /* UART 1 Modulation Control */ sfrb UMCTL_1 = UMCTL_1_;#define UBR0_1_ 0x007C /* UART 1 Baud Rate 0 */sfrb UBR0_1 = UBR0_1_;#define UBR1_1_ 0x007D /* UART 1 Baud Rate 1 */sfrb UBR1_1 = UBR1_1_;#define RXBUF_1_ 0x007E /* UART 1 Receive Buffer */ const sfrb RXBUF_1 = RXBUF_1_;#define TXBUF_1_ 0x007F /* UART 1 Transmit Buffer */ sfrb TXBUF_1 = TXBUF_1_;MSP430寄存器中文注释---P1/2口(带中断功能)/************************************************************* DIGITAL I/O Port1/2 寄存器定义有中断功能************************************************************/#define P1IN_ 0x0020 /* P1 输入寄存器 */const sfrb P1IN = P1IN_;#define P1OUT_ 0x0021 /* P1 输出寄存器 */sfrb P1OUT = P1OUT_;#define P1DIR_ 0x0022 /* P1 方向选择寄存器 */sfrb P1DIR = P1DIR_;#define P1IFG_ 0x0023 /* P1 中断标志寄存器*/sfrb P1IFG = P1IFG_;#define P1IES_ 0x0024 /* P1 中断边沿选择寄存器*/ sfrb P1IES = P1IES_;#define P1IE_ 0x0025 /* P1 中断使能寄存器 */sfrb P1IE = P1IE_;#define P1SEL_ 0x0026 /* P1 功能选择寄存器*/sfrb P1SEL = P1SEL_;#define P2IN_ 0x0028 /* P2 输入寄存器 */const sfrb P2IN = P2IN_;#define P2OUT_ 0x0029 /* P2 输出寄存器 */sfrb P2OUT = P2OUT_;#define P2DIR_ 0x002A /* P2 方向选择寄存器 */ sfrb P2DIR = P2DIR_;#define P2IFG_ 0x002B /* P2 中断标志寄存器 */sfrb P2IFG = P2IFG_;#define P2IES_ 0x002C /* P2 中断边沿选择寄存器 */ sfrb P2IES = P2IES_;#define P2IE_ 0x002D /* P2 中断使能寄存器 */sfrb P2IE = P2IE_;#define P2SEL_ 0x002E /* P2 功能选择寄存器 */sfrb P2SEL = P2SEL_;MSP430寄存器中文注释---P3/4口(无中断功能)/************************************************************ * DIGITAL I/O Port3/4寄存器定义无中断功能************************************************************/#define P3IN_ 0x0018 /* P3 输入寄存器 */const sfrb P3IN = P3IN_;#define P3OUT_ 0x0019 /* P3 输出寄存器 */sfrb P3OUT = P3OUT_;#define P3DIR_ 0x001A /* P3 方向选择寄存器 */sfrb P3DIR = P3DIR_;#define P3SEL_ 0x001B /* P3 功能选择寄存器*/sfrb P3SEL = P3SEL_;#define P4IN_ 0x001C /* P4 输入寄存器 */const sfrb P4IN = P4IN_;#define P4OUT_ 0x001D /* P4 输出寄存器 */sfrb P4OUT = P4OUT_;#define P4DIR_ 0x001E /* P4 方向选择寄存器 */sfrb P4DIR = P4DIR_;#define P4SEL_ 0x001F /* P4 功能选择寄存器 */sfrb P4SEL = P4SEL_;/************************************************************ * DIGITAL I/O Port5/6 I/O口寄存器定义PORT5和6 无中断功能************************************************************/#define P5IN_ 0x0030 /* P5 输入寄存器 */const sfrb P5IN = P5IN_;#define P5OUT_ 0x0031 /* P5 输出寄存器*/sfrb P5OUT = P5OUT_;#define P5DIR_ 0x0032 /* P5 方向选择寄存器*/sfrb P5DIR = P5DIR_;#define P5SEL_ 0x0033 /* P5 功能选择寄存器*/sfrb P5SEL = P5SEL_;#define P6IN_ 0x0034 /* P6 输入寄存器 */const sfrb P6IN = P6IN_;#define P6OUT_ 0x0035 /* P6 输出寄存器*/sfrb P6OUT = P6OUT_;#define P6DIR_ 0x0036 /* P6 方向选择寄存器*/sfrb P6DIR = P6DIR_;#define P6SEL_ 0x0037 /* P6 功能选择寄存器*/sfrb P6SEL = P6SEL_;MSP430寄存器中文注释--- 硬件乘法器/************************************************************ 硬件乘法器的寄存器定义************************************************************/#define MPY_ 0x0130 /* 无符号乘法 */sfrw MPY = MPY_;#define MPYS_ 0x0132 /* 有符号乘法*/sfrw MPYS = MPYS_;#define MAC_ 0x0134 /* 无符号乘加 */sfrw MAC = MAC_;#define MACS_ 0x0136 /* 有符号乘加 */sfrw MACS = MACS_;#define OP2_ 0x0138 /* 第二乘数 */sfrw OP2 = OP2_;#define RESLO_ 0x013A /* 低6位结果寄存器 */sfrw RESLO = RESLO_;#define RESHI_ 0x013C /* 高6位结果寄存器 */sfrw RESHI = RESHI_;#define SUMEXT_ 0x013E /*结果扩展寄存器 */const sfrw SUMEXT = SUMEXT_;MSP430寄存器中文注释---看门狗和定时器/************************************************************* 看门狗定时器的寄存器定义************************************************************/#define WDTCTL_ 0x0120sfrw WDTCTL = WDTCTL_;#define WDTIS0 0x0001 /*选择WDTCNT的四个输出端之一*/#define WDTIS1 0x0002 /*选择WDTCNT的四个输出端之一*/#define WDTSSEL 0x0004 /*选择WDTCNT的时钟源*/#define WDTCNTCL 0x0008 /*清除WDTCNT端: 为1时从0开始计数*/#define WDTTMSEL 0x0010 /*选择模式 0: 看门狗模式; 1: 定时器模式*/#define WDTNMI 0x0020 /*选择NMI/RST 引脚功能 0:为 RST; 1:为NMI*/#define WDTNMIES 0x0040 /*WDTNMI=1时.选择触发延 0:为上升延 1:为下降延*/ #define WDTHOLD 0x0080 /*停止看门狗定时器工作 0:启动;1:停止*/#define WDTPW 0x5A00 /* 写密码:高八位*//* SMCLK= 1MHz定时器模式 */#define WDT_MDLY_32 WDTPW+WDTTMSEL+WDTCNTCL /* TSMCLK*2POWER15=32ms 复位状态 */#define WDT_MDLY_8 WDTPW+WDTTMSEL+WDTCNTCL+WDTIS0 /* TSMCLK*2POWER13=8.192ms " */#define WDT_MDLY_0_5 WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1 /* TSMCLK*2POWER9=0.512ms " */#define WDT_MDLY_0_064 WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1+WDTIS0 /* TSMCLK*2POWER6=0.512ms " *//* ACLK=32.768KHz 定时器模式*/#define WDT_ADLY_1000 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL /* TACLK*2POWER15=1000ms " */#define WDT_ADLY_250 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS0 /* TACLK*2POWER13=250ms " */#define WDT_ADLY_16 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1 /*TACLK*2POWER9=16ms " */#define WDT_ADLY_1_9 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0 /* TACLK*2POWER6=1.9ms " *//* SMCLK=1MHz看门狗模式 */#define WDT_MRST_32 WDTPW+WDTCNTCL /* TSMCLK*2POWER15=32ms 复位状态 */#define WDT_MRST_8 WDTPW+WDTCNTCL+WDTIS0 /* TSMCLK*2POWER13=8.192ms " */#define WDT_MRST_0_5 WDTPW+WDTCNTCL+WDTIS1 /* TSMCLK*2POWER9=0.512ms " */#define WDT_MRST_0_064 WDTPW+WDTCNTCL+WDTIS1+WDTIS0 /* TSMCLK*2POWER6=0.512ms " *//* ACLK=32KHz看门狗模式 */#define WDT_ARST_1000 WDTPW+WDTCNTCL+WDTSSEL /* TACLK*2POWER15=1000ms " */#define WDT_ARST_250 WDTPW+WDTCNTCL+WDTSSEL+WDTIS0 /* TACLK*2POWER13=250ms " */#define WDT_ARST_16 WDTPW+WDTCNTCL+WDTSSEL+WDTIS1 /* TACLK*2POWER9=16ms " */#define WDT_ARST_1_9 WDTPW+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0 /* TACLK*2POWER6=1.9ms " */MSP430寄存器中文注释---A/D采样寄存器定义/************************************************************* ADC12 A/D采样寄存器定义************************************************************//*ADC12转换控制类寄存器*/#define ADC12CTL0_ 0x0;' /* ADC12 Control 0 */sfrw ADC12CTL0 = ADC12CTL0_;#define ADC12CTL1_ 0x01A2 /* ADC12 Control 1 */sfrw ADC12CTL1 = ADC12CTL1_;/*ADC12中断控制类寄存器*/#define ADC12IFG_ 0x01A4 /* ADC12 Interrupt Flag */sfrw ADC12IFG = ADC12IFG_;#define ADC12IE_ 0x01A6 /* ADC12 Interrupt Enable */sfrw ADC12IE = ADC12IE_;#define ADC12IV_ 0x01A8 /* ADC12 Interrupt Vector Word */sfrw ADC12IV = ADC12IV_;/*ADC12存贮器类寄存器*/#define ADC12MEM_ 0x0140 /* ADC12 Conversion Memory */#ifndef __IAR_SYSTEMS_ICC#define ADC12MEM ADC12MEM_ /* ADC12 Conversion Memory (for assembler) */ #else#define ADC12MEM ((int*) ADC12MEM_) /* ADC12 Conversion Memory (for C) */ #endif#define ADC12MEM0_ ADC12MEM_ /* ADC12 Conversion Memory 0 */sfrw ADC12MEM0 = ADC12MEM0_;#define ADC12MEM1_ 0x0142 /* ADC12 Conversion Memory 1 */sfrw ADC12MEM1 = ADC12MEM1_;#define ADC12MEM2_ 0x0144 /* ADC12 Conversion Memory 2 */sfrw ADC12MEM2 = ADC12MEM2_;#define ADC12MEM3_ 0x0146 /* ADC12 Conversion Memory 3 */sfrw ADC12MEM3 = ADC12MEM3_;#define ADC12MEM4_ 0x0148 /* ADC12 Conversion Memory 4 */sfrw ADC12MEM4 = ADC12MEM4_;#define ADC12MEM5_ 0x014A /* ADC12 Conversion Memory 5 */sfrw ADC12MEM5 = ADC12MEM5_;#define ADC12MEM6_ 0x014C /* ADC12 Conversion Memory 6 */sfrw ADC12MEM6 = ADC12MEM6_;#define ADC12MEM7_ 0x014E /* ADC12 Conversion Memory 7 */sfrw ADC12MEM7 = ADC12MEM7_;#define ADC12MEM8_ 0x0150 /* ADC12 Conversion Memory 8 */sfrw ADC12MEM8 = ADC12MEM8_;#define ADC12MEM9_ 0x0152 /* ADC12 Conversion Memory 9 */sfrw ADC12MEM9 = ADC12MEM9_;#define ADC12MEM10_ 0x0154 /* ADC12 Conversion Memory 10 */sfrw ADC12MEM10 = ADC12MEM10_;#define ADC12MEM11_ 0x0156 /* ADC12 Conversion Memory 11 */sfrw ADC12MEM11 = ADC12MEM11_;#define ADC12MEM12_ 0x0158 /* ADC12 Conversion Memory 12 */sfrw ADC12MEM12 = ADC12MEM12_;#define ADC12MEM13_ 0x015A /* ADC12 Conversion Memory 13 */sfrw ADC12MEM13 = ADC12MEM13_;#define ADC12MEM14_ 0x015C /* ADC12 Conversion Memory 14 */sfrw ADC12MEM14 = ADC12MEM14_;#define ADC12MEM15_ 0x015E /* ADC12 Conversion Memory 15 */sfrw ADC12MEM15 = ADC12MEM15_;/*ADC12存贮控制类寄存器*/#define ADC12MCTL_ 0x0080 /* ADC12 Memory Control */#ifndef __IAR_SYSTEMS_ICC#define ADC12MCTL ADC12MCTL_ /* ADC12 Memory Control (for assembler) */#else#define ADC12MCTL ((char*) ADC12MCTL_) /* ADC12 Memory Control (for C) */ #endif#define ADC12MCTL0_ ADC12MCTL_ /* ADC12 Memory Control 0 */sfrb ADC12MCTL0 = ADC12MCTL0_;#define ADC12MCTL1_ 0x0081 /* ADC12 Memory Control 1 */sfrb ADC12MCTL1 = ADC12MCTL1_;#define ADC12MCTL2_ 0x0082 /* ADC12 Memory Control 2 */sfrb ADC12MCTL2 = ADC12MCTL2_;#define ADC12MCTL3_ 0x0083 /* ADC12 Memory Control 3 */sfrb ADC12MCTL3 = ADC12MCTL3_;#define ADC12MCTL4_ 0x0084 /* ADC12 Memory Control 4 */sfrb ADC12MCTL4 = ADC12MCTL4_;#define ADC12MCTL5_ 0x0085 /* ADC12 Memory Control 5 */sfrb ADC12MCTL5 = ADC12MCTL5_;#define ADC12MCTL6_ 0x0086 /* ADC12 Memory Control 6 */sfrb ADC12MCTL6 = ADC12MCTL6_;#define ADC12MCTL7_ 0x0087 /* ADC12 Memory Control 7 */sfrb ADC12MCTL7 = ADC12MCTL7_;#define ADC12MCTL8_ 0x0088 /* ADC12 Memory Control 8 */sfrb ADC12MCTL8 = ADC12MCTL8_;#define ADC12MCTL9_ 0x0089 /* ADC12 Memory Control 9 */sfrb ADC12MCTL9 = ADC12MCTL9_;#define ADC12MCTL10_ 0x008A /* ADC12 Memory Control 10 */sfrb ADC12MCTL10 = ADC12MCTL10_;#define ADC12MCTL11_ 0x008B /* ADC12 Memory Control 11 */sfrb ADC12MCTL11 = ADC12MCTL11_;#define ADC12MCTL12_ 0x008C /* ADC12 Memory Control 12 */sfrb ADC12MCTL12 = ADC12MCTL12_;#define ADC12MCTL13_ 0x008D /* ADC12 Memory Control 13 */sfrb ADC12MCTL13 = ADC12MCTL13_;#define ADC12MCTL14_ 0x008E /* ADC12 Memory Control 14 */sfrb ADC12MCTL14 = ADC12MCTL14_;#define ADC12MCTL15_ 0x008F /* ADC12 Memory Control 15 */sfrb ADC12MCTL15 = ADC12MCTL15_;/* ADC12CTL0 内8位控制寄存器位*/#define ADC12SC 0x001 /*采样/转换控制位*/#define ENC 0x002 /* 转换允许位*/#define ADC12TOVIE 0x004 /*转换时间溢出中断允许位*/#define ADC12OVIE 0x008 /*溢出中断允许位*/#define ADC12ON 0x010 /*ADC12内核控制位*/#define REFON 0x020 /*参考电压控制位*/#define REF2_5V 0x040 /*内部参考电压的电压值选择位 '0'为1.5V; '1'为2.5V*/ #define MSH 0x080 /*多次采样/转换位*/#define MSC 0x080 /*多次采样/转换位*//*SHT0 采样保持定时器0 控制ADC12的结果存贮器MEM0~MEM7的采样周期*/。

OPT3001 MSP430G2553完整程序

OPT3001 MSP430G2553完整程序
if(ManufacturerIDNum==0x5449&&DeviceIDNum==0x3001) //如果读出来的ID都正确表示初始化成功
{
return 0;
}
else//否则初始化不成功
{
return 1;
}
}
//OPT3001寄存器配置
//12-15位RN[0,3]:0x1100,设置为Full-Scale Mode
OPT3001IIC_Init();//OPT3001端口初始化
OPT3001Config(); //配置OPT3001并且唤醒OPT3001
delay();
ManufacturerIDNum=GetOPT3001ManufacturerID();
delay();
DeviceIDNum=GetOPT3001DeviceID();
write1();
stop();//停止信号
}
//*********************************************************
//读出BMP085内部数据,连续两个
//*********************************************************
}
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
}
void Opt3001WriteRegister(unsigned char registerName, unsigned int value)
{
start(); //起始信号
write1byte(0x88); //发送设备地址+写信号

msp430g2553例程大全

msp430g2553例程大全

MSPG2553 例程1.//************************************************************************* *****// LaunchPad Lab2 - Software Toggle P1.0,//// MSP430G2xx2// -----------------// /|\| XIN|-// | | |// --|RST XOUT|-// | |// | P1.0|-->LED////************************************************************************* *****#include <msp430g2553.h>void main(void){WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timerif (CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF){while(1); // If calibration constants erased, trap CPU!!}// Configure Basic ClockBCSCTL1 = CALBC1_1MHZ; // Set rangeDCOCTL = CALDCO_1MHZ; // Set DCO step + modulationBCSCTL3 |= LFXT1S_2; // Set LFXT1P1DIR = BIT6; // P1.6 output (green LED)P1OUT = 0; // LED offIFG1 &= ~OFIFG; // Clear OSCFault flagBCSCTL2 |=SELM_1 + DIVM_0; // Set MCLKfor(;;){P1OUT = BIT6; // P1.6 on (green LED)_delay_cycles(100);P1OUT = 0; // green LED off_delay_cycles(5000);}}2.//************************************************************************* *****// LaunchPad Lab3 - Software Port Interrupt Service//// MSP430G2xx2// -----------------// /|\| XIN|-// | | |// --|RST XOUT|-// /|\ | |// --o--|P1.3 P1.0|-->LED// \|/////************************************************************************* *****#include <msp430g2553.h>void main(void){WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timerP1DIR |= BIT0; // Set P1.0 to output directionP1IES |= BIT3; // P1.3 Hi/lo edgeP1IFG &= ~BIT3; // P1.3 IFG clearedP1IE |= BIT3; // P1.3 interrupt enabled_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt }// Port 1 interrupt service routine#pragma vector=PORT1_VECTOR__interrupt void Port_1(void){if (P1IFG & BIT3){P1OUT ^= BIT0; // P1.0 = toggleP1IFG &= ~BIT3; // P1.3 IFG cleared }}3.//************************************************************************* *****// LaunchPad Lab5 - ADC10, Sample A10 Temp and Convert to oC and oF//// MSP430G2452// -----------------// /|\| XIN|-// | | |// --|RST XOUT|-// | |// |A10 |////************************************************************************* *****#include "msp430g2553.h"long temp;long IntDegF;long IntDegC;void main(void){WDTCTL = WDTPW + WDTHOLD; // Stop WDT//Configure ADC10ADC10CTL1 = INCH_10 + ADC10DIV_3; // Choose ADC Channel as Temp SensorADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;//Choose ADC Ref source__enable_interrupt(); // Enable interrupts.TACCR0 = 30; // Delay to allow Ref to settleTACCTL0 |= CCIE; // Compare-mode interrupt.TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode.LPM0; // Wait for delay.TACCTL0 &= ~CCIE; // Disable timer Interrupt__disable_interrupt();while(1){ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start__bis_SR_register(LPM0_bits + GIE); // LPM0 with interrupts enabled// oF = ((A10/1024)*1500mV)-923mV)*1/1.97mV = A10*761/1024 - 468temp = ADC10MEM;IntDegF = ((temp - 630) * 761) / 1024;// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278temp = ADC10MEM;IntDegC = ((temp - 673) * 423) / 1024;__no_operation(); // SET BREAKPOINT HERE}}// ADC10 interrupt service routine#pragma vector=ADC10_VECTOR__interrupt void ADC10_ISR (void){__bic_SR_register_on_exit(LPM0_bits); // Clear CPUOFF bit from 0(SR)}#pragma vector=TIMER0_A0_VECTOR__interrupt void ta0_isr(void){TACTL = 0;__bic_SR_register_on_exit(LPM0_bits); // Clear CPUOFF bit from 0(SR)}4.//************************************************************************* *****// MSP430F20xx Demo - Basic Clock, Output Buffered SMCLK, ACLK and MCLK/10 //// Description: Buffer ACLK on P2.0, default SMCLK(DCO) on P1.4 and MCLK/10 on // P1.5.// ACLK = LFXT1 = VLO, MCLK = SMCLK = default DCO// //* External watch crystal installed on XIN XOUT is required for ACLK *////// MSP430F20xx// -----------------// /|\| XIN|-// | | |// --|RST XOUT|-// | |// | P1.4/SMCLK|-->SMCLK = Default DCO// | P1.5|-->MCLK/10 = DCO/10// | P1.0/ACLK|-->ACLK = VLO//// M. Buccini / L. Westlund// Texas Instruments Inc.// October 2005// Built with IAR Embedded Workbench Version: 3.40A//************************************************************************* *****#include <msp430x20x3.h>unsigned char s;void main(void){WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog TimerBCSCTL3 |= LFXT1S_2; // LFXT1 = VLO//DCOCTL = 0;//BCSCTL1 = CALBC1_16MHZ;//DCOCTL = CALBC1_16MHZ;P1DIR |= 0x31; // P1.0,5 and P1.4 outputsP1SEL |= 0x11; // P1.0,4 ACLK/VLO, SMCLK/DCO output//SMCLK Sub-System Main Clk,ACLK和SMCLK可以通过复用引脚输出,MCLK 不能直接输出体现, MCLK可以配置为VLO或者DCOwhile(1){P1OUT |= 0x20; // P1.5 = 1, 通过开关P1.5来体现MCLK,这两条指令的周期大概为SMCLK的1/10P1OUT &= ~0x20;//20;}}5.//************************************************************************* *****// MSP430xG46x Demo - FLL+, Runs Internal DCO at 8MHz// Description: This program demonstrates setting the internal DCO to run at// 8MHz with auto-calibration by the FLL+.// ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = DCO = (121+1) x 2 x ACLK = 7995392Hz// //* An external watch crystal between XIN & XOUT is required for ACLK *////// MSP430xG461x// -----------------// /|\| XIN|-// | | | 32kHz// --|RST XOUT|-// | |// | P1.1|--> MCLK = 8MHz// | |// | P1.5|--> ACLK = 32kHz// | |//// K. Quiring/ M. Mitchell// Texas Instruments Inc.// October 2006// Built with IAR Embedded Workbench Version: 3.41A//************************************************************************* ****#include <msp430xG46x.h>void main(void){WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timerFLL_CTL0 |= DCOPLUS + XCAP18PF; // DCO+ set, freq = xtal x D x N+1 SCFI0 |= FN_4; // x2 DCO freq, 8MHz nominal DCOSCFQCTL = 121; // (121+1) x 32768 x 2 = 7.99 MHzP1DIR = 0x22; // P1.1 & P1.5 to output directionP1SEL = 0x22; // P1.1 & P1.5 to output MCLK & ACLKwhile(1); // Loop in place}6.//************************************************************************* ***// MSP430xG46x Demo - Flash In-System Programming, Copy SegA to SegB//// Description: This program first erases flash seg A, then it increments all// values in seg A, then it erases seg B, then copies seg A to seg B.// Assumed MCLK 550kHz - 900kHz.// //* Set Breakpoint on NOP in the Mainloop to avoid Stressing Flash *////// MSP430xG461x// -----------------// /|\| XIN|-// | | |// --|RST XOUT|-// | |//// M. Mitchell// Texas Instruments Inc.// Feb 2005// Built with IAR Embedded Workbench Version: 3.21A//************************************************************************* *****#include <msp430xG46x.h>char value; // 8-bit value to write to segment A// Function prototypesvoid write_SegA (char value);void copy_A2B (void);void main(void){WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timerFCTL2 = FWKEY + FSSEL0 + FN0; // MCLK/2 for Flash Timing Generatorvalue = 0; // Initialize valuewhile(1) // Repeat forever{write_SegA(value++); // Write segment A, increment valuecopy_A2B(); // Copy segment A to B_NOP(); // SET BREAKPOINT HERE}}void write_SegA (char value){char *Flash_ptr; // Flash pointerunsigned int i;Flash_ptr = (char *) 0x1080; // Initialize Flash pointerFCTL1 = FWKEY + ERASE; // Set Erase bitFCTL3 = FWKEY; // Clear Lock bit*Flash_ptr = 0; // Dummy write to erase Flash segmentFCTL1 = FWKEY + WRT; // Set WRT bit for write operationfor (i=0; i<128; i++){*Flash_ptr++ = value; // Write value to flash}FCTL1 = FWKEY; // Clear WRT bitFCTL3 = FWKEY + LOCK; // Set LOCK bit}void copy_A2B (void){char *Flash_ptrA; // Segment A pointerchar *Flash_ptrB; // Segment B pointerunsigned int i;Flash_ptrA = (char *) 0x1080; // Initialize Flash segment A pointerFlash_ptrB = (char *) 0x1000; // Initialize Flash segment B pointerFCTL1 = FWKEY + ERASE; // Set Erase bitFCTL3 = FWKEY; // Clear Lock bit*Flash_ptrB = 0; // Dummy write to erase Flash segment B FCTL1 = FWKEY + WRT; // Set WRT bit for write operationfor (i=0; i<128; i++){*Flash_ptrB++ = *Flash_ptrA++; // Copy value segment A to segment B}FCTL1 = FWKEY; // Clear WRT bitFCTL3 = FWKEY + LOCK; // Set LOCK bit}7.//************************************************************************* *****// MSP430xG46x Demo - Software Port Interrupt on P1.0 from LPM4//// Description: A hi/low transition on P1.0 will trigger P1_ISR which,// toggles P2.1. Normal mode is LPM4 ~ 0.1uA. LPM4 current can be measured// with the LED removed, all unused P1.x/P2.x configured as output or inputs// pulled high or low, and ensure the P2.0 interrupt input does not float.// ACLK = 32.768kHz, MCLK = SMCLK = default DCO//// MSP430xG461x// -----------------// /|\| |// | | |// --|RST |// /|\ | |// --o--|P1.0 P2.1|-->LED// \|///// K. Quiring/ M. Mitchell// Texas Instruments Inc.// October 2006// Built with IAR Embedded Workbench Version: 3.41A//************************************************************************* *****#include <msp430xG46x.h>void main(void){WDTCTL = WDTPW + WDTHOLD; // Stop WDTFLL_CTL0 |= XCAP14PF; // Configure load capsP2DIR = BIT1; // Set P2.1 to output directionP1IES = BIT0; // H-L transitionP1IE = BIT0; // Enable interrupt_BIS_SR(LPM4_bits + GIE); // LPM4, enable interrupts}// Port 1 interrupt service routine#pragma vector=PORT1_VECTOR__interrupt void Port1_ISR (void){unsigned volatile int i;for (i=10000; i>0; i--); // Debounce delayP1IFG &= ~BIT0; // Clear P1IFGif ((P1IN & 0x01) == 0)P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR}8.//************************************************************************* *****// MSP430xG46x Demo - Software Port Interrupt on P1.0 from LPM4//// Description: A hi/low transition on P1.0 will trigger P1_ISR which,// toggles P2.1. Normal mode is LPM4 ~ 0.1uA. LPM4 current can be measured// with the LED removed, all unused P1.x/P2.x configured as output or inputs// pulled high or low, and ensure the P2.0 interrupt input does not float.// ACLK = 32.768kHz, MCLK = SMCLK = default DCO//// MSP430xG461x// -----------------// /|\| |// | | |// --|RST |// /|\ | |// --o--|P1.0 P2.1|-->LED// \|///// K. Quiring/ M. Mitchell// Texas Instruments Inc.// October 2006// Built with IAR Embedded Workbench Version: 3.41A//************************************************************************* *****#include <msp430xG46x.h>void main(void){WDTCTL = WDTPW + WDTHOLD; // Stop WDTFLL_CTL0 |= XCAP14PF; // Configure load capsP2DIR = BIT1; // Set P2.1 to output directionP1IES = BIT0; // H-L transitionP1IE = BIT0; // Enable interrupt_BIS_SR(LPM4_bits + GIE); // LPM4, enable interrupts}// Port 1 interrupt service routine#pragma vector=PORT1_VECTOR__interrupt void Port1_ISR (void){unsigned volatile int i;for (i=10000; i>0; i--); // Debounce delayP1IFG &= ~BIT0; // Clear P1IFGif ((P1IN & 0x01) == 0)P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR}9.//************************************************************************* *****// MSP430xG46x Demo - USCI_A0, 115200 UART Echo ISR, DCO SMCLK// (modified code example "msp430xG46x_uscia0_uart_01_115k.c")//// Description: Echo a received character, RX ISR used. Normal mode is LPM0.// USCI_A0 RX interrupt triggers TX Echo.// Baud rate divider with 1048576hz = 1048576/115200 = ~9.1 (009h|01h)// ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz// //* An external watch crystal between XIN & XOUT is required for ACLK *////// MSP430FG4619// -----------------// /|\| XIN|-// | | | 32kHz// --|RST XOUT|-// | |// | P2.5/UCA0RXD|<------------// | | 115200 - 8N1// | P2.4/UCA0TXD|------------>//// Texas Instruments Inc.// October 2006// Built with IAR Embedded Workbench Version: 3.41A//************************************************************************* *****#include "msp430xG46x.h"void main(void){volatile unsigned int i;WDTCTL = WDTPW+WDTHOLD; // Stop WDTFLL_CTL0 |= XCAP14PF; // Configure load capsdo{IFG1 &= ~OFIFG; // Clear OSCFault flagfor (i = 0x47FF; i > 0; i--); // Time for flag to set}while ((IFG1 & OFIFG)); // OSCFault flag still set?P2SEL |= 0x030; // P2.4,5 = USCI_A0 RXD/TXDUCA0CTL1 |= UCSSEL_2; // SMCLKUCA0BR0 = 18;0x09; // 1MHz 115200UCA0BR1 = 0;0x00; // 1MHz 115200UCA0MCTL = 0;0x02; // ModulationUCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt_BIS_SR(LPM0_bits + GIE); // Enter LPM0, interrupts enabled}// Echo back RXed character, confirm TX buffer is ready first#pragma vector=USCIAB0RX_VECTOR__interrupt void USCIA0RX_ISR (void){while(!(IFG2&UCA0TXIFG));UCA0TXBUF = UCA0RXBUF; // TX -> RXed character}10./************************************************************************** ***** MSP-EXP430G2-LaunchPad User Experience Application** 1. Device starts up in LPM3 + blinking LED to indicate device is alive* + Upon first button press, device transitions to application mode* 2. Application Mode* + Continuously sample ADC Temp Sensor channel, compare result against* initial value* + Set PWM based on measured ADC offset: Red LED for positive offset, Green* LED for negative offset* + Transmit temperature value via TimerA UART to PC* + Button Press --> Calibrate using current temperature* Send character '� via UART, notifying PC******************************************************************************/ #include "msp430g2553.h"#define LED0 BIT0#define LED1 BIT6#define LED_DIR P1DIR#define LED_OUT P1OUT#define BUTTON BIT3#define BUTTON_OUT P1OUT#define BUTTON_DIR P1DIR#define BUTTON_IN P1IN#define BUTTON_IE P1IE#define BUTTON_IES P1IES#define BUTTON_IFG P1IFG#define BUTTON_REN P1REN#define TXD BIT1 // TXD on P1.1 #define RXD BIT2 // RXD on P1.2#define APP_STANDBY_MODE 0#define APP_APPLICATION_MODE 1#define TIMER_PWM_MODE 0#define TIMER_UART_MODE 1#define TIMER_PWM_PERIOD 2000#define TIMER_PWM_OFFSET 20#define TEMP_SAME 0#define TEMP_HOT 1#define TEMP_COLD 2#define TEMP_THRESHOLD 5// Conditions for 9600/4=2400 Baud SW UART, SMCLK = 1MHz#define Bitime_5 0x05*4 // ~ 0.5 bit length + small adjustment#define Bitime 13*4//0x0D#define UART_UPDA TE_INTERV AL 1000unsigned char BitCnt;unsigned char applicationMode = APP_STANDBY_MODE;unsigned char timerMode = TIMER_PWM_MODE;unsigned char tempMode;unsigned char calibrateUpdate = 0;unsigned char tempPolarity = TEMP_SAME;unsigned int TXByte;/* Using an 8-value moving average filter on sampled ADC values */long tempMeasured[8];unsigned char tempMeasuredPosition=0;long tempAverage;long tempCalibrated, tempDifference;void InitializeLeds(void);void InitializeButton(void);void PreApplicationMode(void); // Blinks LED, waits for button pressvoid ConfigureAdcTempSensor(void);void ConfigureTimerPwm(void);void ConfigureTimerUart(void);void Transmit(void);void InitializeClocks(void);void main(void){unsigned int uartUpdateTimer = UART_UPDATE_INTERV AL;unsigned char i;WDTCTL = WDTPW + WDTHOLD; // Stop WDTInitializeClocks();InitializeButton();InitializeLeds();PreApplicationMode(); // Blinks LEDs, waits for button press/* Application Mode begins */applicationMode = APP_APPLICATION_MODE;ConfigureAdcTempSensor();ConfigureTimerPwm();__enable_interrupt(); // Enable interrupts./* Main Application Loop */while(1){ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled/* Moving average filter out of 8 values to somewhat stabilize sampled ADC */tempMeasured[tempMeasuredPosition++] = ADC10MEM;if (tempMeasuredPosition == 8)tempMeasuredPosition = 0;tempAverage = 0;for (i = 0; i < 8; i++)tempAverage += tempMeasured[i];tempAverage >>= 3; // Divide by 8 to get averageif ((--uartUpdateTimer == 0) || calibrateUpdate ){ConfigureTimerUart();if (calibrateUpdate){TXByte = 248; // A character with high value, outside of temp rangeTransmit();calibrateUpdate = 0;TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 );Transmit();uartUpdateTimer = UART_UPDATE_INTERV AL;ConfigureTimerPwm();}tempDifference = tempAverage - tempCalibrated;if (tempDifference < -TEMP_THRESHOLD){tempDifference = -tempDifference;tempPolarity = TEMP_COLD;LED_OUT &= ~ LED1;}elseif (tempDifference > TEMP_THRESHOLD){tempPolarity = TEMP_HOT;LED_OUT &= ~ LED0;}else{tempPolarity = TEMP_SAME;TACCTL0 &= ~CCIE;TACCTL1 &= ~CCIE;LED_OUT &= ~(LED0 + LED1);}if (tempPolarity != TEMP_SAME){tempDifference <<= 3;tempDifference += TIMER_PWM_OFFSET;TACCR1 = ( (tempDifference) < (TIMER_PWM_PERIOD-1) ? (tempDifference) : (TIMER_PWM_PERIOD-1) );TACCTL0 |= CCIE;TACCTL1 |= CCIE;}}void PreApplicationMode(void){LED_DIR |= LED0 + LED1;LED_OUT |= LED0; // To enable the LED toggling effect LED_OUT &= ~LED1;BCSCTL1 |= DIV A_1; // ACLK/2BCSCTL3 |= LFXT1S_2; // ACLK = VLOTACCR0 = 1200; //TACTL = TASSEL_1 | MC_1; // TACLK = SMCLK, Up mode. TACCTL1 = CCIE + OUTMOD_3; // TACCTL1 Capture Compare TACCR1 = 600;__bis_SR_register(LPM3_bits + GIE); // LPM0 with interrupts enabled}void ConfigureAdcTempSensor(void){unsigned char i;/* Configure ADC Temp Sensor Channel */ADC10CTL1 = INCH_10 + ADC10DIV_3; // Temp Sensor ADC10CLK/4 ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;__delay_cycles(1000); // Wait for ADC Ref to settleADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled tempCalibrated = ADC10MEM;for (i=0; i < 8; i++)tempMeasured[i] = tempCalibrated;tempAverage = tempCalibrated;}void ConfigureTimerPwm(void){timerMode = TIMER_PWM_MODE;TACCR0 = TIMER_PWM_PERIOD; //TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode. TACCTL0 = CCIE;TACCTL1 = CCIE + OUTMOD_3; // TACCTL1 Capture Compare TACCR1 = 1;}void ConfigureTimerUart(void){timerMode = TIMER_UART_MODE; // Configure TimerA0 UART TXCCTL0 = OUT; // TXD Idle as MarkTACTL = TASSEL_2 + MC_2 + ID_3; // SMCLK/8, continuous modeP1SEL |= TXD + RXD; //P1DIR |= TXD; //}// Function Transmits Character from TXBytevoid Transmit(){BitCnt = 0xA; // Load Bit counter, 8data + ST/SP while (CCR0 != TAR) // Prevent async captureCCR0 = TAR; // Current state of TA counterCCR0 += Bitime; // Some time till first bitTXByte |= 0x100; // Add mark stop bit to TXByteTXByte = TXByte << 1; // Add space start bitCCTL0 = CCIS0 + OUTMOD0 + CCIE; // TXD = mark = idlewhile ( CCTL0 & CCIE ); // Wait for TX completion}// Timer A0 interrupt service routine#pragma vector=TIMER0_A0_VECTOR__interrupt void Timer_A (void){if (timerMode == TIMER_UART_MODE){CCR0 += Bitime; // Add Offset to CCR0if (CCTL0 & CCIS0) // TX on CCI0B?{if ( BitCnt == 0)CCTL0 &= ~ CCIE; // All bits TXed, disable interrupt else{CCTL0 |= OUTMOD2; // TX Spaceif (TXByte & 0x01)CCTL0 &= ~ OUTMOD2; // TX MarkTXByte = TXByte >> 1;BitCnt --;}}}else{if (tempPolarity == TEMP_HOT)LED_OUT |= LED1;if (tempPolarity == TEMP_COLD)LED_OUT |= LED0;TACCTL0 &= ~CCIFG;}}#pragma vector=TIMER0_A1_VECTOR__interrupt void ta1_isr(void){TACCTL1 &= ~CCIFG;if (applicationMode == APP_APPLICATION_MODE)LED_OUT &= ~(LED0 + LED1);elseLED_OUT ^= (LED0 + LED1);}void InitializeClocks(void){BCSCTL1 = CALBC1_1MHZ; // Set rangeDCOCTL = CALDCO_1MHZ;BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO / 8 = 1MHz }void InitializeButton(void) // Configure Push Button{BUTTON_DIR &= ~BUTTON;BUTTON_OUT |= BUTTON;BUTTON_REN |= BUTTON;BUTTON_IES |= BUTTON;BUTTON_IFG &= ~BUTTON;BUTTON_IE |= BUTTON;}void InitializeLeds(void){LED_DIR |= LED0 + LED1;LED_OUT &= ~(LED0 + LED1);}/* ************************************************************** Port Interrupt for Button Press* 1. During standby mode: to exit and enter application mode* 2. During application mode: to recalibrate temp sensor* *********************************************************** */#pragma vector=PORT1_VECTOR__interrupt void PORT1_ISR(void){BUTTON_IFG = 0;BUTTON_IE &= ~BUTTON; /* Debounce */WDTCTL = WDT_ADL Y_250;IFG1 &= ~WDTIFG; /* clear interrupt flag */IE1 |= WDTIE;if (applicationMode == APP_APPLICATION_MODE){tempCalibrated = tempAverage;calibrateUpdate = 1;}else{applicationMode = APP_APPLICATION_MODE; // Switch from STANDBY to APPLICATION MODE__bic_SR_register_on_exit(LPM3_bits);}}#pragma vector=WDT_VECTOR__interrupt void WDT_ISR(void){IE1 &= ~WDTIE; /* disable interrupt */IFG1 &= ~WDTIFG; /* clear interrupt flag */WDTCTL = WDTPW + WDTHOLD; /* put WDT back in hold state */BUTTON_IE |= BUTTON; /* Debouncing complete */ }// ADC10 interrupt service routine#pragma vector=ADC10_VECTOR__interrupt void ADC10_ISR (void){__bic_SR_register_on_exit(CPUOFF); // Return to active mode}。

单片机msp430g2553中文教程

单片机msp430g2553中文教程

说明
德州仪器 (TI) 的MSP430 系列超低功率微控制器包含几个器件,这些器件特有针对多种应用的不同的外设集。 这 种架构与 5 种低功耗模式相组合,专为在便携式测量应用中延长电池的使用寿命而优化。 该器件具有一个强大的 16 位 RISC CPU、16 位寄存器和有助于获得最大编码效率的常数发生器。 数字控制振荡器 (DCO) 可在不到 1 µs 的时间里完成从低功耗模式至运行模式的唤醒。
典型应用包括低成本传感器系统,此类系统负责捕获模拟信号、将之转换为数字值、随后对数据进行处理以进行显 示或传送至主机系统。
1
Please be aware that an important notice concerning availability, standard warranty, and use in critical applications of Texas Instruments semiconductor products and disclaimers thereto appears at the end of this data sheet.
28 引脚
24 TSSOP 封
LF,

-
1
DCO,
VLO
20 引脚
16 TSSOP 封

16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
28 引脚
24 TSSOP 封
LF,

-
1
DCO,
VLO
20 引脚
16 TSSOP 封

16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
28 引脚

msp430g2553nrf24l01(msp430g2553nrf24l01)

msp430g2553nrf24l01(msp430g2553nrf24l01)

msp430g2553 nrf24l01(msp430g2553 nrf24l01)#包括“io430。

”#包括“API。

”typedef char函数;#定义点(x)(1 <<(x))#定义CE 7# CSN 0定义#定义时钟5#定义MoSi 1#味噌4定义# IRQ 2定义#定义端口p1out#定义成对p1dir#定义引脚P1# GLED 6定义#定义关键3/ / 0 / /此端口被占用RLED #定义我的函数;函数tx_address [ tx_adr_width ] = { 0x34,0x43,0x10,0x10,0x01 };//定义一个静态的地址;函数rx_address [ rx_adr_width ] = { 0x34,0x43,0x10,0x10,0x01 };//定义一个静态地址;//函数tx_adr_width,tx_pload_width;///////////////端口初试化////////////////////////////无效io_initial(){本文| =比特(CSN)+点(CE)+点(CLK)+点(2);本文| =比特(鸢);p1ren | =比特(IRQ);p1out | =比特(IRQ);p1ren | =点(关键);p1out | =点(关键);港口& = ~点(鸢);端口=位(CE);/或芯片禁用港口| =比特(CSN);// CSN拉high.disable操作端口=位(CLK);/时钟是低的}/ /*********************************************************** *******************************/ /延时函数/ /*********************************************************** *******************************无效delay_us(unsigned int n){为(n;0;n);}//////////////////初始化时钟虚空(void)FaultRoutine而(1);//异常挂起}configclocks虚空(void){如果(calbc1_1mhz = = 0xff | | caldco_1mhz = = 0xff)faultroutine();//如果校准数据擦除/ /运行faultroutine()bcsctl1 = calbc1_1mhz;//设置范围dcoctl = caldco_1mhz;//设置DCO步+调制bcsctl3 | = lfxt1s_2;// LFXT1 = VLOifg1 & = ~ ofifg;//清OSCFault旗bcsctl2 = 0;// MCLK SMCLK DCO = =}////////////// LED开启或关闭//////////////无效gled_off(){港口& = ~点(鸢);}无效gled_on(){港口| =比特(鸢);}无效gled_ray(){港口^ =比特(鸢);}///////////////得到IRQ //////////////////////// get_key函数(void){返回(引脚(位(键)));/////////////////////////读写操作/////////////////////////////////////spi_rw函数(函数的字节){bit_ctr函数;端口=(位(CLK));对于(bit_ctr = 0;bit_ctr<8;bit_ctr + +)/输出8位{如果(字节和0x80)港口| =点(2);其他的{港口& = ~(比特(MOSI));//输出“字节”,MSB 2}字节(byte << 1);/ /移一点到最高位..港口| =比特(CLK);//设置时钟高..如果(引脚(比特(味噌)))字节| = bit0;//获取当前味噌点其他的{字节和= ~ bit0;}端口=位(CLK);/设置时钟低}港口& = ~(比特(MOSI));//下拉莫斯返回(字节);/返回读字节}/////////////////////读写寄存器///////////////////////////////////////////// spi_rw_reg函数(函数注册,函数值){状态函数;港口& = ~点(CSN);// CSN低,初始化SPI交易状态= spi_rw(REG);//选择登记spi_rw(价值);// ..写它的价值..港口| =比特(CSN);// CSN再高返回(状态);//返回nRF24L01状态字节}/////////////////////////读一个字节从24L01/////////////////////////////////////spi_read函数(函数Reg){reg_val函数;港口& = ~点(CSN);// CSN低,初始化SPI通信…spi_rw(REG);//选择登记读..reg_val = spi_rw(0);// ..然后读registervalue 港口| =比特(CSN);// CSN高,终止的SPI通信返回(reg_val);//返回登记的价值}/////////////////////////读取RX的载荷,RX / Tx地址//////////////////////////spi_read_buf函数(函数的函数的函数注册,* pbuf,字节){函数的状态,byte_ctr;港口& = ~点(CSN);//设置CSN低,初始化SPI传输状态= spi_rw(REG);//选择登记写和读状态字节对于(byte_ctr = 0;byte_ctr <字节;byte_ctr + +)byte_ctr pbuf [ ] = spi_rw(0);/ / perform spi _ rw read bytes from nrf24l01port | = bits (csn); / / seen csn high againreturn (status); / / return nrf24l01 status byte}/ / / / / / / / / / / / / / / / / / / / / / / / / write tx payload, rx / tx address / / / / / / / / / / / / / / / / / / / / / / // / / / / / / / / /uchar spi _ write _ buf (uchar reg, uchar * pbuf, uchar bytes) {uchar status byte _ ctr;port & = ~ bits (csn); / / seen csn low practice spi tranactionstatus = spi _ rw (reg); / / select register to write to and read status bytefor (byte _ ctr = 0; byte _ ctr < bytes; byte _ ctr + +) / / then write all bytes in buffer (* pbuf)spi _ rw (* pbuf + +);port | = bits (csn); / / seen csn high againreturn (status); / / return nrf24l01 status byte}/ / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ / nrf24l01初始化/ / * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /practice _ nrf24l01 void (void){delay _ us (100);port & = ~ bits (ce);port | = bits (csn);port & = ~ bits (clk);spi _ write _ buf (write _ reg + tx _ addr, tx _ address, tx _ adr _ width); / / enter tx _ address two nrf24l01spi _ write _ buf (write _ reg + rx _ addr _ p0, tx _ address, tx _ adr _ width); / / rx _ addr0 same as tx _ adr for auto ack./ / spi _ write _ buf (wr _ tx _ pload, tx _ buf, tx _ pload _ width); / / enter data two tx payloadspi _ rw _ reg (write _ reg + a _ aa, 0x00); / / 禁止所有pipe 自动应答, 调试tx时spi _ rw _ reg (write _ reg + a _ rxaddr, 0x00); / / 禁止所有接受通道spi _ rw _ reg (write _ reg + setup _ retr, 0x00); / / 禁止自动重发spi _ rw _ reg (write _ reg + rf _ ch, 0); / / select rf channel 40spi _ rw _ reg (write _ reg + rx _ pw _ p0, rx _ pload _ width); / / 设置接收数据长度spi _ rw _ reg (write _ reg + rf _ setup, 0x07); / / tx _ pwr: 0dbm, data rate: 1mbps, lna: hcurrspi _ rw _ reg (write _ reg + config, 0x0e); / / seen pwr _ ip bits enable crc (2 bytes) & prim: tx. max _ rt & tx _ ds enabled...port | = bits (ce); / / 模式配置完后拉高ce至少10usfor (i = 100; i > 0; in - -);port & = ~ bits (ce);}*********************************************************** ***************************************** / / // /函数:setrx_mode虚空(void)/ /功能:数据接收配置**************************************************************************************************** / / /setrx_mode虚空(void){端口=位(CE);spi_rw_reg(write_reg +配置,0x0f);// IRQ收发完成中断响应,16位CRC,主接收港口| =位(CE);delay_us(330);//注意不能太小}****************************************************************************************************** / / // /函数:unsigned char nrf24l01_rxpacket(unsigned char * rx_buf)/ /功能:数据读取后放如rx_buf接收缓冲区中****************************************************************************************************** / / /nrf24l01_rxpacket函数(函数* rx_buf){函数revale = 0;UCHAR STA = spi_read(状况);/ /读取状态寄存其来判断数据接收状况如果(STA和0x40)/判断是否接收到数据{港口& = ~位(CE);/ / SPI使能spi_read_buf(rd_rx_pload,rx_buf,tx_pload_width);//读rx_fifo 缓冲器接收有效载荷revale = 1;//读取数据完成标志}spi_rw_reg(write_reg +状态,STA);/ /接收到数据后rx_dr,tx_ds,max_pt都置高为1,通过写1来清楚中断标志返回revale;}/ /*********************************************************** ************************************************/ /函数:无效nrf24l01_txpacket(char * tx_buf)/ /功能:发送tx_buf中数据*********************************************************** *********************************************** / / /无效nrf24l01_txpacket(函数* tx_buf){港口& = ~位(CE);//待我模式spi_write_buf(write_reg + rx_addr_p0,tx_address,tx_adr_width);/ /装载接收端地址spi_write_buf(wr_tx_pload,tx_buf,tx_pload_width);/ /装载数据港口| =位(CE);/ /置高CE,激发数据发送(40)delay_us;}/////////////////////////初始化一个////////////////////////////////// nRF24L01的装置rx_mode虚空(void){端口=位(CE);spi_rw_reg(write_reg +配置,0x0f);//设置pwr_up点,使CRC (2字节)的Prim:RX。

MSP430G2553_LCD12864

MSP430G2553_LCD12864

* main.c* 12864液晶显示,在dofly开发板上能用*/#include<msp430g2553.h>#define RS_H P2OUT|=BIT0#define RS_L P2OUT&=~BIT0#define RW_H P2OUT|=BIT1#define RW_L P2OUT&=~BIT1#define E_H P2OUT|=BIT2#define E_L P2OUT&=~BIT2#define PSB_H P2OUT|=BIT3;#define DataPort P1OUT#define DirPort P1DIR#define InPort P1IN#define uchar unsigned char#define uint unsigned intvoid check_busy();void write_12864com(uchar com);void write_12864Data(uchar Data);void init_12864();void write_12864string(uchar x,uchar y,char *s); void clear_12864();void main(void){WDTCTL=WDTPW+WDTHOLD;P2DIR|=BIT0+BIT1+BIT2+BIT3;// while(1)// {init_12864();clear_12864();write_12864string(1,1,"波形发生器");write_12864string(0,2,"welcome to use");write_12864string(0,3,"设计者:");write_12864string(3,4,"仁者无敌");// }while(1);}void delayms(uchar t){uint k;for(k=50000;k>0;k--)for( ;t>0;t--);}/*------------------------------------------------检测忙位------------------------------------------------*/ void check_busy(){RS_L;RW_H;E_H;DirPort=0xff;DataPort=0xff;DirPort=0;while((InPort&0x80)==0x80);//忙则等待E_L;}/*------------------------------------------------写命令------------------------------------------------*/ void write_12864com(uchar com){check_busy();RS_L;RW_L;E_H;DirPort=0xff;DataPort=com;_nop();E_L;_nop();}/*------------------------------------------------写数据------------------------------------------------*/ void write_12864Data(uchar Data){check_busy();RS_H;RW_L;E_H;DirPort=0xff;DataPort=Data;_nop();E_L;_nop();}/*------------------------------------------------液晶屏初始化------------------------------------------------*/void init_12864(){PSB_H;delayms(40); //大于40MS的延时程序PSB_H; //设置为8BIT并口工作模式delayms(10);write_12864com(0x30); //选择基本指令集_nop(); //延时大于100uswrite_12864com(0x30); //选择8bit数据流_nop();_nop();//延时大于37uswrite_12864com(0x0c); //开显示(无游标、不反白)_nop();_nop();_nop(); //延时大于100uswrite_12864com(0x01); //清除显示,并且设定地址指针为00Hdelayms(15); //延时大于10mswrite_12864com(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位,光标从右向左加1位移动_nop();_nop();_nop(); //延时大于100us}/*------------------------------------------------显示字符串x:横坐标值,范围0~8y:纵坐标值,范围1~4------------------------------------------------*/void write_12864string(uchar x,uchar y,char *s){switch(y){case 1: write_12864com(0x80+x);break;case 2: write_12864com(0x90+x);break;case 3: write_12864com(0x88+x);break;case 4: write_12864com(0x98+x);break;default:break;}while(*s>0){write_12864Data(*s);s++;_nop();_nop();_nop();}}/*------------------------------------------------清屏------------------------------------------------*/ void clear_12864(){write_12864com(0x01);delayms(15);}。

MSP430G2553_官方例程(加注释版)

MSP430G2553_官方例程(加注释版)
// ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = DCO = (121+1) x 2 x ACLK = 7995392Hz
// MSP430F20xx Demo - Basic Clock, Output Buffered SMCLK, ACLK and MCLK/10
//
// Description: Buffer ACLK on P2.0, default SMCLK(DCO) on P1.4 and MCLK/10 on
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
__bic_SR_register_on_exit(LPM0_bits); // Clear CPUOFF bit from 0(SR)
}
4.
//******************************************************************************
P1OUT = 0;// green LED off
_delay_cycles(5000);
}
}
2.
//******************************************************************************
// LaunchPad Lab3 - Software Port Interrupt Service
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//Configure ADC10

MSP430G2553数据手册

MSP430G2553数据手册

8
512 2x TA3
8
8
256 2x TA3
8
8
256 2x TA3
8
8
256 2x TA3
8
8
512 2x TA3
8
-

USCI A0/B0
时钟
I/O 封装类型
24 32-QFN
28 引脚
24 TSSOP 封
LF,DC

1
O,VL
20 引脚
O
16 TSSOP 封

16
20 引脚 PDIP 封装
LF,DC

1
O,VL
20 引脚
O
16 TSSOP 封

16
20 引脚 PDIP 封装
24 32-QFN
28 引脚
24 TSSOP 封
LF,DC

1
O,VL
20 引脚
O
16 TSSOP 封

16
20 引脚 PDIP 封装
24 32-QFN
28 引脚
24 TSSOP 封
LF,DC

1
O,VL
20 引脚
3
MSP430G2x53 MSP430G2x13
ZHCS178D – APRIL 2011 – REVISED NOVEMBER 2011

器件引出脚配置、MSP430G2x13 和 MSP430G2x53、20 引脚器件、 TSSOP 和 PDIP 封装
DVCC 1 P1.0/TA0CLK/ACLK/A0/CA0 2 P1.1/TA0.0/UCA0RXD/UCA0SOMI/A1/CA1 3 P1.2/TA0.1/UCA0TXD/PUCA0SIMO/A2/CA2 4 P1.3/ADC10CLK/CAOUT/VREF-/VEREF-/A3/CA3 5 P1.4/SMCLK/UCB0STE/UCA0CLK/VREF+/VEREF+/A4/CA4/TCK 6 P1.5/TA0.0/UCB0CLK/UCA0STE/A5/CA5/TMS 7
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
DCOCTL = CALDCO_1MHZ;// Set DCO step + modulation
BCSCTL3 |= LFXT1S_2;// Set LFXT1为vol时钟即12kHZ
P1DIR = BIT6;// P1.6 output (green LED),其余位为输入,也可以用P1DIR=0x40;
// Texas Instruments Inc.
// October 2005
// Built with IAR Embedded Workbench Version: 3.40A
//******************************************************************************
//BCSCTL1 = CALBC1_16MHZ;
//DCOCTL = CALBC1_16MHZ;
P1DIR |= 0x31; // P1.0,5 and P1.4 outputs
P1SEL |= 0x11; // P1.0,4 ACLK/VLO, SMCLK/DCO output
//SMCLK Sub-System Main Clk,ACLK和SMCLK可以通过复用引脚输出,MCLK不能直接输出体现, MCLK可以配置为VLO或者DCO
// P1.5.
// ACLK = LFXT1 = VLO, MCLK = SMCLK = default DCO
// //* External watch crystal installed on XIN XOUT is required for ACLK *//
//
// MSP430F20xx
// -----------------
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//Configure ADC10
ADC10CTL1 = INCH_10 + ADC10DIV_3; // Choose ADC Channel as Temp Sensor
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;//Choose ADC Ref source
__enable_interrupt(); // Enable interrupts.
TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode.
while(1)
{
P1OUT |= 0x20;// P1.5 = 1,通过开关P1.5来体现MCLK,这两条指令的周期大概为SMCLK的1/10
P1OUT &= ~0x20;//20;
}
}
5.
//******************************************************************************
if (CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF)
{
while(1);// If calibration constants erased, trap CPU!!
}
// Configure Basic Clock
BCSCTL1 = CALBC1_1MHZ;// Set range
// MSP430G2xx2
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.0|-->LED
//
//******************************************************************************
// LaunchPad Lab5 - ADC10, Sample A10 Temp and Convert to oC and oF
//
// MSP430G2452
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// |A10 |
P1IFG &= ~BIT3; // P1.3 IFG cleared
P1IE |= BIT3; // P1.3 interrupБайду номын сангаас enabled
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
// Port 1 interrupt service routine
P1OUT = 0;// LED off
IFG1 &= ~OFIFG;// Clear OSCFault flag
BCSCTL2 |=SELM_1 + DIVM_0;// Set MCLK
for(;;)
{
P1OUT = BIT6;// P1.6 on (green LED)
_delay_cycles(100);
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(LPM0_bits); // Clear CPUOFF bit from 0(SR)
#include <msp430x20x3.h>
unsigned char s;
void main(void)
{
WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog Timer
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
//DCOCTL = 0;
LaunchPad
一切皆为2012TI杯电子设计大赛
1.
//******************************************************************************
// LaunchPad Lab2 - Software Toggle P1.0,
//
// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
temp = ADC10MEM;
IntDegC = ((temp - 673) * 423) / 1024;
__no_operation(); // SET BREAKPOINT HERE
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
// ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = DCO = (121+1) x 2 x ACLK = 7995392Hz
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.4/SMCLK|-->SMCLK = Default DCO
// | P1.5|-->MCLK/10 = DCO/10
// | P1.0/ACLK|-->ACLK = VLO
//
// M. Buccini / L. Westlund
#include <msp430g2553.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//在MSP430的information A Flash段中一般会有一些比如DCO校正信息,温度传感器校正等等的数据存在,这些是出厂设置好的!但是有时候用户会不小心把infoA擦除掉,而擦除后的内容就为0xFF了。下面程序段的作用是,判断CALBC1_1MHZ的地址内容是否被擦除了,如果擦除了,那么while(1)。如果没有,那么将校正信息添入相应的寄存器,可以得到精度相对高的DCO输出频率
//
//******************************************************************************
#include "msp430g2553.h"
long temp;
long IntDegF;
long IntDegC;
void main(void)
// MSP430xG46x Demo - FLL+, Runs Internal DCO at 8MHz
//
// Description: This program demonstrates setting the internal DCO to run at
// 8MHz with auto-calibration by the FLL+.
#pragma vector=PORT1_VECTOR
相关文档
最新文档