www.pudn.com > ADC.rar > main.c


/*              ADC模块例程 
 
             HCS908_QG8 单片机开发板  
 
实验介绍: 
    本程序是ADC模块的例程,所用资源为单片机内部ADC转换模块, 
所接器件为电位器.确定你开发板上拨码开关JP2(图片上的6)的1位 
处于on(这位是和电位器的连接),而其他位处于远离on! 
 
实验现象: 
    在仿真界面的DATA1窗口中观察mm的值是否随电位器输出值变化而变化 
 
 
author:QGL 
 
any question mail me: 
libing.qu@free-tech.com.cn  
*/ 
 
/*****************头文件*****************************************/ 
#include  /* for EnableInterrupts macro */ 
#include "derivative.h" /* include peripheral declarations */ 
 
 /*********************变量和函数定义****************************/ 
 
unsigned int DATA; 
void ADC_INI(void); 
  
  
 /*****************主函数*****************************************/ 
 void main(void) { 
 
    EnableInterrupts; /* enable interrupts */ 
    /* include your code here */ 
   
    ADC_INI();  
 
    for(;;) { 
    
        __RESET_WATCHDOG(); /* feeds the dog */ 
    
        ADCSC1=0x20;  //选择通道号,使能adc转换 
        
        while(!ADCSC1_COCO)// 
        
        __RESET_WATCHDOG();   
     
        DATA=ADCR; 
     
        ADCSC1=0x1f; //禁止ADC转换 
  } /* loop forever */ 
  /* please make sure that you never leave main */ 
} 
 
/*****************adc中断*****************************************/ 
interrupt 19 void   ADC_INT(void) { 
 
    ADCSC1_COCO=0;    // clear TOF清标志位  
  
} 
 
/*****************adc初始化*****************************************/ 
void ADC_INI(void) { 
 
    ADCSC1=0x20;//选择通道号,使能ADC   
    ADCSC2=0x00;      
    ADCCFG = 0x49;//四分频、10位模式、时钟源为总线时钟/2   
    APCTL1=0b00000001;  //选择管脚16(通道1) 
    ADCSC1=0x1f; //禁止 ADC  
}