P6SEL = 0x7F //管脚功能选择成ADC
ADC12CTL0=ADC12ON+MSC+SHT0_2+REFON+REF2_5V//打开ADC内核/连续采样/采样率设置/打开内部参考电压源/选择2.5V参考电压
ADC12CTL1 = SHP+CONSEQ_1 //采样信号来自采样定时器/序列通道单次转换模式
ADC12MCTL0 = INCH_0+SREF_1 //通道0/参考电压源选择内部参考电压
ADC12MCTL1 = INCH_1+SREF_1
ADC12MCTL2 = INCH_2+SREF_1
ADC12MCTL3 = INCH_3+SREF_1
ADC12MCTL4 = INCH_4+SREF_1
ADC12MCTL5 = INCH_5+SREF_1
ADC12MCTL6 = INCH_6+SREF_1+EOS//EOS序让雀列转换结束
ADC12IE = 0x40 //使能ADC中断
ADC12CTL0 |= ENC//允许转换
ADC12CTL0 |= ADC12SC//消滑亮开始转换
_EINT() //全局中断使能 }
interrupt[ADC_VECTOR] void ADC12ISR (void)
{
results[0] = ADC12MEM0 //将通拿宽道0采样结果读出,赋给RESULTS数组
results[1] = ADC12MEM1
results[2] = ADC12MEM2
results[3] = ADC12MEM3
results[4] = ADC12MEM4
results[5] = ADC12MEM5
results[6] = ADC12MEM6
//LED流水灯\x0d\x0a#include \x0d\x0avoid delay(unsigned int cnt) //局春枯简单的延时\x0d\x0a{\x0d\x0a while(--cnt)\x0d\x0a}\x0d\x0avoid main()\x0d\x0a{\x0d\x0a WDTCTL = WDTPW + WDTHOLD// 关狗\x0d\x0a P2DIR = 0xff// P2端口设置为输出森胡\x0d\x0a P2OUT=0xfe//给初始化值\x0d\x0a while(1)\x0d\x0a {\x0d\x0a delay(30000)//delay at crystal frequency in 12MHz\x0d\x0a P2OUT 回答于 2022-12-11//******************************************************************************// MSP-FET430P140 Demo - ADC12, Sample A0, Set P3.4 if A0 >派绝 0.5*AVcc
//
// Description: A single sample is made on A0 with reference to AVcc.
// Software sets ADC10SC to start sample and conversion - ADC12SC
// automatically cleared at EOC. ADC12 internal oscillator times sample (16x)
// and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC12
// conversion complete, ADC12_ISR will force exit from LPM0 in Mainloop on
// reti. If A0 >0.5*AVcc, P3.4 set, else reset.
//
// MSP430F149
// -----------------
// /|\尘世姿| XIN|-
// | | |
// --|RST XOUT|-
// | |
// Vin-->|P6.0/A0 P3.4|-->LED
//
// Dasheng
// LiTian Electronic Inc.
// Feb 2008
// Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include <msp430x14x.h>
#include "BoardConfig.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD// Stop WDT
ADC12CTL0 = SHT0_2 + ADC12ON// Set sampling time, turn on ADC12
ADC12CTL1 = SHP// Use sampling timer
ADC12IE = 0x01// Enable interrupt
ADC12CTL0 |= ENC// Conversion enabled
P6SEL |= 0x01// P6.0 ADC option select
P3DIR |= BIT4// P3.4 output
for ()
{
ADC12CTL0 |= ADC12SC// Sampling open
_BIS_SR(CPUOFF + GIE)// LPM0, ADC12_ISR will force exit
}
}
// ADC12 interrupt service routine
#pragma vector=ADC_VECTOR
__interrupt void ADC12_ISR (void)
{
if (ADC12MEM0 <0x7FF)
P3OUT &= ~BIT4// Clear P3.4 LED off
else
P3OUT |= BIT4//返没 Set P3.4 LED on
_BIC_SR_IRQ(CPUOFF)// Clear CPUOFF bit from 0(SR)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)