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

📄 chap11.c

📁 Motorola 6808嵌入式接口设计开发原程序
💻 C
字号:
// Chapter 11 6808 C programs// Jonathan W. Valvano// This software accompanies the book,// Embedded Microcomputer Systems: Real Time Interfacing// published by Brooks Cole, 1999//  Program 11.1. Software used to test how many bits are really needed.void DACout8(unsigned int code){     DACout(code&0xFFF0);}   // ignore bottom 4 bitsvoid DACout10(unsigned int code){     DACout(code&0xFFFC);}  // ignore bottom 2 bits//  Program 11.2. Periodic interrupt used to create the analog output waveform.unsigned int wave(unsigned int t){float result,time;time=2*pi*((float)t)/1000.0; // integer t in msec into floating point time in secondsresult=2048.0+1000.0*cos(31.25*time)-500.0*sin(125.0*time);return (unsigned int) result;}// Program 11.10. Software implementation of a ramp A/D.unsigned int rampAD(void){ unsigned int DOUT; // guess    DOUT = 0;             // start at minimum, V0=-5.00 (offset binary)    do {      DACout(DOUT);       // set D/A output, V0      DOUT++;             // ramp    }    while((!Z())&&(DOUT<4096));  // stop when V0>Vin or DOUT=4096    return(DOUT);}// Program 11.11. Software implementation of a tracking A/D.int DOUT; // guessvoid main(void){     DOUT = 2048;        // start in the middle, V0=0.00 (offset binary)    while(1) {      DACout(DOUT);     // set D/A output, V0      if(Z()) {         // check input        if(DOUT>0)      // don't go below 0           DOUT--;      // V0>Vin so decrement      }      else {        if(DOUT<4095)            DOUT++;      // V0<Vin so increment      }    }}// Program 11.12. Interrupting software implementation of a tracking A/D.#pragma interrupt_handler TOC5handler()void TOC5handler(void){   TFLG1=OC5;         // ack C5F    TC5=TC5+rate;    DACout(DOUT);      // set D/A output, V0   if(Z()) {          // check input      if(DOUT>0)      // don't go below 0         DOUT--;      // V0>Vin so decrement   }   else {      if(DOUT<4095)          DOUT++;      // V0<Vin so increment   }   DACout(DOUT);      // set D/A output, V0}// Program 11.13. Software implementation of a successive approximation A/D.unsigned int SuccAproxAD(void){ unsigned int DOUT,bit;     DOUT = 0;            for(bit=2048;bit;bit>>1){      DOUT |= bit;        // try to turn on this bit      DACout(DOUT);       // set D/A output, V0      if(Z())        DOUT ^= bit;      // too big, so remove this bit    }    return(DOUT);}

⌨️ 快捷键说明

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