⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppdev.c

📁 at51系列单片机编程源码
💻 C
字号:
/* ---------------------------------------------------------------------------- * ppdev.c * this module contains all functions cope with the parallel port * * Copyright 2003/2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * ----------------------------------------------------------------------------*/#ifdef HAVE_CONFIG_H#  include <config.h>#endif#include <stdio.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <sys/ioctl.h>#include <linux/ppdev.h>#include "isp-at89.h"/* Parallel port stuff *//* This function takes the given parportdevice, checks if   is a valid character device and if so, claim it.   It returns a filehandle on success, otherwise ERROR. */intparport_gethandle (char *ppdev){	int rc = ERROR;#ifndef __powerpc__	if (getFileStatus(ppdev) == FST_CHARDEV) {		if((rc = parport_claim (ppdev)) == ERROR)			printf (_("-- ERROR: Couldn't claim parport device [%s]\n"), ppdev);	} else		printf (_("-- ERROR: Have problems accessing parport device [%s]: %s\n"), ppdev, strerror(errno));#else	rc = 0xAA55;  /* random value */#endif	return rc;}/* open /dev/parportX device and claim it. * The return value is a file descriptor or -1 * in case of error. */intparport_claim(char *dev){	int fd, rc = ERROR;	long dummy = 0;	if ((fd = open(dev, O_RDWR )) > 0) {		if ((ioctl (fd, PPCLAIM, &dummy)) != 0) {			close (fd);		} else {			ioctl (fd, PPWDATA, &dummy);   /* clear parport */			rc = fd;		}	}	return rc;}voidparport_release (int fd){#ifndef __powerpc__	long dummy = 0;	ioctl (fd, PPWDATA, &dummy);   /* clear parport */	ioctl (fd, PPRELEASE, &dummy);	close (fd);#endif}unsigned charparport_wdata (int fd, unsigned char wdata){	unsigned char rdata = 0;	ioctl (fd, PPWDATA, &wdata);	ioctl (fd, PPRSTATUS, &rdata);#ifdef DEBUG	debug_adddata (wdata, rdata);#endif	return ((rdata >> MISO_BIT) & 1);     /* return atmel's reaction */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -