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

📄 1.c

📁 一个用单片机跟普通键盘的通信程序
💻 C
字号:
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"


unsigned char data[10];
unsigned char  data_get=0;
unsigned char count=11;
unsigned char k=0;



void ect_init(void){
   DDRT=0x00;       //input
   TSCR1=0x80;      //enable timer
   TIOS=0x00;       //the correspond prot as input
   TCTL4=0x08;      /*channel 1 as capture on fall edge下沿*/
   TSCR2=0x07;      //div 128 for the bus clock 
   PACTL=0x00;
}

//TIE as the contcol of the intrrupt 





void main(void) {
  ect_init();
  TIE=0x02;  //start the intrrupt 
  DDRM=0x00;
  EnableInterrupts;
  PTM|=0x01;
  while(1);
  


}

#pragma CODE_SEG NON_BANKED
void interrupt 9 data_in(void) {
    
     TFLG1_C1F=1;  //clear the flag
     TIE=0x00;
     
     if(count>1){
           
       if(count<11&&count>2){
          data_get>>=1;
          if(PTM&0x01)
          data_get|=0x80;
       }
        count--;   
          
 
      
     
     }else{
       data[k++]=data_get;
       data_get=0;
       count=11;
     }

    TIE=0x02;
}

⌨️ 快捷键说明

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