?? chap14.c
字號:
// Chapter 14 6811 C programs// Jonathan W. Valvano// This software accompanies the book,// Embedded Microcomputer Systems: Real Time Interfacing// published by Brooks Cole, 1999 // Program 14.1. AART code to receive from an input-only full-duplex AART.// AART full duplex Input only, returns ID:S as 16-bitunsigned int GetAART(unsigned char addr){ // addr specifies which AART unsigned char ID,S; // inputs from AART OutCh(addr|0x80); // activate AART ID=InCh(); // read ID S=InCh(); // read status return((ID<<8)+S);} // return ID:S as 16-bit unsigned int// Program 14.2. AART code to receive from an input-only half-duplex AART.// AART half duplex Input only, returns ID:S as 16-bitunsigned int GetAART(unsigned char addr){ // addr specifies which AART unsigned char ID,S; // inputs from AART OutCh(addr|0x80); // activate AART InCh(); // read echo of previous addr output ID=InCh(); // read ID S=InCh(); // read status return((ID<<8)+S);} // return ID:S as 16-bit unsigned int// Program 14.3. AART code to transmit to an output-only half-duplex AART.// AART full duplex output onlyvoid PutAART(unsigned char addr,data){ // addr specifies which AART OutCh(addr|0x80); // activate AART OutCh(data&0x7F); // send data OutCh(addr|0x80);} // deactivate AART// Program 14.4. AART code to transmit to an output-only half-duplex AART.// AART half duplex output onlyvoid PutAART(unsigned char addr,data){ // addr specifies which AART OutCh(addr|0x80); // activate AART InCh(); // read echo of addr output OutCh(data&0x7F); // send data InCh(); // read echo of data output OutCh(addr|0x80); // deactivate AART InCh();} // read echo of previous output// Program 14.5. AART code to transmit then receive.// AART full duplex Output then Input, returns ID:S as 16-bitunsigned int PutGetAART(unsigned char addr,data){ // addr specifies which AART unsigned char ID,S; // inputs from AART OutCh(addr|0x80); // activate AART OutCh(data&0x7F); // send data ID=InCh(); // read ID S=InCh(); // read status return((ID<<8)+S);} // return ID:S as 16-bit unsigned int// Program 14.6. 6811 code to output on the parallel network./* Port C output handshake tristate output example */ #define STAF 0x80void main(void){ unsigned char Number; DDRC = 0x00; /* Port C are outputs, only when STRA=0 *//* STAI=0 no interrupts, HNDS=1, OIN=1 output handshake mode CWOM=0 normal push/pull outputs on C PLS=0 makes STRB a level output EGA=1 means STRA active on the rise INVB=0 makes STRB=0 after write CL */ PIOC = 0x1A; Number=100; OutC(Number); }void OutC(unsigned char data) { PORTCL=data; /* set PortC flip flops, and make STRB=0 *//* Port C data is driven only when STRA=0, otherwise Port C data=hiZ */ while ((PIOC & STAF) == 0); } /* wait for rise of STRA */// Program 14.7. Bit fifo routines.//********************GetTxBit************************// returns TRUE=1 if successful, FALSE=0 if empty and data not removed// output is boolean 0 means FALSE, nonzero is trueint GetTxBit (unsigned int *datapt) { if (SameBit(PutTxPt,GeTxtPt)) return(0); /* Failed, fifo was empty */ else { *datapt=(*GetTxPt.WPt)&GetTxPt.Mask; GetTxPt.Mask=GetTxPt.Mask>>1; if(GetTxPt.Mask==0) { GetTxPt.Mask=0x8000; ++GetTxPt.WPt; // next word if((GetTxPt.WPt)==&TxFifo[FifoSize]) GetTxPt.WPt=&TxFifo[0];} // wrap return(1); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -