利用MSP430內部DAC產生正弦信號
while(wait==0) ;
}
#pragma vector=ADC_VECTOR
__interrupt void ADC()
{int result[7];
wait=1;
result[0] = ADC12MEM0;
/*unsigned char q0;
int *pmem=ADC12MEM;
//轉換結束的標志位置位
for(q0=0;q0<16;q0++)
{
AdMem[q0]= *pmem;
pmem++;
}*/
}
下面再來簡要的介紹一下這個模塊不易理解的地方
1、MSP430可以使用內部、外部的參考電壓,內部1.5或2.5,外部0~3.3,可以通過寄存器設置,采樣電壓的輸入范圍最大為0~3.3即AVss~AVcc,不能檢測負電壓,如果需要檢測負電壓,可以使用運放,電壓偏置成為正電壓然后檢測
2、使用外部AVss~AVcc作為參考電壓不夠穩(wěn)定,但是精度高,使用內部電壓較穩(wěn)定。
3、程序中一定要打開全局中斷_EINT();
ADC12
************************************************** ********** /
#定義__ MSP430_HAS_ADC12__ / *定義表明模塊是* /
#定義ADC12CTL0_(0x01A0u)/ * ADC12控制0 * /
DEFW(ADC12CTL0,ADC12CTL0_)
#定義ADC12CTL1_(0x01A2u)/ * ADC12控制1 * /
DEFW(ADC12CTL1,ADC12CTL1_)
#定義ADC12IFG_(0x01A4u)/ * ADC12中斷標志* /
DEFW(ADC12IFG,ADC12IFG_)
#定義ADC12IE_(0x01A6u)/ * ADC12中斷使能* /
DEFW(ADC12IE,ADC12IE_)
#定義ADC12IV_(0x01A8u)/ * ADC12中斷向量字* /
DEFW(ADC12IV,ADC12IV_)
#定義ADC12MEM_(0x0140u)/ * ADC12轉換內存* /
的#ifndef __ IAR_SYSTEMS_ICC__
#定義ADC12MEM(ADC12MEM_)/ * ADC12轉換存儲器(匯編)* /
其他#
#定義ADC12MEM((INT *)ADC12MEM_)/ * ADC12轉換存儲器(C)* /
#ENDIF
#定義ADC12MEM0_(0x0140u)/ * ADC12轉換內存0 * /
DEFW(ADC12MEM0,ADC12MEM0_)
#定義ADC12MEM1_(0x0142u)/ * ADC12轉換內存1 * /
DEFW(ADC12MEM1,ADC12MEM1_)
#定義ADC12MEM2_(0x0144u)/ * ADC12轉換內存2 * /
DEFW(ADC12MEM2,ADC12MEM2_)
#定義ADC12MEM3_(0x0146u)/ * ADC12轉換記憶體3 * /
DEFW(ADC12MEM3,ADC12MEM3_)
#定義ADC12MEM4_(0x0148u)/ * ADC12轉換內存4 * /
DEFW(ADC12MEM4,ADC12MEM4_)
#定義ADC12MEM5_(0x014Au)/ * ADC12轉換記憶5 * /
DEFW(ADC12MEM5,ADC12MEM5_)
#定義ADC12MEM6_(0x014Cu)/ * ADC12轉換存儲器6 * /
DEFW(ADC12MEM6,ADC12MEM6_)
#定義ADC12MEM7_(0x014Eu)/ * ADC12轉換記憶7 * /
DEFW(ADC12MEM7,ADC12MEM7_)
#定義ADC12MEM8_(0x0150u)/ * ADC12轉換內存8 * /
DEFW(ADC12MEM8,ADC12MEM8_)
#定義ADC12MEM9_(0x0152u)/ * ADC12轉換存儲器9 * /
DEFW(ADC12MEM9,ADC12MEM9_)
#定義ADC12MEM10_(0x0154u)/ * ADC12轉換記憶體10 * /
DEFW(ADC12MEM10,ADC12MEM10_)
#定義ADC12MEM11_(0x0156u)/ * ADC12轉換記憶體11 * /
DEFW(ADC12MEM11,ADC12MEM11_)
#定義ADC12MEM12_(0x0158u)/ * ADC12轉換記憶體12 * /
DEFW(ADC12MEM12,ADC12MEM12_)
#定義ADC12MEM13_(0x015Au)/ * ADC12轉換記憶體13 * /
DEFW(ADC12MEM13,ADC12MEM13_)
#定義ADC12MEM14_(0x015Cu)/ * ADC12轉換記憶體14 * /
DEFW(ADC12MEM14,ADC12MEM14_)
#定義ADC12MEM15_(0x015Eu)/ * ADC12轉換記憶體15 * /
DEFW(ADC12MEM15,ADC12MEM15_)
#定義ADC12MCTL_(0x0080u)/ * ADC12內存控制* /
的#ifndef __ IAR_SYSTEMS_ICC__
#定義ADC12MCTL(ADC12MCTL_)/ * ADC12存儲器控制(用于匯編)* /
其他#
#定義ADC12MCTL((char *)的ADC12MCTL_)/ * ADC12存儲器控制(對于C)* /
#ENDIF
#定義ADC12MCTL0_(0x0080u)/ * ADC12內存控制0 * /
DEFC(ADC12MCTL0,ADC12MCTL0_)
#定義ADC12MCTL1_(0x0081u)/ * ADC12內存控制1 * /
DEFC(ADC12MCTL1,ADC12MCTL1_)
#定義ADC12MCTL2_(0x0082u)/ * ADC12內存控制2 * /
DEFC(ADC12MCTL2,ADC12MCTL2_)
#定義ADC12MCTL3_(0x0083u)/ * ADC12內存控制3 * /
DEFC(ADC12MCTL3,ADC12MCTL3_)
#定義ADC12MCTL4_(0x0084u)/ * ADC12內存控制4 * /
DEFC(ADC12MCTL4,ADC12MCTL4_)
#定義ADC12MCTL5_(0x0085u)/ * ADC12內存控制5 * /
DEFC(ADC12MCTL5,ADC12MCTL5_)
#定義ADC12MCTL6_(0x0086u)/ * ADC12內存控制6 * /
DEFC(ADC12MCTL6,ADC12MCTL6_)
#定義ADC12MCTL7_(0x0087u)/ * ADC12內存控制7 * /
DEFC(ADC12MCTL7,ADC12MCTL7_)
#定義ADC12MCTL8_(0x0088u)/ * ADC12內存控制8 * /
DEFC(ADC12MCTL8,ADC12MCTL8_)
#定義ADC12MCTL9_(0x0089u)/ * ADC12內存控制9 * /
DEFC(ADC12MCTL9,ADC12MCTL9_)
#定義ADC12MCTL10_(0x008Au)/ * ADC12內存控制10 * /
DEFC(ADC12MCTL10,ADC12MCTL10_)
#定義ADC12MCTL11_(0x008Bu)/ * ADC12內存控制11 * /
DEFC(ADC12MCTL11,ADC12MCTL11_)
#定義ADC12MCTL12_(0x008Cu)/ * ADC12內存控制12 * /
DEFC(ADC12MCTL12,ADC12MCTL12_)
#定義ADC12MCTL13_(0x008Du)/ * ADC12內存控制13 * /
DEFC(ADC12MCTL13,ADC12MCTL13_)
#定義ADC12MCTL14_(0x008Eu)/ * ADC12內存控制14 * /
DEFC(ADC12MCTL14,ADC12MCTL14_)
#定義ADC12MCTL15_(0x008Fu)/ * ADC12內存控制15 * /
DEFC(ADC12MCTL15,ADC12MCTL15_)
/ * ADC12CTL0 * /
#定義ADC12SC(0×001)/ * ADC12開始轉換* /
#定義ENC(0x002)/ * ADC12啟用轉換* /
#定義ADC12TOVIE(量0x004)/ * ADC12定時器溢出中斷使能* /
#定義ADC12OVIE(量0x008)/ * ADC12溢出中斷使能* /
#定義ADC12ON(量0x010)/ * ADC12開/使能* /
#定義REFON對*(量0x020)/ * ADC12參考/
#定義REF2_5V(量0x040)/ * ADC12參考0:1.5 V / 1:2.5 V * /
#定義MSC(量0x080)/ * ADC12多SampleConversion * /
#定義SHT00(0x0100u)/ * ADC12采樣保持0選擇0 * /
#定義SHT01(0x0200u)/ * ADC12采樣保持0選擇1 * /
#定義SHT02(0x0400u)/ * ADC12采樣保持0選擇2 * /
#定義SHT03(0x0800u)/ * ADC12采樣保持0選擇3 * /
#定義SHT10(0x1000u)/ * ADC12采樣保持0選擇0 * /
#定義SHT11(0x2000u)/ * ADC12采樣保持1選擇1 * /
#定義SHT12(0x4000u)/ * ADC12采樣保持2選擇2 * /
#定義SHT13(0x8000u)/ * ADC12采樣保持3選擇3 * /
#定義MSH(量0x080)
#定義SHT0_0(0 * 0x100u)/ * ADC12采樣保持0選擇位:0 * /
#定義SHT0_1(1 * 0x100u)/ * ADC12采樣保持0選擇位:1 * /
#定義SHT0_2(2 * 0x100u)/ * ADC12采樣保持0選擇位:2 * /
#定義SHT0_3(3 * 0x100u)/ * ADC12采樣保持0選擇位:3 * /
#定義SHT0_4(4 * 0x100u)/ * ADC12采樣保持0選擇位:4 * /
#定義SHT0_5(5 * 0x100u)/ * ADC12采樣保持0選擇位:5 * /
#定義SHT0_6(6 * 0x100u)/ * ADC12采樣保持0選擇位:6 * /
#定義SHT0_7(7 * 0x100u)/ * ADC12采樣保持0選擇位:7 * /
#定義SHT0_8(8 * 0x100u)/ * ADC12采樣保持0選擇位:8 * /
#定義SHT0_9(9 * 0x100u)/ * ADC12采樣保持0選擇位:9 * /
#定義SHT0_10(10 * 0x100u)/ * ADC12采樣保持0選擇位:10 * /
#定義SHT0_11(11 * 0x100u)/ * ADC12采樣保持0選擇位:11 * /
#定義SHT0_12(12 * 0x100u)/ * ADC12采樣保持0選擇位:12 * /
#定義SHT0_13(13 * 0x100u)/ * ADC12采樣保持0選擇
評論