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

📄 main.c

📁 MC9S08QG8 Quick Start Examples,含ADC.C,KBI.GPIO.C等7个例程.
💻 C
字号:
/*******************************************************************
**  Filename    : main.c
**  Project     : kbi example
**  Processor   : MC9S08QG8
**  Version     : $v
**  Location    : h:\projects\freescale\kbi\
**  Author      : Jim McLean
**  Company     : Highlander Tech.
**  Date        : 10/23/2005, 3:33 PM
**  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 */
#include "main.h"


byte keypress;

void main(void) 
{

// set up kbi
  /* set pin mode and polarity if desired
  KBIES_KBEDG2 = 0; // 0 is low/falling edge
  KBIES_KBEDG3 = 0;
  KBISC_KBIMOD = 0; // 0 is edge, 1 is level/edge
  */
  
  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 outputs for status indicators 
  PTBDD_PTBDD7 = 1;   // set PTB7 as an output
  PTBDD_PTBDD6 = 1;   // set PTB6 as an output

  PTBD_PTBD6 = 0;   // port b6
  PTBD_PTBD7 = 0;   // port b7 

  EnableInterrupts; /* enable interrupts */

  for(;;) 
  {
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  
}// end of main



//KBI ISR
interrupt 18 void   KBI_ISR(void) 
  {
  keypress = PTAD;  // read port A to find which key
  
  if (keypress & 8)
    PTBD_PTBD6 = ~PTBD_PTBD6;     // toggle LED
  else
    PTBD_PTBD7 = ~PTBD_PTBD7;     // toggle LED
    
  KBISC_KBACK = 1;  // clear kb interrupt
  }







⌨️ 快捷键说明

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