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

📄 chap15.c

📁 Motorola 6812芯片开发的接口程序。
💻 C
字号:
// Chapter 15 6812 C programs// Jonathan W. Valvano// This software accompanies the book,// Embedded Microcomputer Systems: Real Time Interfacing// published by Brooks Cole, 1999//  Program 15.1. Real time data acquisition with a simple digital filter, Equation 2.// MC68HC812A4#define Rate 2000#define OC5  0x20#pragma interrupt_handler TOC5handler()void TOC5handler(void){   TFLG1=OC5;       // ack OC5F   TC5=TC5+Rate;    // Executed every 1 ms   x[1]=x[0];       // shift MACQ data   x[0] = A2D(channel);  // new data   y=(x[0]+x[1])>>1;}void ritual(void) { asm(" sei");     // make atomic  TIOS|=OC5;     // enable OC5  TSCR|=0x80;    // enable  TMSK2=0x32;    // 500 ns clock  TMSK1|=OC5;    // Arm output compare 5  x[0] = x[1] = 0;  TFLG1=OC5;     // Initially clear C5F  TC5=TCNT+Rate; // First one in 1 msasm(" cli"); }//  Program 15.2. Real time data acquisition with a simple digital filter, Equation 3.// MC68HC812A4#define OC5  0x20 #pragma interrupt_handler TOC5handler()void TOC5handler(void){ unsigned int i;   TFLG1=OC5;       // ack OC5F   TC5=TC5+5556;    // fs=360Hz   for(i=5;i>0;i++)        x[i]=x[i-1];      // shift MACQ data   x[0] = A2D(channel);  // new data   y=(x[0]+x[1]+x[2]+x[3]+x[4]+x[5])/6;}void ritual(void) { asm(" sei");     // make atomic  TIOS|=OC5;     // enable OC5  TSCR|=0x80;    // enable  TMSK2=0x32;    // 500 ns clock  TMSK1|=OC5;    // Arm output compare 5  x[0]=x[1]=x[2]=x[3]=x[4]=x[5]=0;  TFLG1=OC5;     // Initially clear C5F  TC5=TCNT+5556; asm(" cli"); } //  Program 15.3. Real time data acquisition with a simple digital filter, Equation 4.// MC68HC812A4#define OC5  0x20 #pragma interrupt_handler TOC5handler()void TOC5handler(void){    TFLG1=OC5;       // ack OC5F   TC5=TC5+5556;    // fs=360Hz   x[3]=x[2];       // shift MACQ data   x[2]=x[1];   x[1]=x[0];      x[0] = A2D(channel);  // new data   y=(x[0]+x[3])>>1;}     void ritual(void) { asm(" sei");     // make atomic  TIOS|=OC5;     // enable OC5  TSCR|=0x80;    // enable  TMSK2=0x32;    // 500 ns clock  TMSK1|=OC5;    // Arm output compare 5  x[0]=x[1]=x[2]=x[3]=0;  TFLG1=OC5;     // Initially clear C5F  TC5=TCNT+5556; asm(" cli"); }  // Program 15.4. Compiler listings for the filter implementation.; MC68HC812A4, ICC12; y=(x[0]+x[3])>>1;  ldab _x+3  ; 8-bit x[3]  clra       ; promote into RegD  std -10,x  ; save on stack  ldab _x    ; 8 bit x[0]  clra       ; promote into RegD  addd -10,x ; 16-bit x[0]+x[3]  asra  rolb       ; 16-bit shift  stab _y    ; demote to 8 bit  //   Program 15.5. Real time data acquisition with a simple digital filter, Equation 5.// MC68HC812A4#define Rate 2000#define OC5  0x20#pragma interrupt_handler TOC5handler()void TOC5handler(void){   TFLG1=OC5;       // ack OC5F   TC5=TC5+Rate;    // Executed at fs   y[1]=y[0];       // shift MACQ data   x = A2D(channel);  // new data   y[0]=(x+y[1])>>1;} // 16-bitvoid ritual(void) { asm(" sei");     // make atomic  TIOS|=OC5;     // enable OC5  TSCR|=0x80;    // enable  TMSK2=0x32;    // 500 ns clock  TMSK1|=OC5;    // Arm output compare 5  y[0] = y[1] = 0;  TFLG1=OC5;     // Initially clear C5F  TC5=TCNT+Rate; // First one in 1 msasm(" cli"); } // Program 15.6: The median filter is an example of a nonlinear filter.unsigned char Median(unsigned char u1,unsigned char u2,unsigned char u3){ unsigned char result;  if(u1>u2)    if(u2>u3)   result=u2;     // u1>u2,u2>u3       u1>u2>u3      else        if(u1>u3) result=u3;   // u1>u2,u3>u2,u1>u3 u1>u3>u2        else      result=u1;   // u1>u2,u3>u2,u3>u1 u3>u1>u2  else     if(u3>u2)   result=u2;     // u2>u1,u3>u2       u3>u2>u1      else        if(u1>u3) result=u3;   // u2>u1,u2>u3,u1>u3 u2>u1>u3        else      result=u1;   // u2>u1,u2>u3,u3>u1 u2>u3>u1  return(result):}unsigned char x[3],y;   // x[0] is x(n) the current sample// x[1] is x(n-1) the sample 1/fs ago// x[2] is x(n-2) the sample 2/fs agovoid sample(void){   x[2]=x[1];  // shift MACQ data   x[1]=x[0];      x[0] = A2D(0);  // new data from channel 0   y=median(x[0],x[1],x[2]); //    Program 15.7. Real time data acquisition with a 60 Hz notch digital filter, Equation 58.// MC68HC812A4#define OC5  0x20 #pragma interrupt_handler TOC5handler()void TOC5handler(void){    TFLG1=OC5;       // ack OC5F   TC5=TC5+8333;    // fs=240Hz   y[2]=y[1]; y[1]=y[0];  // shift MACQ   x[2]=x[1]; x[1]=x[0];      x[0] = A2D(channel);  // new data   y[0]=(113*(x[0]+x[2])-98*y[2])>>7;}     void ritual(void) { asm(" sei");     // make atomic  TIOS|=OC5;     // enable OC5  TSCR|=0x80;    // enable  TMSK2=0x32;    // 500 ns clock  TMSK1|=OC5;    // Arm output compare 5  y[0]=y[1]=y[2]=x[0]=x[1]=x[2]=0;  TFLG1=OC5;     // Initially clear C5F  TC5=TCNT+8333; asm(" cli"); } 

⌨️ 快捷键说明

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