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

📄 chap7.c

📁 Motorola 6808嵌入式接口设计开发原程序
💻 C
字号:
// Chapter 7 6808 C programs// Jonathan W. Valvano// This software accompanies the book,// Embedded Microcomputer Systems: Real Time Interfacing// published by Brooks Cole, 1999// Program 7.19. C language initialization for a D/A interface using the SPI.// MC68HC708XL36void DACInit(void){ // PTF0=LD=1  DDRF|=0x07;  // PTF1=CLK=SPI clock out  PORTF|=0x01; // PTF2=SRI=SPI master out/* bit SPCR 7 SPRIE  = 0   no receive interrupts 6 DMAS   = 0   no DMA 5 SPMSTR = 1   master 4 CPOL   = 0   output changes on fall,  3 CPHA   = 0   clock normally low 2 SPWOM  = 0   regular outputs 1 SPE    = 1   enable SPI 0 SPTIE  = 0   no transmit interrupts */    SPCR=0x42;    SPSCR=0x00;} // 2 MHz clock// Program 7.20. C language function for a D/A interface using the SPI.// MC68HC708XL36#define SPRF 0x80void DACout(unsigned int code){ unsigned char dummy;   SPDR=0x00FF &(code>>8); // msbyte   while((SPSCR&SPRF)==0); // gadfly wait    dummy=SPDR;            // clear SPIF   SPDR=0x00FF& code;     // lsbyte   while((SPSCR&SPRF)==0); // gadfly wait    dummy=SPDR;            // clear SPIF   PORTF &= ~0x01;        // PTF0=LD=0   PORTF |= 0x01; }       // PTF0=LD=1// Program 7.21. C language initialization for an A/D interface using the SPI.// MC68HC708XL36void ADCInit(void){ // PTF0=CS=1  DDRF|=0x07;  // PTF1=SCLK=SPI clock out  PORTF|=0x01; // PTF2=DIN=SPI master out/* bit SPCR       PTF3=DOUT=SPI master in 7 SPRIE  = 0   no receive interrupts 6 DMAS   = 0   no DMA 5 SPMSTR = 1   master 4 CPOL   = 0   output changes on fall,  3 CPHA   = 0   clock normally low 2 SPWOM  = 0   regular outputs 1 SPE    = 1   enable SPI 0 SPTIE  = 0   no transmit interrupts */    SPCR=0x42;    SPSCR=0x00;} // 2 MHz clock #define CH0 0x9F#define CH1 0xDF#define CH2 0xAF#define CH3 0xEF// Program 7.22. C language function for an A/D interface using the SPI.// MC68HC708XL36unsigned int ADCin(unsigned char code){ unsigned int data;   PORTF &= ~0x01; // PTF0=CS=0   SPDR=code;    // set channel,mode   while((SPSCR&0x80)==0); // gadfly wait    data=SPDR;    // clear SPIF   SPDR=0;       // start SPI   while((SPSCR&0x80)==0); // gadfly wait    data=SPDR<<8; // msbyte of A/D   SPDR=0;       // start SPI   while((SP0SR&0x80)==0); // gadfly wait    data+=SPDR;    // lsbyte of A/D   PORTF |= 0x01; // PTF0=CS=1   return data>>3;} // right justify// Program 7.23. C language initialization of a temperature sensor interface using the SPI.// MC68HC812A4/MC68HC912B32 only// Program 7.24. C language helper functions for a temperature sensor interface using the SPI.// MC68HC812A4/MC68HC912B32 only// Program 7.25. C language functions for a temperature sensor interface using the SPI.// MC68HC812A4/MC68HC912B32 only

⌨️ 快捷键说明

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