www.pudn.com > avrepp.zip > hostepp.c
/**** A P P L I C A T I O N N O T E A V R 3 2 5 ************************ * * Title: High-speed Interface to Host EPP Parallel Port * Version: 1.0 * Last updated: 2001.12.20 * Target: All AVR Devices with 12 I/O pins or more * * Support E-mail: avr@atmel.com * * DESCRIPTION * This Application Note describes a method for high-speed bidirectional data * transfer between an AVR microcontroller and an off-the-shelf Intel x86 * desktop computer. * * This host program is constructed to talk to an AVR running AVREPP (over * an EPP link). * * It functions more or less as a terminal program, passing keyboard data * into the AVR, and displaying data from the AVR on the screen. The program * exits if ESC (0x1b) is typed. * * This program expects the EPP to be at LPT1 (0x378); to change this, change * PPORT below. * * This program was written for DOS Turbo-C 2.01 ***************************************************************************/ #include/* inp, outp */ #include /* kbhit() et al */ #define PPORT 0x378 /* LPT1 */ #define EPPSTAT(_p) ((_p)+1) /* EPP/SPP status register */ #define EPPDATA(_p) ((_p)+4) /* EPP data register */ #define SPPCTL(_p) ((_p)+2) /* SPP Control Register */ /* * status register bits */ #define EPPTIMEOUT 0x01 #define EPPBSY 0x80 #define EPPINTR 0x40 #define EPPINIT 0x04 /* 0bxxxx0100 */ #define ESC 0x1B /* use this to quit */ int main(int argc, char *argv[]) { unsigned char c, r; if (argc || argv) /* ARGSUSED */ ; outp(SPPCTL(PPORT), EPPINIT); /* FAMcK */ /* Forever (or at least until user types Esc): */ while (1) { /* Check keyboard side */ if (kbhit()) { /* Something typed -- pass it through */ c = getch(); /* get what user typed */ if (c == ESC) /* way-out */ break; outp(EPPDATA(PPORT), c); /* write to port */ } /* Check EPP (Rx) side. The EPP peripheral (the AVR) indicates */ /* that data is ready via the INTR signal. */ r = inp(EPPSTAT(PPORT)); if ((r & EPPBSY) == 0) /* powered down? */ continue; /* ignore it */ if (r & EPPINTR) /* intr is request to read */ { c = inp(EPPDATA(PPORT)); /* so do it */ r = inp(EPPSTAT(PPORT)); /* get the status register */ /* If we're following the protocol (reading only on EPPINTR) */ /* we should Never see a timeout. */ if (r & EPPTIMEOUT) { outp(EPPSTAT(PPORT), EPPTIMEOUT); /* clear it */ c = '@'; /* display '@' on timeout */ } putch(c); /* display on the screen */ } } /* end while(1) */ return(0); }