新手上路
- 积分
- 29
- 金钱
- 29
- 注册时间
- 2017-4-12
- 在线时间
- 2 小时
|
发表于 2017-4-14 23:06:02
|
显示全部楼层
我之前用的149的AD中断代码,你可以参考一下:
[mw_shl_code=c,true]#define JINGDU 32
uint jieguo1[JINGDU];
uchar dianya[5];
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
GuanBiIO();
GuanBiSMG();
guan_dianpin;
guan_fengmingqi;
P6SEL |= 0x01;
LCDFuWei();
XianShiZiFuChuan(3,0,"Dian Ya :");
XianShi1ZiFu(10,1,'V');
ADC12CTL0 = ADC12ON+SHT0_8+MSC; // 打开ADC,设置采样时间
ADC12CTL1 = SHP+CONSEQ_2; // 使用采样定时器
ADC12IE = 0x01; // 使能ADC中断
ADC12CTL0 |= ENC; // 使能转换
ADC12CTL0 |= ADC12SC; // 开始转换
_EINT();
LPM0;
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR(void)
{
static uint cishu = 0;
jieguo1[cishu++] = ADC12MEM0;
if(cishu >= JINGDU)
{
cishu = 0;
unsigned long sum = 0;
for(uchar i=0;i<JINGDU;i++)
{
sum += jieguo1;
}
sum /= JINGDU;
DianYaZhuanHuan(sum,dianya);
XianShiNZiFu(5,1,4,dianya);
}
}[/mw_shl_code] |
|