承认偷懒了,找完工作,16号sopc比赛,最近的天天的实验课,导致了压根不想调,哈哈。
今天抽出来了点时间,先把ad的调了出来,使用的背部adc,P12引脚。详情见代码好了。
ADC的初始化:
void adc_init()
{
P1SEL1 |= BIT2; // Configure P1.2 for ADC
P1SEL0 |= BIT2;
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
// Configure ADC12
ADC12CTL0 = ADC12SHT0_2 | ADC12ON; // Sampling time, S&H=16, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12CTL2 |= ADC12RES_2; // 12-bit conversion results
ADC12MCTL0 |= ADC12INCH_2; // A1 ADC input select; Vref=AVCC
ADC12IER0 |= ADC12IE0; // Enable ADC conv complete interrupt
}
使用了adc中断,他的中断函数如下:
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
{
case ADC12IV_ADC12IFG0: // Vector 12: ADC12MEM0 Interrupt
adc_data=ADC12MEM0 ;
break; // Clear CPUOFF bit from 0(SR)
default: break;
}
}
启动adc函数:
void adc_start()
{
ADC12CTL0 |= ADC12ENC | ADC12SC; // Start sampling/conversion
}
使用办法:
adc_start();
sprintf(s, "%3.4f", ADC12MEM0*3.3/4096);
sendstring(s);
s是一个数组,用来保存sprintf转换过来的字符串,通过串口打印输出。串口的部分见
https://bbs.eeworld.com.cn/thread-447702-1-1.html
好啦好啦,赶快去吃饭!!饿死了,不吃饭哪有力气写代码~