MSP430G2553学习笔记(数据手册)MSP430G2553性能参数(DIP-20)工作电压范围:1.8~3.6V。5种低功耗模式。16位的RISC结构,62.5ns指令周期。超低功耗:运行模式-230µA;待机模式-0.5µA;关闭模式-0.1µA;可以在不到1µs的时间里超快速地从待机模式唤醒。基本时钟模块配置:具有四种校准频率并高达16MHz的内部频率;内部超低功耗LF振荡器;32.768KHz晶体;外部数字时钟源。两个16位Timer_A,分别具有三个捕获/比较寄存器。用于模拟信号比较功能或者斜率模数(A/D)转换的片载比较器。带内部基准、采样与保持以及自动扫描功能的10位200-ksps模数(A/D)转换器。16KB闪存,512B的RAM。16个I/O口。注意:MSP430G2553无P3口!MSP430G2553的时钟基本时钟系统的寄存器DCOCTL-DCO控制寄存器DCOxDCO频率选择控制1MODxDCO频率校正选择,通常令MODx=0注意:在MSP430G2553上电复位后,默认RSEL=7,DCO=3,通过数据手册查得DCO频率大概在0.8~1.5MHz之间。BCSCTL1-基本时钟控制寄存器1XT2OFF不用管,因为MSP430G2553内部没有XT2提供的HF时钟XTS不用管,默认复位后的0值即可DIVAx设置ACLK的分频数00/101/210/411/8RSELxDCO频率选择控制2BCSCTL2-基本时钟控制寄存器2SELMxMCLK的选择控制位00DCOCLK01DCOCLK10LFXT1CLK或者VLOCLK11LFXT1CLK或者VLOCLKDIVMx设置MCLK的分频数00/101/210/411/8SELSSMCLK的选择控制位0DCOCLK1LFXT1CLK或者VLOCLKDIVSx设置SMCLK的分频数00/101/210/411/8DCORDCO直流发生电阻选择,此位一般设00内部电阻1外部电阻BCSCTL3-基本时钟控制寄存器3XT2Sx不用管LFXT1Sx00LFXT1选为32.768KHz晶振01保留10VLOCLK11外部数字时钟源XCAPxLFXT1晶振谐振电容选择001pF016pF1010pF1112.5pFmsp430g2553.h中基本时钟系统的内容/*************************************************************BasicClockModule************************************************************/#define__MSP430_HAS_BC2__/*DefinitiontoshowthatModuleisavailable*/SFR_8BIT(DCOCTL);/*DCOClockFrequencyControl*/SFR_8BIT(BCSCTL1);/*BasicClockSystemControl1*/SFR_8BIT(BCSCTL2);/*BasicClockSystemControl2*/SFR_8BIT(BCSCTL3);/*BasicClockSystemControl3*/#defineMOD0(0x01)/*ModulationBit0*/#defineMOD1(0x02)/*ModulationBit1*/#defineMOD2(0x04)/*ModulationBit2*/#defineMOD3(0x08)/*ModulationBit3*/#defineMOD4(0x10)/*ModulationBit4*/#defineDCO0(0x20)/*DCOSelectBit0*/#defineDCO1(0x40)/*DCOSelectBit1*/#defineDCO2(0x80)/*DCOSelectBit2*/#defineRSEL0(0x01)/*RangeSelectBit0*/#defineRSEL1(0x02)/*RangeSelectBit1*/#defineRSEL2(0x04)/*RangeSelectBit2*/#defineRSEL3(0x08)/*RangeSelectBit3*/#defineDIVA0(0x10)/*ACLKDivider0*/#defineDIVA1(0x20)/*ACLKDivider1*/#defineXTS(0x40)/*LFXTCLK0:LowFreq./1:HighFreq.*/#defineXT2OFF(0x80)/*EnableXT2CLK*/#defineDIVA_0(0x00)/*ACLKDivider0:/1*/#defineDIVA_1(0x10)/*ACLKDivider1:/2*/#defineDIVA_2(0x20)/*ACLKDivider2:/4*/#defineDIVA_3(0x30)/*ACLKDivider3:/8*/#defineDIVS0(0x02)/*SMCLKDivider0*/#defineDIVS1(0x04)/*SMCLKDivider1*/#defineSELS(0x08)/*SMCLKSourceSelect0:DCOCLK/1:XT2CLK/LFXTCLK*/#defineDIVM0(0x10)/*MCLKDivider0*/#defineDIVM1(0x20)/*MCLKDivider1*/#defineSELM0(0x40)/*MCLKSourceSelect0*/#defineSELM1(0x80)/*MCLKSourceSelect1*/#defineDIVS_0(0x00)/*SMCLKDivider0:/1*/#defineDIVS_1(0x02)/*SMCLKDivider1:/2*/#defineDIVS_2(0x04)/*SMCLKDivider2:/4*/#defineDIVS_3(0x06)/*SMCLKDivider3:/8*/#defineDIVM_0(0x00)/*MCLKDivider0:/1*/#defineDIVM_1(0x10)/*MCLKDivider1:/2*/#defineDIVM_2(0x20)/*MCLKDivider2:/4*/#defineDIVM_3(0x30)/*MCLKDivider3:/8*/#defineSELM_0(0x00)/*MCLKSourceSelect0:DCOCLK*/#defineSELM_1(0x40)/*MCLKSourceSelect1:DCOCLK*/#defineSELM_2(0x80)/*MCLKSourceSelect2:XT2CLK/LFXTCLK*/#defineSELM_3(0xC0)/*MCLKSourceSelect3:LFXTCLK*/#defineLFXT1OF(0x01)/*Low/highFrequencyOscillatorFaultFlag*/#defineXT2OF(0x02)/*Highfrequencyoscillator2faultflag*/#defineXCAP0(0x04)/*XIN/XOUTCap0*/#defineXCAP1(0x08)/*XIN/XOUTCap1*/#defineLFXT1S0(0x10)/*Mode0forLFXT1(XTS=0)*/#defineLFXT1S1(0x20)/*Mode1forLFXT1(XTS=0)*/#defineXT2S0(0x40)/*Mode0forXT2*/#defineXT2S1(0x80)/*Mode1forXT2*/#defineXCAP_0(0x00)/*XIN/XOUTCap:0pF*/#defineXCAP_1(0x04)/*XIN/XOUTCap:6pF*/#defineXCAP_2(0x08)/*XIN/XOUTCap:10pF*/#defineXCAP_3(0x0C)/*XIN/XOUTCap:12.5pF*/#defineLFXT1S_0(0x00)/*Mode0forLFXT1:Normaloperation*/#defineLFXT1S_1(0x10)/*Mode1forLFXT1:Reserved*/#defineLFXT1S_2(0x20)/*Mode2forLFXT1:VLO*/#defineLFXT1S_3(0x30)/*Mode3forLFXT1:Digitalinputsignal*/#defineXT2S_0(0x00)/*Mode0forXT2:0.4-1MHz*/#defineXT2S_1(0x40)/*Mode1forXT2:1-4MHz*/#defineXT2S_2(0x80)/*Mode2forXT2:2-16MHz*/#defineXT2S_3(0xC0)/*Mode3forXT2:Digitalinputsignal*/基本时钟系统例程(DCO)MSP430G2553在上电之后默认CPU执行程序的时钟MCLK来自于DCO时钟。TI提供的LaunchPad上,P1.0和P1.6分别接了红色和绿色的LED灯,下面写一个程序让它们交替闪烁;之后我们来改变DCO的频率,进而使软延时时间变化,可以看到LED闪烁间隔有变化。#includemsp430g2553.hvoidmain(void){WDTCTL=WDTPW+WDTHOLD;P1DIR|=BIT0+BIT6;while(1){P1OUT^=BIT0+BIT6;__delay_cycles(100000);}}这段程序采用430上电后默认的DCO频率,假设是1MHz的话,则延时100000个DCO提供的MCLK大概是0.1s左右。下面一段程序,将DCOx设置为1,RSELx设置为1,通过数据手册查得DCO频率大概在0.06~0.14MHz之间,所以明显MCLK要慢得多了,因此LED闪烁时间延长。#includemsp430g2553.hvoidmain(void){WDTCTL=WDTPW+WDTHOLD;DCOCTL|=DCO0;DCOCTL&=~(DCO1+DCO2);BCSCTL1|=RSEL0;BCSCTL1&=~(RSEL1+RSEL2+RSEL3);P1DIR|=BIT0+BIT6;while(1){P1OUT^=BIT0+BIT6;__delay_cycles(100000);}}MSP430G2553的I/O口MSP430G2553共有2组数字I/O口:P1和P2,每组各有8个引脚,每个引脚都能够响应中断,接受外部输入的上升沿或者下降中断请求。所有I/O口均与单片机内部外设的特殊功能引脚复用,当我们选用I/O功能时,要作为通用I/O口来使用,这需要相应的寄存器来进行控制。I/O头文件内容/*************************************************************DIGITALI/OPort1/2Pullup/PulldownResistors************************************************************/#define__MSP430_HAS_PORT1_R__/*DefinitiontoshowthatModuleisavailable*/#define__MSP430_HAS_PORT2_R__/*DefinitiontoshowthatModuleisavailable*/SFR_8BIT(P1IN);/*Port1Input*/SFR_8BIT(P1OUT);/*Port1Output*/SFR_8BIT(P1DIR);/*Port1Direction*/SFR_8BIT(P1IFG);/*Port1InterruptFlag*/SFR_8BIT(P1IES);/*Port1InterruptEdge