我币不多大家见谅
用430F149测方波占空比在LCD1602上显示,怎么弄都有问题,而且屏幕不能一直刷新数值。求教大神!!谢谢
/测方波信号占空比
#include <msp430x14x.h>
#include <cry1602.c>
#include <cry1602.h>
void delay();
void InitSys();
void process(void);
long int a[3]={0},pulse,period;
uint zhan,j;
uint e[5];
uchar shuzi[]={"0123456789."};
void main( void )
{
WDTCTL = WDTPW + WDTHOLD;
InitSys();
LcdReset();
P2DIR|=BIT0;
P1DIR &=~ BIT2;
P1SEL = BIT2;
TACTL = TASSEL_2+ID_3+TACLR+TAIE+MC1;
CCTL1 = CM_1 + SCS + CAP + CCIE;
_EINT();
while (1)
{ process();
for (j=0;j<5;j++){
Disp1Char((9+j),1,shuzi[e[4-j]]);}
delay();
}
}
#pragma vector =TIMERA1_VECTOR
__interrupt void timer_a(void)
{ static int k=0;
switch (TAIV)
{
case 2: if (k<3){
if (CCTL1&CM0)//上升沿
{a[k++]= TAR;
CCTL1 = (CCTL1&(~CM0))|CM1;
}
else if (CCTL1&CM1)//下降沿
{
a[k++]= TAR;
CCTL1 = (CCTL1&(~CM1))|CM0;
}}
else{k=0;}
P2OUT ^=BIT0;
break;
default:break;
}
delay();
}
void InitSys()
{
unsigned int i;
//--- 使用XT2振荡器 ---
BCSCTL1&=~XT2OFF; //==打开XT2振荡器==
do
{
IFG1 &= ~OFIFG; //==清除振荡器失效标志==
for (i = 0xFF; i > 0; i--); //==延时,等待XT2起振==
}
while ((IFG1 & OFIFG) != 0); //==判断XT2是否起振==
BCSCTL2 =SELM_2+SELS; //==选择MCLK、SMCLK为XT2,8M==
}
void process(void)
{
while ((a[0]>a[1])||(a[1]>a[2]));
pulse = a[1]-a[0];
period = a[2]-a[0];
zhan = pulse*1000/period;
e[4]=zhan/1000;
e[3]=10;
e[2]=zhan/100%10;
e[1]=zhan/10%10;
e[0]=zhan%10;
}
void delay()
{
unsigned int i;
for (i=5000;i>0;i--);
}
一周热门 更多>