430g2553测频率和幅度,不能实时显示,必须reset,求帮助
时间:10-02
整理:3721RD
点击:
430g2553测频率和幅度 运用了定时器中断测一方波频率,ad10中断测一直流信号的幅度,并在12864上显示
可以得到较准的结果,但是频率/幅度改变时在12864上不能实时改变显示,必须reset之后才能
频率和幅度分别一个程序时都能做到实时改变显示
觉得是中断的问题,但不知道···430的中断嵌套呀,理解无能
主程序如下:
void main()
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= BIT7; // P1.0 output
P1DIR |= BIT0;
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!
}
//1Mhz
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */
LCD_Init();
Init_In();
Init_Timer();
ShowInit();
ADC10CTL0 =SREF_1+ ADC10SHT_2 + ADC10ON + REFON + REF2_5V + ADC10IE; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_2; // input A1
ADC10AE0 |= 0x04; // PA.1 ADC option select
P1DIR |= 0x04;
while(1)
{
ShowF();//频率显示
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
vol=(ADC10MEM*2.5)/1023;
vol=vol*10;
int temp=(int)vol;
c=temp/10;
b=temp%10;
Write_Pos(2,4);
Write_Data(tab[c]);
Write_Data('.');
Write_Data(tab);
_EINT();
}
}
#pragma vector=PORT1_VECTOR
__interrupt void port_1()
{
if(P1IFG & BIT1)
{
port_i++;
if(port_i>=100)
{
P1OUT ^= BIT6;
port_i = 0;
F =(unsigned long int)((1000000*100.0)/((TA_overflow*65536)+TAR));
TA_overflow = 0;
TACTL |= TACLR;
}
P1IFG &= ~BIT1;
}
_EINT();
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A1()
{
switch(TA0IV)
{
case 2:break;
case 4:break;
case 10:TA_overflow++;break;
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
//__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
_EINT();
}
求帮助!1谢谢!
可以得到较准的结果,但是频率/幅度改变时在12864上不能实时改变显示,必须reset之后才能
频率和幅度分别一个程序时都能做到实时改变显示
觉得是中断的问题,但不知道···430的中断嵌套呀,理解无能
主程序如下:
void main()
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= BIT7; // P1.0 output
P1DIR |= BIT0;
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!
}
//1Mhz
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */
LCD_Init();
Init_In();
Init_Timer();
ShowInit();
ADC10CTL0 =SREF_1+ ADC10SHT_2 + ADC10ON + REFON + REF2_5V + ADC10IE; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_2; // input A1
ADC10AE0 |= 0x04; // PA.1 ADC option select
P1DIR |= 0x04;
while(1)
{
ShowF();//频率显示
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
vol=(ADC10MEM*2.5)/1023;
vol=vol*10;
int temp=(int)vol;
c=temp/10;
b=temp%10;
Write_Pos(2,4);
Write_Data(tab[c]);
Write_Data('.');
Write_Data(tab);
_EINT();
}
}
#pragma vector=PORT1_VECTOR
__interrupt void port_1()
{
if(P1IFG & BIT1)
{
port_i++;
if(port_i>=100)
{
P1OUT ^= BIT6;
port_i = 0;
F =(unsigned long int)((1000000*100.0)/((TA_overflow*65536)+TAR));
TA_overflow = 0;
TACTL |= TACLR;
}
P1IFG &= ~BIT1;
}
_EINT();
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A1()
{
switch(TA0IV)
{
case 2:break;
case 4:break;
case 10:TA_overflow++;break;
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
//__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
_EINT();
}
求帮助!1谢谢!
恩,我自己尝试着解决了~~觉得是中断时序和嵌套的问题
有点碰运气
改了这两个地方
while(1)
{
ShowF();
ADC10CTL0 |= ENC + ADC10SC;
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
_EINT();
P1OUT^=BIT0;
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
vol=(ADC10MEM*2.5)/1023;
vol=vol*10;
int temp=(int)vol;
c=temp/10;
b=temp%10;
Write_Pos(2,4);
Write_Data(tab[c]);
Write_Data('.');
Write_Data(tab[b]);
}
又发现只要把原来的程序中
while(1)中的
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
去掉就行,其余都不用改,那些中断中的啥_EINT();都可以去掉
不太清楚原因,求帮忙解释
附注:单独测电压时AD中断还有while(1)中的程序都是那样的,但可以实时显示