?? chap7.c
字號:
// Chapter 7 6805 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.// MC68HC05C8void DACInit(void){ // PD5=LD=1 DDRD|=0x38; // PD4=CLK=SPI clock out PORTD|=0x20; // PD3=SRI=SPI master out/* bit SPCR 7 SPIE = 0 no interrupts 6 SPE = 1 enable SPI 4 MSTR = 1 master 3 CPOL = 0 output changes on fall, 2 CPHA = 0 clock normally low 1 SPR1 = 0 1 MHz operation 0 SPR0 = 0 */ SPCR=0x50;}// Program 7.20. C language function for a D/A interface using the SPI.// MC68HC05C8#define SPRF 0x80void DACout(unsigned int code){ unsigned char dummy; SPDR=0x00FF &(code>>8); // msbyte while((SPSR&SPIF)==0); // gadfly wait dummy=SPDR; // clear SPIF SPDR=0x00FF& code; // lsbyte while((SPSR&SPIF)==0); // gadfly wait dummy=SPDR; // clear SPIF PORTD &= ~0x20; // PD5=LD=0// Program 7.21. C language initialization for an A/D interface using the SPI.// MC68HC05C8void ADCInit(void){ // PD5=CS=1 DDRD|=0x38; // PD4=SCLK=SPI clock out PORTD|=0x20; // PD3=DIN=SPI master out/* bit SPCR PD2=DOUT=SPI master in 7 SPIE = 0 no interrupts 6 SPE = 1 enable SPI 4 MSTR = 1 master 3 CPOL = 0 output changes on fall, 2 CPHA = 0 clock normally low 1 SPR1 = 0 1 MHz operation 0 SPR0 = 0 */ SPCR=0x50;} #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.// MC68HC05C8unsigned int ADCin(unsigned char code){ unsigned int data; PORTD &= ~0x20; // PD5=CS=0 SPDR=code; // set channel,mode while((SPSR&0x80)==0); // gadfly wait data=SPDR; // clear SPIF SP0DR=0; // start SPI while((SPSR&0x80)==0); // gadfly wait data=SPDR<<8; // msbyte of A/D SPDR=0; // start SPI while((SPSR&0x80)==0); // gadfly wait data+=SPDR; // lsbyte of A/D PORTD |= 0x20; // PD5=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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -