运用了定时器中断测一方波频率,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谢谢!!!!!!!!!
此帖出自小平头技术问答
一周热门 更多>