MSP430单片机称之为混合信号处理器,是由于其针对实际应用需求,将多个不同功能的模拟电路、数字电路模块和微处理器集成在一个芯片上,以提供“单片机”解决方案。该系列单片机多应用于需要电池供电的便携式仪器仪表中。
MSP430系列单片机是美国德州仪器(TI)1996年开始推向市场的一种16位超低功耗、具有精简指令集(RISC)的混合信号处理器(Mixed Signal Processor)。#include "lcd12864c"
unsigned int flag = 0;
unsigned int fre_reg[2] = {0};
unsigned char temp = 0;
unsigned int temp1 = 0;
unsigned char num[5] = {0};
unsigned char digit[11]={'0','1','2','3','4','5','6','7','8','9',''};
unsigned char S1 = "测试结果";
float count = 00;
/
函数功能:配置时钟
/
void clk_init()
{
if(CALBC1_1MHZ == 0XFF || CALDCO_1MHZ == 0XFF)
{
while(1);
}
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ; //输出校正频率1MHZ
}
/
TIME_A初始化捕获模式
/
void time_a_init(void)
{
P1DIR &= ~(BIT2);
P1SEL |= BIT2;
/P12为捕获输入口 对应TACCR0 CCLA/
TACCTL1 = CM_1 + SCS + CCIS_0 + CAP + CCIE; //这里对应CCTL1 CCR1 P12口
/上升沿捕获 + 同步模式 + 捕获输入选择CCLA + 选择捕获 + 捕获中断使能/
TACTL = TASSEL0 + MC_2;
/TACLK为定时器时钟 + 连续计数模式/
}
/
中断服务子程序
/
#pragma vector = TIMER0_A1_VECTOR //用TAIV则用TIMER0_A1_VECTOR 若为CCR0则用TIMER0_A0_VECTOR
__interrupt void time_a(void)
{
switch(TAIV)
{
case 2: flag = 1; break; //捕获中断标志置1
case 4: break;
case 10: break;
}
}
/
主函数
/
void main()
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
P1DIR |= BIT0 + BIT1 + BIT5;
clk_init(); //时钟源初始化
time_a_init(); //定时器A初始化
lcd_init();
write_string(1,0,S1);
_EINT(); //开启全局中断
while(1)
{
while(flag == 1)
{
_DINT(); //关闭全局中断
flag = 0; //捕获中断标志清零
fre_reg[temp] = TACCR1; //读取捕获比较寄存器内的时间
temp++;
if(temp == 2)
{
count = fre_reg[1] - fre_reg[0];
count = 32 / count;
temp1 = (unsigned int)(count1000);
num[0] = temp1/10000;
num[1] = temp1%10000/1000;
num[2] = temp1%1000/100;
num[3] = temp1%100/10;
num[4] = temp1%10;
write_char(2,0,digit[num[0]]);
delayus(10);
write_char(2,1,digit[num[1]]);
delayus(10);
write_char(2,2,digit[num[2]]);
delayus(10);
write_char(2,3,digit[num[3]]);
delayus(10);
write_char(2,4,digit[num[4]]);
delayus(10);
}
_EINT(); //开启中断
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)