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

📄 main.c

📁 MC9S08QG8 Quick Start Examples,含ADC.C,KBI.GPIO.C等7个例程.
💻 C
字号:
/*******************************************************************
**  Filename    : main.c
**  Project     : adc example
**  Processor   : MC9S08QG8
**  Version     : $v
**  Location    : h:\projects\freescale\adc\
**  Author      : Jim McLean
**  Company     : Highlander Technologies
**  Date        : 10/23/2005, 9:69 AM :)
**  Compiler    : Metrowerks CodeWarrior HC08 C Compiler
**  Notes       : HC9S08QG Quick Start Example
**              : This example can be used on the DEMO9S08QG8 board
**
*******************************************************************/

#include <hidef.h> /* for EnableInterrupts macro */
#include <MC9S08QG8.h> /* include peripheral declarations */

int keypress;
int ADC_val_H;
int ADC_val_L;


void main(void) 
  {

// set up kbi
  PTAPE_PTAPE2 = 1; // enable pullup for kb2
  PTAPE_PTAPE3 = 1; // enable pullup for kb3
  KBIPE_KBIPE2 =1;  // enable kb 2
  KBIPE_KBIPE3 =1;  // enable kb 3
  KBISC_KBACK = 1;  // clear kb interrupts
  KBISC_KBIE = 1;   // enable Keyboard Interrupts


// set up adc
  ADCSC1_ADCH = 0x1f; // all channels selected disables the ADC
  ADCSC1_AIEN = 1;    // enable ADC interrupt
  ADCSC1_ADCO = 0;    // enable single conversion, 1 is continuous conversion

  ADCSC2_ADTRG = 0;   // select software trigger
  ADCSC2_ACFE = 0;    // disable the compare function

  ADCCFG_ADICLK = 0; 	// bus clock
  ADCCFG_ADIV = 1; 	  // input clock/2
  ADCCFG_MODE = 0x00; // 10 bit mode
  ADCCFG_ADLSMP = 1; 	// long sample time

  APCTL1_ADPC2 = 1;
  //APCTL1 = 0x00;  // Disable all pins as ADC inputs
  												 
  EnableInterrupts;   // enable interrupts 


  for(;;) 
    {
    __RESET_WATCHDOG(); /* feeds the dog */
    }/* loop forever */
    /* please make sure that you never leave this function */
  
}// end main



//KBI ISR
interrupt 18 void   KBI_ISR(void) 
  {
  keypress = PTAD;  // read port a to find key
  
  if (keypress & 8)
    ADCSC1_ADCH = 0;
  else
    ADCSC1_ADCH = 1;
    
  KBISC_KBACK = 1;  // clear kb interrupt
  }

interrupt 19 void ADC_ISR(void) 
  {
  ADC_val_H = ADCRH;
  ADC_val_L = ADCRL;
  
  ADCSC1_ADCH = 0x1f; // all channels selected disables the ADC
  }

⌨️ 快捷键说明

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