// oh3nwq 25.2.2007 // // reads a 24 bit counter a nibble at a time // using parallel port // work flow // send 0 // send 0x10 = latch enable // send 0 // send 1 = read 1st byte from counter to PIC 16F84 memory // send 0 // send 2 = read 2nd byte from counter to PIC 16F84 memory // send 0 // send 3 = read 3rd byte from counter to PIC 16F84 memory // send 0 // send 4 = read 4th byte from counter to PIC 16F84 memory // send 0 //LOOP send 13..6; //LOOP read nibble x from PIC 16F84 memory //LOOP send 0 #include #include #include #include #define wbase 0x378 /* printer port base address */ #define rbase 0x379 /* I/O address to read */ main(int argc, char **argv) { int value,rvalue,inverted,nibble; int j; value = 0; if (ioperm(wbase,1,1)) fprintf(stderr, "Couldn't get the port at %x\n", wbase), exit(1); outb(value, wbase); // start with 0 if (ioperm(rbase,1,1)) fprintf(stderr, "Couldn't get the port at %x\n", rbase), exit(1); value = 0x10; outb(value, wbase); // latch enable for (j=0;j<2000000;j++); value = 0x00; outb(value, wbase); for (j=0;j<2000000;j++); // latch disable value = 0x01; outb(value, wbase); // read byte 1 for (j=0;j<2000000;j++); value = 0x00; outb(value, wbase); for (j=0;j<2000000;j++); // done value = 0x02; outb(value, wbase); // read byte 2 for (j=0;j<2000000;j++); value = 0x00; outb(value, wbase); for (j=0;j<2000000;j++); // done value = 0x03; outb(value, wbase); // read byte 3 for (j=0;j<2000000;j++); value = 0x00; outb(value, wbase); for (j=0;j<2000000;j++); // done value = 0x04; outb(value, wbase); // read byte 4 for (j=0;j<2000000;j++); value = 0x00; outb(value, wbase); for (j=0;j<2000000;j++); // done printf("0x"); for (value=13;value>5;value--){ outb(value, wbase); for (j=0;j<100000;j++); rvalue = inb(rbase); nibble = ((rvalue >> 3) & 0x0f); printf("%X", nibble); j=0; outb(j, wbase); for (j=0;j<100000;j++); } printf("\n"); }