msp430f149测量PWM高电平的时间,在1602液晶上显示出来,代码如下://MSP430F149 定时器A捕获功能测脉冲宽度
#include <msp430x14x.h>
#include "Config.h"
#include "1602.c"
#define uint unsigned int
#define uchar unsigned char
uint pwm_end;
uint time;
uint width;
//***********************************************************************
// 键值显示程序
//***********************************************************************
void LCD_DisplayKey(uint keynum)
{
LCD_write_char(0x0a,1,0x30+(keynum/10000));
LCD_write_char(0x0b,1,0x30+((keynum%10000)/1000));
LCD_write_char(0x0c,1,0x30+(keynum%1000)/100);
LCD_write_char(0x0d,1,0x30+ ((keynum%1000)%100)/10);
LCD_write_char(0x0e,1,0x30+ (((keynum%1000)%100)%10)/1);
}
void LCD_DisplayKey1(uint keynum)
{
LCD_write_char(0x01,1,0x30+(keynum/10000));
LCD_write_char(0x02,1,0x30+((keynum%10000)/1000));
LCD_write_char(0x03,1,0x30+(keynum%1000)/100);
LCD_write_char(0x04,1,0x30+ ((keynum%1000)%100)/10);
LCD_write_char(0x05,1,0x30+ (((keynum%1000)%100)%10)/1);
LCD_write_char(0x06,1,0x75);
LCD_write_char(0x07,1,0x73);
}
void main(void)
{
WDT_Init(); //看门狗设置
Clock_Init(); //系统时钟设置
Port_init(); //系统初始化,设置IO口属性
delay_ms(100); //延时100ms
LCD_init(); //液晶参数初始化设置
LCD_clear(); //清屏
P1DIR|=BIT1;
P1SEL|=BIT1; //捕获源为P1.1
TACCTL0 =CM_3+SCS+CAP+CCIS_0+CCIE; //上升沿下降沿都同步捕获
TACTL =TASSEL_2 + MC_2; //定时器计数开始 连续计数模式
_EINT(); //开总中断
// LPM0; //低功耗模式
// _NOP(); //不操作
while(1)
{
width = pwm_end;
time=width/8;
LCD_DisplayKey(width);
LCD_DisplayKey1(time);
}
}
/******定时器TA的CCR1的中断 用于检测脉冲上升沿和下降沿******/
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A1(void)
{
switch(TAIV)
{
case 0x02:break;
case 0x04:
if(TACCTL0 & CCI )// if(CCI==1)
{
TACTL=TACLR; //定时器清零
}
else
{
pwm_end = TACCR0;
}
break;
case 0x0A:break;
default:
break;
}
LPM0_EXIT;
}
大家帮忙看看是那个地方出问题了 |