msp430g2553测量电压程序
基于msp430g2553单片机ADC测量外部直流电压
#include<msp430g2553、h>#define uchar unsigned char#define uint unsigned int#define LCD_CON_DIR P2DIR#define LCD_CON_IN P2IN#define LCD_CON_OUT P2OUT#define LCD_RS BIT0 //p2、5接51 p2、5#define LCD_RW BIT1 //p2、0接51 p2、6#define LCD_EN BIT2 //p2、1接51 p2、7#define LCD_DATA_DIR P1DIR#define LCD_DATA_IN P1IN#define LCD_DATA_OUT P1OUT#define A 1000#define B 100#define X 10void InitOsc(void);void InitLCD(void);void write_command(uchar command);void write_data(uchar data);void Display_ZFC(uchar *s);void LCD_Set_xy(uchar x,uchar y);void Trans_val(uint Hex_Val);void Display_Volte(uint Hex_Val);void Measure_Volte(void);uchar num[]={"0123456789、v"};uchar volte[]={"Volt: "};uint index=0;int i;unsigned long sum=0;uint Hex_Val;#define Num_of_Results 32uint results[Num_of_Results]; //保存ADC转换结果的数组uint average;/**************************************************************************** ADC初始化*****************************************************************************/ void ADC_Init(void){ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled ADC10CTL1 = INCH_1; // input A1ADC10AE0 |= 0x02; //二次采集}/**************************************************************************** DCO时钟初始化设为1MHz*****************************************************************************/ void DCO_Init(void){if(CALBC1_1MHZ==0xFF||CALDCO_1MHZ==0xFF){while(1);}BCSCTL1 = CALBC1_1MHZ;DCOCTL = CALDCO_1MHZ;BCSCTL2 = SELM_0 +DIVM_0;}/****************************************************************************向12864发送字节*****************************************************************************/ void SendByte(uchar Zdata){uint i;for(i=0; i<8; i++){if((Zdata << i) & 0x80){LCD_CON_OUT |= LCD_RW; //clk始终信号为高}else{LCD_CON_OUT &=~LCD_RW; //clk始终信号为低}LCD_CON_OUT &= ~LCD_EN;LCD_CON_OUT |= LCD_EN;}}/****************************************************************************向12864写命令*****************************************************************************/ void write_command(uchar command){LCD_CON_OUT |= LCD_RS;SendByte(0xF8);SendByte(command & 0xF0);SendByte((command<<4)&0xF0);_delay_cycles(200);}/****************************************************************************向12864写数据*****************************************************************************/ void write_data(uchar data){LCD_CON_OUT |= LCD_RS;SendByte(0xFA);SendByte(data & 0xF0);SendByte((data << 4) & 0xF0);_delay_cycles(200);}void Display_ZFC(uchar *s){while(*s > 0){write_data(*s);s++;_delay_cycles(5000);}}/****************************************************************************确定12864屏幕显示的坐标位置(x,y)*****************************************************************************/ void LCD_Set_xy( uchar x, uchar y ){uchar address;switch(x){case 0: address = 0x80 + y; break;case 1: address = 0x80 + y; break;case 2: address = 0x90 + y; break;case 3: address = 0x88 + y; break;case 4: address = 0x98 + y; break;default:address = 0x80 + y; break;}write_command(address); //写入地址命令}/**************************************************************************** lcd初始化*****************************************************************************/ void InitLCD(void){LCD_CON_DIR |= 0xFF; //p2口定义为输出write_command(0x01); //清屏write_command(0x30);_delay_cycles(5000);write_command(0x0c);_delay_cycles(5000);}/****************************************************************************采集到的数据转化成电压形式*****************************************************************************/ void Trans_val(uint Hex_Val){unsigned long caltmp;uint Curr_Volt,volt,max;uint a[50];caltmp = Hex_Val;caltmp = caltmp*34600; //caltmp = Hex_Val * 34600Curr_Volt = caltmp >> 10 ; //Curr_Volt = caltmp / 2^nvolt = Curr_Volt;for(i=0;i<50;i++){a[i]=volt;}for(max=a[0],i=0;i<50;i++){if(a[i]>max)max=a[i];}Curr_Volt = max;Display_Volte(Curr_Volt);}/****************************************************************************主函数*****************************************************************************/ void main(void){WDTCTL = WDTPW + WDTHOLD;ADC_Init(); //ADC初始化DCO_Init(); //DCO初始化InitLCD(); //12864液晶初始化while(1){Measure_Volte(); //测量直流电压值并且显示}}/****************************************************************************测量电压*****************************************************************************/ void Measure_Volte(void){ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE);results[index++] = ADC10MEM; // Move resultsif(index == Num_of_Results){index = 0;for(i = 0; i < Num_of_Results; i++){sum += results[i];}sum >>= 5; //除以32Trans_val(sum);sum=0;}}/****************************************************************************显示电压值*****************************************************************************/ void Display_Volte(uint Hex_Val){uint Curr_Volt;Curr_Volt = Hex_Val;write_command(0x90);for(i=0;i<16;i++){write_data(volte[i]);}write_command(0x93);write_data(num[Curr_Volt / 10000]);write_data(num[10]);write_data(num[Curr_Volt % 10000/1000]);write_data(num[Curr_Volt % 10000 % 1000 / 100]);write_data(num[Curr_Volt % 10000 % 1000 % 100 / 10]);write_data(' ');write_data(num[11]);}/****************************************************************************ADC中断,进入低功耗模式关闭CPU*****************************************************************************/ #pragma vector=ADC10_VECTOR__interrupt void ADC10_ISR(void){__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)}。
基于msp430g2553单片机ADC测量外部直流电压
#include<msp430g2553.h>#define uchar unsigned char#define uint unsigned int#define LCD_CON_DIR P2DIR#define LCD_CON_IN P2IN#define LCD_CON_OUT P2OUT#define LCD_RS BIT0 //p2.5接51 p2.5#define LCD_RW BIT1 //p2.0接51 p2.6#define LCD_EN BIT2 //p2.1接51 p2.7#define LCD_DATA_DIR P1DIR#define LCD_DATA_IN P1IN#define LCD_DATA_OUT P1OUT#define A 1000#define B 100#define X 10void InitOsc(void);void InitLCD(void);void write_command(uchar command);void write_data(uchar data);void Display_ZFC(uchar *s);void LCD_Set_xy(uchar x,uchar y);void Trans_val(uint Hex_Val);void Display_Volte(uint Hex_Val);void Measure_Volte(void);uchar num[]={"0123456789.v"};uchar volte[]={"Volt: "};uint index=0;int i;unsigned long sum=0;uint Hex_Val;#define Num_of_Results 32uint results[Num_of_Results]; //保存ADC转换结果的数组uint average;/**************************************************************************** ADC初始化*****************************************************************************/ void ADC_Init(void){ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled ADC10CTL1 = INCH_1; // input A1ADC10AE0 |= 0x02; //二次采集}/**************************************************************************** DCO时钟初始化设为1MHz*****************************************************************************/ void DCO_Init(void){if(CALBC1_1MHZ==0xFF||CALDCO_1MHZ==0xFF){while(1);}BCSCTL1 = CALBC1_1MHZ;DCOCTL = CALDCO_1MHZ;BCSCTL2 = SELM_0 +DIVM_0;}/****************************************************************************向12864发送字节*****************************************************************************/ void SendByte(uchar Zdata){uint i;for(i=0; i<8; i++){if((Zdata << i) & 0x80){LCD_CON_OUT |= LCD_RW; //clk始终信号为高}else{LCD_CON_OUT &=~LCD_RW; //clk始终信号为低}LCD_CON_OUT &= ~LCD_EN;LCD_CON_OUT |= LCD_EN;}}/****************************************************************************向12864写命令*****************************************************************************/ void write_command(uchar command){LCD_CON_OUT |= LCD_RS;SendByte(0xF8);SendByte(command & 0xF0);SendByte((command<<4)&0xF0);_delay_cycles(200);}/****************************************************************************向12864写数据*****************************************************************************/ void write_data(uchar data){LCD_CON_OUT |= LCD_RS;SendByte(0xFA);SendByte(data & 0xF0);SendByte((data << 4) & 0xF0);_delay_cycles(200);}void Display_ZFC(uchar *s){while(*s > 0){write_data(*s);s++;_delay_cycles(5000);}}/****************************************************************************确定12864屏幕显示的坐标位置(x,y)*****************************************************************************/ void LCD_Set_xy( uchar x, uchar y ){uchar address;switch(x){case 0: address = 0x80 + y; break;case 1: address = 0x80 + y; break;case 2: address = 0x90 + y; break;case 3: address = 0x88 + y; break;case 4: address = 0x98 + y; break;default:address = 0x80 + y; break;}write_command(address); //写入地址命令}/**************************************************************************** lcd初始化*****************************************************************************/ void InitLCD(void){LCD_CON_DIR |= 0xFF; //p2口定义为输出write_command(0x01); //清屏write_command(0x30);_delay_cycles(5000);write_command(0x0c);_delay_cycles(5000);}/****************************************************************************采集到的数据转化成电压形式*****************************************************************************/ void Trans_val(uint Hex_Val){unsigned long caltmp;uint Curr_Volt,volt,max;uint a[50];caltmp = Hex_Val;caltmp = caltmp*34600; //caltmp = Hex_Val * 34600Curr_Volt = caltmp >> 10 ; //Curr_Volt = caltmp / 2^nvolt = Curr_Volt;for(i=0;i<50;i++){a[i]=volt;}for(max=a[0],i=0;i<50;i++){if(a[i]>max)max=a[i];}Curr_Volt = max;Display_Volte(Curr_Volt);}/****************************************************************************主函数*****************************************************************************/ void main(void){WDTCTL = WDTPW + WDTHOLD;ADC_Init(); //ADC初始化DCO_Init(); //DCO初始化InitLCD(); //12864液晶初始化while(1){Measure_Volte(); //测量直流电压值并且显示}}/****************************************************************************测量电压*****************************************************************************/ void Measure_Volte(void){ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE);results[index++] = ADC10MEM; // Move resultsif(index == Num_of_Results){index = 0;for(i = 0; i < Num_of_Results; i++){sum += results[i];}sum >>= 5; //除以32Trans_val(sum);sum=0;}}/****************************************************************************显示电压值*****************************************************************************/ void Display_Volte(uint Hex_Val){uint Curr_Volt;Curr_Volt = Hex_Val;write_command(0x90);for(i=0;i<16;i++){write_data(volte[i]);}write_command(0x93);write_data(num[Curr_Volt / 10000]);write_data(num[10]);write_data(num[Curr_Volt % 10000/1000]);write_data(num[Curr_Volt % 10000 % 1000 / 100]);write_data(num[Curr_Volt % 10000 % 1000 % 100 / 10]);write_data(' ');write_data(num[11]);}/****************************************************************************ADC中断,进入低功耗模式关闭CPU*****************************************************************************/ #pragma vector=ADC10_VECTOR__interrupt void ADC10_ISR(void){__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)}。
msp430g2553测频率以及测峰值
msp430g2553测频率以及测峰值电子设计综合实验项目报告项目名称:MCU交流电压参数测量小组成员:林伊、武正浩学号:20111112、20111201项目要求题目:交流电压参数的测量 要求:用给定的MCU:msp430g2553,制作交流电压参数测试设备图表 1基本要求:一、 用给定运放LM324制作一放大器 a) 增益大于:20dBb) 带宽大于:100KHz二、 用指定MCU 和已制作的放大器制作频率计a) 测量范围:10Hz~100KHzb) 显示:3位以上信号放大 A/D比较器 指定MCUMSP430发挥部分:一、用A/D测量已给电压的幅度,信号由已制作的放大器输入a)测量范围:输入信号越小越好实现思路放大:首先分析题目要求,要实现放大20dB,频率1~100KHz的信号,通过公式20lg(Ad)得出Ad=10,即放大10倍必须使用运放lm324实现,则需要知道该芯片的器件参数,即增益带宽积。
通过数据手册得知其增益带宽积为6.4MHz,除去放大倍数得知能够实现该信号的放大,通过设计放大电路并焊接即可,放大电路为反向比例放大电路,见Figure 1Figure 1频率:实现频率的测量,这一块需使用到MCU,测量频率的方法有很多种,通过捕捉上升沿下降沿产生中断,也可以不产生中断,还可通过时钟计数。
其中通过捕捉上升沿下降沿的思路又分两种,1、检测上升沿后再检测下一个上升沿(检测下降沿后再检测下一个下降沿)2、检测上升沿后再检测下降沿(检测下降沿后再检测上升沿)。
这些思路对应不同的采集方法又可以细分,其中方案1对于测量高频信号有着较好的效果,方案2对于测低频的信号较好,前提是占空比为50%,若不为则变为测脉宽。
这次的题目我采用的是用时钟计数的方式,msp430g2553中含有2个时钟,timer0和timer1,每个时钟都有如下功能,选择时钟来源:1、外部时钟(即外部输入的方波信号)2、ACLK 3、smclk等。
电设工作小结之——MSP430G2553学习笔记—2
电设工作小结之——MSP430G2553学习笔记——2接上一篇:(四),ADC101,ADC10是十位的AD,在g2553上有A0~A7八个可以外接的AD通道,A10接到片上的温度传感器上,其他的通道都接在内部的VCC或GND上。
因为是10为的AD所以计算公式如下:2 ,ADC参考电压的选择:ADC的参考电压可以为:由ADC控制寄存器0 ADC10CTL0控制。
但是要提高ADC的精度的话,尽量不要用内部的参考电压,最好外接一个比较稳定的电压作为参考电压,因为内部的产生的参考电压不是特别稳定或精度不是特别的高。
例如我在使用时遇到的情况如下:Vref设为2.5V 但实际的值大概为2.475V,选择VCC VSS作为参考,用电压表测得大概为3.58V 还是不小的偏差的。
另外,在有可能的情况下,尽量采用较大的VR+和VR-,以减小纹波对采样结果的影响。
3,ADC10的采样方式有:单通道单次采样,单通道多次采样,多通道单次采样,多通道多次采样。
4,DTC:因为ADC10只有一个采样结果存储寄存器ADC10MEM,所以除了在单通道单次采样的模式下,其他的三个模式都必须使用DCT,否则转换结果会不停地被新的结果给覆盖。
DTC是转换结果传送控制,也就是转换结果可以不用CPU的干预,就可以自动地存储在指定的存储空间内。
使用这种方式转换速度快,访问方便,适用于高速采样模式中。
DTC的使用可以从下面的例子中很容易看明白:#include <msp430g2553.h>#include "ser_12864.h"uchar s1[]={"DTC:"};uchar s2[]={"2_cha_2_time_DTC"};void ADC_init(){ADC10CTL1 = CONSEQ_3 + INCH_1; // 2通道多次转换, 最大转换通道为A1ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; // ADC10ON, interrupt enabl 参考电压选默认值VCC和VSS//采样保持时间为16 x ADC10CLKs,ADC内核开,中断使能 MSC多次转换选择开//如果MSC置位,则第一次开始转换时需要触发源触发一次,以后的转换会自动进行中断使能//使用DTC时,当一个块传送结束,产生中断//数据传送控制寄存器0 ADC10DTC0设置为默认模式:单传送块模式,单块传送完停止 ADC10DTC1 = 0x04; //数据传送控制寄存器1 4 conversions 定义在每块的传送数目一共采样4次所以单块传送4次//以后就停止了传送因为是两通道的,所以是每个通道采样数据传送2次ADC10AE0 |= BIT0+BIT1; // P1.0 P1.1 ADC option select 使能模拟输入脚A0 A1//不知道为什么,当P10 P11都悬空时,采样值不同,用电压表测得悬空电压不同,但是当都接上采样源的时候,//采样是相同的}void main(void){uint adc_sample[8]={0}; //存储ADC序列采样结果WDTCTL = WDTPW+WDTHOLD;BCSCTL1 = CALBC1_12MHZ; //设定cpu时钟DCO频率为12MHzDCOCTL = CALDCO_12MHZ;P2DIR |=BIT3+BIT4; //液晶的两条线init_lcd();ADC_init();wr_string(0,0,s1);wr_string(0,3,s2);for (;;){ADC10CTL0 &= ~ENC; //ADC不使能其实这句话可以放在紧接着CPU唤醒之后的,因为CPU唤醒了,说明我们想要的//转换数据传送完成了,如果ADC继续转换,那么转换结果也不再传输,是无用的。
基于MSP430G2553的电压表设计
数字式直流电压表一、整体说明在电子技术中,往往离不开对电压的测量,作为一种测量电压的仪器——电压表是近代电子技术领域的常用工具之一,在许多领域得到广泛应用。
本设计是基于TI单片机设计的数字式直流电压表,它主要由MSP430G2553、LCD12864和分压电路三部分组成。
分压电路先将输入的电压信号衰减一定的倍数,后通过控制双路选择开关设定测量的量程,分别有0~3V和0~15V两个档,以便实现精确读数;分压处理后的电压信号由MSP430G2553内部的ADC10模块转换成数字信号;再通过LCD12864液晶屏进行串行显示。
经多次测量实验得出误差范围在2%以内。
二、原理图基于MSP430G2553单片机设计的数字式直流电压表的电路图如图1所示。
由于MSP430开发板已具备单片机最小系统结构,只需添加显示电路和分压电路。
LCD12864通过串口方式显示,只需占用单片机2个I/O口;分压电路可以通过开关S1选择量程档位,只占用1个I/O口。
图1 直流电压表电路图三、接口定义MSP430G2553的接口说明如表1所示。
图1中的复位和晶振部分是MSP430开发板固有的部分,故不再说明。
P1.0接液晶屏的SID脚,作为串行的数据口用;P1.1则接液晶屏的SCLK脚,控制串行的同步时钟;P1.4接分压电路的输出端。
LCD12864的接口说明如表2所示。
当PSB脚接低电平时,串口模式被选择。
在该模式下,只用2根线(SID与SCLK)来完成数据传输。
RS接高电平,不使用片选功能。
注意:信号源与单片机之间要共地。
表1 MSP430G2553的接口说明表2 LCD12864的接口说明四、程序流程图(一)主函数主函数的流程框图如图1所示。
主函数主要是调用系统初始化函数和循环开启ADC 转换,这是由于ADC10采用单通道单次转换模式,每次采样后需要重新开启ADC ,才会进行下一次信号采样转换。
另外,信号的采样与处理以及电压值的显示都是通过中断来完成。
msp430g2553_LCD1602显示直流电压检测电路
msp430g2553_LCD1602显示直流电压检测电路按此图连接即可。
以下是显示部分程序,DA部分简单,大家稍微动动脑子~~~/************************msp430g2553_LCD1602_Voltage_Detect********************* *********date:2012.7.13*/#include <msp430g2553.h>int data;int i,j;double n;char a[];/************************延时函数*****************************/void delay(int i){int s=500;for(;i>0;i--){for(;s>0;s--){;;}}}/************************lcd写指令*****************************/void write_com(char com){P1OUT&=~(1<<3);//RS=0,输入指令P1OUT&=~(1<<4);//RW=0,向lcd写入指令或数据P1OUT&=~(1<<5);//EN=0,始终执行指令delay(8);P2OUT=com;delay(8);P1OUT|=(1<<5);//EN=1,读取信息delay(8);P1OUT&=~(1<<5);//EN=0,执行指令}/************************lcd写数据*****************************/ void write_data(char data_bit){P1OUT|=(1<<3);//RS=1,输入数据P1OUT&=~(1<<4);//RW=0,向lcd写入指令或数据P1OUT&=~(1<<5);//EN=0,执行指令delay(8);P2OUT=data_bit;delay(8);P1OUT|=(1<<5);//EN=1,读取信息delay(8);P1OUT&=~(1<<5);//EN=0,执行指令}/************************lcd初始化*****************************/ void initial_lcd(void){delay(20);write_com(0x38);delay(15);write_com(0x0c);delay(15);write_com(0x06);delay(15);write_com(0x01);}/************************lcd显示*****************************/void LCD_Display(char x,char y,char *str){char xtemp;switch(x){case 0:xtemp=0x80+y;break;case 1:xtemp=0xc0+y;break;default:break;}write_com(xtemp);while(*str!=0){write_data(*str);str++;}}/************************主函数*****************************/void main(void){WDTCTL = WDTPW + WDTHOLD; // Stop WDTP2SEL=0x00;//设置P2为通用IOP2DIR |= 0xff; // Set P2 to output directionP1DIR |= 0x38;//0011 1000 p1.3 1.4 1.5 作为LCD使能复位控制端initial_lcd();//LCD初始化__enable_interrupt(); // Enable interrupts.TACCR0 = 30; // Delay to allow Ref to settleTACCTL0 |= CCIE; // Comvolre-mode interrupt.TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode.LPM0; // Wait for delay.TACCTL0 &= ~CCIE; // Disable timer Interrupt__disable_interrupt();for (;;){n =12345678;a[0]=((long)n/100000000%10+0x30);a[1]=0x2e;a[2]=((long)n/10000000%10+0x30);a[3]=((long)n/1000000%10+0x30);a[4]=((long)n/100000%10+0x30);a[5]=((long)n/10000%10+0x30);a[6]=((long)n/1000%10+0x30);a[7]=((long)n/100%10+0x30);a[8]=((long)n/10%10+0x30);a[9]=((long)n/1%10+0x30);a[10]='\0';for(j = 0;j <= 618;j++) //扫描延时,稳定显示{//LCD_Display(0,0,"Voltage=");//LCD_Display(0,15,"V");LCD_Display(0,0,a);LCD_Display(1,1,"No:22 copyright");}}}// ADC10 interrupt service routine#pragma vector=TIMER0_A0_VECTOR__interrupt void ta0_isr(void){TACTL = 0;LPM0_EXIT; // Exit LPM0 on return }。
MSP430G2553中比较器测电阻的程序
DCOCTL =CALDCO_12MHZ;//具体代码没看到
IFG1=0x00; //清除中断标志 中断标志寄存器1 主要控制系统的中断
while(IFG1&OFIFG!=0)//OFIG在头文件中定义为0X20
//比较器设置
CACTL1 = CAEX + CAREF0 +CAON + CAIES + CAIE; //打开比较器 比较器中断 下降沿触发中断
CACTL2 = P2CA3 + CAF; // 一个选择CA1 P1.1 正输入端 一个选择CA2 P1.2 负输入端
else
start_data=0xfa;//写数据
Hdata=data&0xf0;//取高四位
Ldata=(data<<4)&0xf0;//取第四位
Send_Data(start_data);
Delay(1);
Send_Data(Hdata);
Delay(1);
// P1OUT ^= BIT6;
_BIC_SR_IRQ(LPM0_bits+GIE);
}
for(i=0;i<=15;i++)
{
Write_data(1,*P); P++;
Delay(move_timer);
num++;
}
}
if(hang==2)
{
Write_data(0,0x90+num);
}
}
void u32tostr(uint dat,char *str) //将一个32位的变量dat转为字符串
OPT3001 MSP430G2553完整程序
{
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学习笔记——1一,MSP430G2553单片机的各个功能模块(一),IO口模块,1,我们所用的MSP430G2553有两组IO口,P1和P2。
2,IO口的寄存器有:方向选择寄存器PxDIR,输出寄存器PxOUT,输入寄存器PxIN,IO口内部上拉或下拉电阻使能寄存器PxREN,IO口功能选择寄存器PxSEL和PxSEL2,IO口中断使能寄存器PxIE,中断沿选择寄存器PxIES,IO口中断标志寄存器PxIFG。
3,所有的IO都带有中断,其中所有的P1口公用一个中断向量,所有的P2口公用一个中断向量。
所以在使用中断时,当进入中断后,还要判断到底是哪一个IO口产生的中断,判断方法可以是判断各个IO口的电平。
4,中断标志PxIFG需要软件清除,也可以用软件置位,从而用软件触发一个中断。
注意:在设置PxIESx时根据PxINx有可能会引起相应的PxIFGx置位(具体的情况见用户指南),所以在初始化完IO口中断以后,正式使用IO中断前要先将对应的PxIFGx清零。
程序如下:void IO_interrupt_init() //IO中断初始化函数{P1REN |= BIT4+BIT5+BIT6+BIT7; // pull up 内部上拉电阻使能//使用中断时,使能内部的上拉电阻这样当该脚悬空是,电平不会跳变,防止悬空时电平跳变不停的触发中断P1OUT = BIT4+BIT5+BIT6+BIT7; // 当引脚上的上拉或下拉电阻使能时,PxOUT选择是上拉还是下来//0:下拉,1:上拉P1IE |= BIT4+BIT5+BIT6+BIT7; // interrupt enabled P13中断使能P1IES |= BIT4+BIT5+BIT6+BIT7; // Hi/lo edge 下降沿中断//P1IES &= ~BIT3; //上升沿触发中断P1IFG &= ~(BIT4+BIT5+BIT6+BIT7); //中断标志位清零}5,PxOUT:如果引脚选择了内部的上拉或下拉电阻使能,则PxOUT设定电阻是上拉还是下拉,0:下拉,1:上拉6,当IO口不用时,最好不要设为输入,且为浮动状态(这是IO口的默认状态),因为当输入为浮动时,输入电压有可能会在VIL和VIH之间,这样会产生击穿电流。
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用户手册中文
• 通用串行通信接口 (USCI) – 支持自动波特率检测的增强型通用异步收发器 (UART) – IrDA 编码器和解码器 – 同步 SPI – I2C™
• 用于模拟信号比较功能或者斜率模数 (A/D) 转换的 片载比较器
• 带内部基准、采样与保持以及自动扫描功能的 10 位 200-ksps 模数 (A/D) 转换器(见 表 1)
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
28 引脚
24 TSSOP 封
LF,
装
-
1
DCO,
VLO
20 引脚
16 TSSOP 封
装
16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
28 引脚
24 TSSOP 封
LF,
装
-
1
DCO,
VLO
20 引脚
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
MSP430G2553用户手册中文
28 引脚 24 TSSOP 封
装
20 引脚 16 TSSOP 封
装
16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
28 引脚 24 TSSOP 封
装
20 引脚 16 TSSOP 封
装
16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
28 引脚 24 TSSOP 封
装
20 引脚 16 TSSOP 封
时钟
I/O 封装类型
16
512 2x TA3
8
8
512 2x TA3
8
4
256 2x TA3
8
2
256 2x TA3
8
1
256 2x TA3
8
24
32 引脚 QFN 封装
28 引脚
24 TSSOP 封
LF,
装
-
1
DCO,
VLO
20 引脚
16 TSSOP 封
装
16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
MSP430G2x13 和 MSP430G2x53 系列是超低功耗混合信号微控制器,具有内置的 16 位定时器、多达 24 个支持 触摸感测的 I/O 引脚、一个通用型模拟比较器以及采用通用串行通信接口的内置通信能力。 此外,MSP430G2x53 系列成员还具有一个 10 位模数 (A/D) 转换器。 有关配置的详情请见 表 1。
• 欠压检测器 • 串行板上编程,
无需外部编程电压, 利用安全熔丝 (Security Fuse) 实现可编程代码保 护
• 具有两线制 (Spy-Bi-Wire) 接口的片上仿真逻辑电 路
mini12864的MSP430G2553驱动程序
ret_data=ret_data+0;
// P2DIR|=BIT1;
ROMSCK_1;
}
return(ret_data);
}
/*从相关地址(addrHigh:地址高字节,addrMid:地址中字节,addrLow:地址低字节)中连续读出DataLen个字节的数据到 pBuff的地址*/
LCDSID_1;
else
LCDSID_0;
LCDSCLK_1;
data1=data1<<=1;
}
}
/*写数据到LCD模块*/
void transfer_data_lcd(int data1)
{
char i;
LCDRS_1;
for(i=0;i<8;i++)
#define ROMCS_0 P2OUT&=~BIT3
/*写指令到LCD模块*/
void transfer_command_lcd(int data1)
{
char i;
LCDRS_0;
for(i=0;i<8;i++)
{
LCDSCLK_0;
if(data1&0x80)
#define LCDCS_0 P1OUT&=~BIT4
#define ROMIN_1 P2OUT|=BIT0 /*字库IC接口定义:Rom_IN就是字库IC的SI*/
#define ROMIN_0 P2OUT&=~BIT0
#define ROMOUT_1 P2OUT|=BIT1 /*字库IC接口定义:Rom_OUT就是字库IC的SO*/
基于MSP430G2553的简易智能电阻测量仪设计
基于MSP430G2553的简易智能电阻测量仪设计徐明【期刊名称】《电子测试》【年(卷),期】2017(0)10【摘要】The simple intelligent resistance measuring instrument is designed with an MSP430G2553 single chip computer as the core component. The system has realized resistance to voltage conversion through 10 bit A/D cnoverter inside the microcomputer.It has the functions of automatic range switching and realtime resistance value measuring & displaying.The whole system measurement error is below 1%.It also has the features of high measurement precision ,fast speed,low power consumption,good stability,easy operation and so on.It has good practical value.%本作品以MSP430G2553微控制器为控制核心,设计并实现了一简易电阻测量仪.该测量仪通过微控制器内部的片上10位A/D转换器,实现电阻-电压转换,具备自动量程转换和阻值实时测量显示等功能.整个系统测量误差≤1%,具有测试精度高、速度快、功耗低、稳定性好、操作方便等特点,有较好的实用价值.【总页数】3页(P20-21,17)【作者】徐明【作者单位】武汉理工大学自动化学院,湖北武汉,430000;仙桃职业学院机电学院,湖北仙桃,433000【正文语种】中文【相关文献】1.一款简易电阻电容测量仪的设计 [J], 滕飞;胡湘娟;阳泳2.基于单片机 MSP430G2553的智能电波钟设计 [J], 王旭;曾谢华;李光辉3.基于MSP430G2553单片机的简易水情检测系统设计 [J], 王珏敏4.基于MSP430G2553的智能防夹密码锁设计 [J], 薛晶晶; 刘珂; 刘丽丽; 杨延宁5.基于NTC热敏电阻简易快速智能体温计的设计 [J], 杨清志;张运芝因版权原因,仅展示原文概要,查看原文内容请购买。