main.c

来自「freescale 的HCS08的编程示例。 其一:ADC应用」· C语言 代码 · 共 56 行

C
56
字号
/*****************头文件*****************************************/
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

 /*********************变量和函数定义****************************/

unsigned int DATA;
void ADC_INI(void);
void IO_INIT(void);
 
 
 /*****************主函数*****************************************/
 void main(void) {

    EnableInterrupts; /* enable interrupts */
    /* include your code here */
  
    ADC_INI();
    IO_INIT();; 

    for(;;) {
   
        __RESET_WATCHDOG(); /* feeds the dog */
   
        ADC1SC1=0x28;  //选择通道号,使能adc转换
       
        while(!ADC1SC1_COCO)//
       
        __RESET_WATCHDOG();  
    
        DATA=ADC1R;
        if(DATA>=500)
            PTAD=0X02;
        else
            PTAD=0X00;
    
        ADC1SC1=0x1f; 
        
  } /* loop forever */
  /* please make sure that you never leave main */
}

/*****************adc中断*****************************************/
interrupt 19 void   ADC_INT(void) {

    ADC1SC1_COCO=0;    // clear TOF清标志位 
 
}

/*****************adc初始化*****************************************/
void ADC_INI(void) {

    ADC1SC1=0x28;//选择通道号,使能ADC  
    ADC1SC2=0x00;     
    ADC1CFG = 0x49;//四分频、10位模式、时钟源为总线时钟/2  
    APCTL2=0b00000001;  //选择管脚16(通道1

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?