上图是ADC的内部工作原理图,通过这个图,我们可以知道430有16个转化通道,16个转化结果寄存器和16个控制寄存器
其中ADC12MEMX与ADC12MCTLX是一一对应的,但是要注意的一点是通道Ax并不与ADC12MEMX相对应,也就是说A1的转化结果不一定非得放到ADC12MEM1当中,
ADC12MCTLX中的INCHx可以确定ADC12MEMX存放哪个通道的转化结果。
下面附一个单通道单次转化的程序:
#include <msp430x14x.h>
#include"lcd.h"
void int2charsLcdshow(int value);
void DelayXms(unsigned int i); //delay about x ms
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
// LcdReset(); //LCD1602³õʼ»¯
ADC12CTL0 = SHT0_2 + ADC12ON; // ÉèÖòÉÑù±£³ÖµÄʱ¼äΪ8¸ö£¨4n¸ö£©Ê±ÖÓÖÜÆÚ£¬´ò¿ªADC12
ADC12CTL1 = SHP; // ʹÓòÉÑù¶¨Ê±Æ÷¾ö¶¨²ÉÑùʱ¼ä
ADC12IE = 0x01; //
ADC12CTL0 |= ENC; // ADת»¯Ê¹ÄÜ
P6SEL |= BIT0; // P6.0 ×÷ΪADת»¯µÄA0
P2DIR |= BIT0; // P1.0 output
for (;;)
{
DelayXms(500);
ADC12CTL0 |= ADC12SC; // ¿ªÊ¼×ª»¯
_BIS_SR(CPUOFF + GIE); // LPM0, ADC12_ISR will force exit
}
}
// ADC12 interrupt service routine
#pragma vector=ADC_VECTOR
__interrupt void ADC12_ISR (void)
{
// int2charsLcdshow(ADC12MEM0);
if (ADC12MEM0 < 0x7FF) //×î´óÖµÊÇ0xFFF£¬ÔòËüµÄÒ»°ë¾ÍÊÇ0x7FF
P2OUT &= ~0x01; // Clear P1.0 LED off
else
P2OUT |= 0x01; // Set P1.0 LED on
_BIC_SR_IRQ(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
void int2charsLcdshow(int value){
int bits=0,ten = 0,hundred = 0,thousand = 0; //ÕâËÄλ·Ö±ð´æ´¢¸ö¡¢Ê®¡¢°Ù¡¢Ç§Î»¡£
thousand = value/1000;
hundred = value%1000/100;
ten = value%100/10;
bits = value%10;
Disp1Char(0,0,thousand+'0');
Disp1Char(1,0,hundred+'0');
Disp1Char(2,0,ten+'0');
Disp1Char(3,0,bits+'0');
}
void DelayXms(unsigned int i){
unsigned int j;
for( ; i>0; i--){
for(j=0;j<200;j++);
}
}
不错,谢谢分享
感谢分享