This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432边沿捕获

源代码如下:

#include "msp432p401r.h"
#include <stdlib.h>
#include"oled.h"
u16 res=0;
u16 count=0;
void timer0_init(void)
{
TIMER_A0->CTL |= TIMER_A_CTL_TASSEL_2 ;
TIMER_A0->CCTL[2] = TIMER_A_CCTLN_CM_1 | // Capture rising edge,
TIMER_A_CCTLN_CCIS_0 | // Use CCI2A=ACLK,
TIMER_A_CCTLN_CCIE | // Enable capture interrupt
TIMER_A_CCTLN_CAP | // Enable capture mode,
TIMER_A_CCTLN_SCS; // Synchronous capture
P2->SEL0|=BIT5;
P2->SEL1&=~BIT5;
P2->DIR&=~BIT5;
}
void wave_count(void)
{
count=0; // 定时器 A 计数寄存器内容清零
TIMER_A0->CTL =TIMER_A_CTL_MC__UP; // 定时器 A 工作模式选择:连续模式
delay_ms(1000); // 产生 1s 计数闸门
TIMER_A0->CTL =TIMER_A_CTL_MC__STOP; // 定时器 A 工作模式选择:停止模式
count+=TIMER_A0->CCR[2];;
LCD_ShowNum(160,0,count,4,RED);

}
void adcinit(void)
{
P5->SEL1 |= BIT5; // Configure P5.5 for ADC
P5->SEL0 |= BIT5;
ADC14->CTL0 = ADC14_CTL0_SHT0_2 | ADC14_CTL0_SHP | ADC14_CTL0_ON| ADC14_CTL0_CONSEQ_0|ADC14_CTL0_SSEL_1;//adc14on+adcsht8+repeat channel
ADC14->CTL1 = ADC14_CTL1_RES_3; // Use sampling timer, 14-bit conversion results
ADC14->MCTL[0] |= ADC14_MCTLN_INCH_0;
}
void get_adc_result(void)
{
u16 a=0;
ADC14->CTL0 |= ADC14_CTL0_ENC | ADC14_CTL0_SC;//get adc value
a=ADC14->MEM[0];
res=a*3300/4096/4;
LCD_ShowNum(60,0,res,4,RED);
}
void draw(void)
{
int i=0;
int x1=10,y1=60;
int x2=311,y2=239;
LCD_ShowString(0,0," FORM:",RED);
LCD_ShowString(0,20," VALUE:",RED);
LCD_ShowString(0,40," FRE:",RED);
LCD_DrawLine(0,230,320,230,BLACK);
LCD_DrawLine(10,60,10,240,BLACK);
LCD_DrawLine(310,220,320,230,BLACK);
LCD_DrawLine(10,60,0,70,BLACK);
while(i<=9)
{
LCD_DrawPoint(x1,y1,BLACK);
LCD_DrawPoint(x2,y2,BLACK);
i+=1;
x1+=1;
x2+=1;
y1+=1;
y2-=1;
}
}
int main(void) {
WDT_A->CTL = WDT_A_CTL_PW | // Stop WDT
WDT_A_CTL_HOLD;
SystemCoreClockUpdate();
SystemInit();
adcinit();
timer0_init();
Lcd_Init(); //初始化OLED
LCD_Clear(WHITE);
BACK_COLOR=WHITE;
draw();
while (1) // continuous loop
{
wave_count();
get_adc_result();
}
}

想利用边沿捕获计数获得方波频率值,但是寄存器始终读不到内容,