lpt-signal-generator: první verze
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 04 Jun 2017 14:57:42 +0200
changeset 44896eca3d40d8
parent 43 b54d76467040
child 45 ea8642c17495
lpt-signal-generator: první verze
c++/lpt-signal-generator/lpt.cpp
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/c++/lpt-signal-generator/lpt.cpp	Sun Jun 04 14:57:42 2017 +0200
     1.3 @@ -0,0 +1,57 @@
     1.4 +/**
     1.5 + * LPT signal generator
     1.6 + * Copyright © 2017 František Kučera (frantovo.cz)
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, either version 3 of the License, or
    1.11 + * (at your option) any later version.
    1.12 + *
    1.13 + * This program is distributed in the hope that it will be useful,
    1.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.16 + * GNU General Public License for more details.
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License
    1.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.20 + */
    1.21 +
    1.22 +#include <stdlib.h>
    1.23 +#include <iostream>
    1.24 +#include <stdio.h>
    1.25 +#include <math.h>
    1.26 +#include <sys/io.h>
    1.27 +#include <unistd.h>
    1.28 +
    1.29 +using namespace std;
    1.30 +
    1.31 +// g++ lpt.cpp && ./a.out
    1.32 +
    1.33 +int main() {
    1.34 +  cout << "LPT!" << endl;
    1.35 +
    1.36 +  //int addr = 0x378; // parport0
    1.37 +
    1.38 +  int addr = 0xe400; // parport1
    1.39 +
    1.40 +  //int addr = 0x278;
    1.41 +
    1.42 +  //int addr = 0xc800;
    1.43 +
    1.44 +
    1.45 +  if (ioperm(addr,1,1)) { fprintf(stderr, "Access denied to %x\n", addr), exit(1); }
    1.46 +
    1.47 +
    1.48 +  for (int i = 0; i < 30; i++) {
    1.49 +    cout << "cyklus" << endl;
    1.50 +    usleep(100*1000);
    1.51 +    outb(0b11111111, addr);
    1.52 +    usleep(10*1000);
    1.53 +    outb(0b00000000, addr);
    1.54 +  }
    1.55 +
    1.56 +
    1.57 +  cout << "hotovo" << endl;
    1.58 +
    1.59 +
    1.60 +}