Paralelni port [long]

Tomas Rett rett na chmi.cz
Středa Říjen 27 13:48:38 CEST 2004


Dekuji. Skvele. Odkud pochazi ?

Dne st 27. října 2004 09:17 jste napsal(a):
> Takze hadam vam pomoze tento zdrojak :
>
> void dsend(int byte) - zapis dat na dat. zbernicu
> int dget(void) - nacitanie dat z dat zbernice
>
> #include <unistd.h>
> #include <sys/perm.h>
> #include <asm/io.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <time.h>
>
> #define lpt1            0x378
> #define lpt2            0x278
>
> #define us              1000
> #define ms              1000000
> #define s               1000000000
>
> class parport {
> 	public:
> 		parport(int baseport);
> 		~parport();
> 		int bitronic;
>
> 		void dsend(int byte);
> 		int dget(void);
> 		void csend(int byte);
> 		int status(void);
>
> 		void nsleep(unsigned int ns);
> 	private:
> 		short int base;
> 		struct timespec ts;
> 		int lastcmd;
> };
>
> parport::parport(int baseport)
> {
> 	base = baseport;
> 	ioperm(base, 3, 1);
> 	ts.tv_sec=bitronic=lastcmd=0;
> 	dsend(0);
> 	csend(0);
> }
>
> parport::~parport()
> {
> 	ioperm(base, 3, 0);
> }
>
> void parport::dsend(int byte)
> {
> 	if (!bitronic)
> 	{
> 		outb(byte, base);
> 	} else {
> 		bitronic=0;
> 		csend(lastcmd);
> 		outb(byte, base);
> 		bitronic=1;
> 		csend(lastcmd);
> 	}
> }
>
> int parport::dget(void)
> {
> 	if (bitronic)
> 	{
> 		return inb(base);
> 	} else {
> 		bitronic=1;
> 		csend(lastcmd);
> 		int res=inb(base);
> 		bitronic=0;
> 		csend(lastcmd);
> 		return res;
> 	}
> }
>
> void parport::csend(int byte)
> {
> 	lastcmd=byte;
> 	if (!bitronic)
> 	{
> 		outb((byte & 7) ^ 2, base+2);
> 	} else {
> 		outb(((byte & 7) ^ 2) | 32, base+2);
> 	}
> }
>
> int parport::status(void)
> {
> 	return (inb(base+1) ^ 200) >> 3;
> }
>
> void parport::nsleep(unsigned int ns)
> {
> 	ts.tv_nsec = ns;
> 	nanosleep(&ts, &ts);
> }

-- 
Tomas Rett



Další informace o konferenci Linux