⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 飞思卡尔单片机ad中断程序 编程环境codewarrior
💻 C
字号:
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

/*void wait() 
{
  int i,j;
  for(i=0;i<1000;i++)
   for(j=0;j<1000;j++) ;
    asm nop;
  
}
 */
void ADCInit(void)
{
  ATD0CTL2=0xC2;  //AD模块上电, 快速清零, 无等待模式
                  // 禁止外部触发, 中断开放
  ATD0CTL3=0x20;  // 每个序列4次转换, 
                  //No FIFO, Freeze模式下继续转换
  ATD0CTL4=0x83;  // 8位精度, 2个时钟, ATDClock=[BusClock*0.5]/[PRS+1]
                  //PRS=3, divider=8
  ATD0CTL5=0xA0;  //右对齐无符号,单通道采样,通道0
  ATD0DIEN=0x00;  // 禁止数字输入
}

word AD_wData = 0;

void main(void) 
{
  DisableInterrupts;
  ADCInit();   
  DDRB = 0xFF;
  PORTB  = 0x00;
  EnableInterrupts;
  for(;;) { } 
}

void interrupt 22 Int_AD0(void)
{
   DisableInterrupts;
   AD_wData = ATD0DR0;  //Read out the Result Register
   PORTB = (byte)AD_wData;
   //   wait();
   EnableInterrupts;
}

⌨️ 快捷键说明

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