di2713.txt LISTINGS 1 THROUGH 3 ;************************************************************************************************ ; LISTING 1 - ENCODE.H ; ; "Single printer-port pin acts as an encoder output," EDN, June 7, 2001, pg 156 ; ; http://www.ednmag.com/ednmag/reg/2001/060701/designideas.htm#13di4 ;************************************************************************************************ /****************************************************************************/ /*LIST 1. */ /* Routine Name "Encode.h" */ /* Use one line of printer port as encoder output */ /* Output from pin 2(d0 at 0x378h of PC's LPT1) of DB25 connector */ /****************************************************************************/ #include #include #include void codd12(int address,char data) { int i,j,k; unsigned char asd[2][3]={0,1,1,0,0,1}; /* when bit=1, then output '0 0 1' */ /* and bit=0, then output '0 1 1' */ for (i=0;i<4;i++) { for (j=0;j<36;j++) outa12(0); /* pilot periods */ outa12(1); /* 1/3 bit sync */ for (j=0;j<8;j++) /* 8 bits address */ for(k=0;k<3;k++) outa12(asd[(address>>j)&1][k]); for (j=0;j<4;j++) /* 4 bits data */ for(k=0;k<3;k++) outa12(asd[(data>>j)&1][k]); } outa12(0); /* Set D0=0 */ } /* Transmit pulse from D0 of printer port */ int T_delay; void outa12(int j) { int i; outportb(0x378, j&0x01); for(i=0;i