📄 snowmakingcontrol.c
字号:
/* * snowmakingcontrol v0.1 9/25/01 * www.embeddedlinuxinterfacing.com * * The original location of this code is * http://www.embeddedlinuxinterfacing.com/chapters/07/snowmakingcontrol.c * * * Copyright (C) 2001 by Craig Hollabaugh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* snowmakingcontrol * snowmakingcontrol uses outb system calls to control an interface * circuit connected the PC parallel printer port. The port's * control port drives the interface circuit's output latch signals. *//*remember to compile with -O2 for proper inb/outb macro expansiongcc -O2 -o snowmakingcontrol snowmakingcontrol.c*/#include <asm/io.h>#define SPPDATAPORT 0x378#define SPPSTATUSPORT (SPPDATAPORT + 1)#define SPPCONTROLPORT (SPPDATAPORT + 2)/* these are the control port bit defs */#define OUTPUTENABLE 0x02#define OUTPUTLATCH 0x04#define INPUTENABLE 0x08#define SPPPORTREAD 0x20int main(int argc, char *argv[]){/* get permission from the OS to use the * data, status and control ports*/ if (ioperm(SPPDATAPORT, 3, 1)) { perror("ioperm"); exit(1); }/* Use OUTPUTENABLE to keep output latch enabled */ outb(OUTPUTENABLE ,SPPCONTROLPORT); /* put the first char of command line argument 1 on the data bus */ outb(argv[1][0],SPPDATAPORT);/* assert OUTPUTLATCH, this latches the data bus to the latch's * outputs, driving the output module rack */ outb(OUTPUTENABLE | OUTPUTLATCH ,SPPCONTROLPORT); //latch data/* Use OUTPUTENABLE to keep output latch enabled */ outb(OUTPUTENABLE ,SPPCONTROLPORT); /* let OS know we're done with the port */ if (ioperm(SPPDATAPORT, 3, 0)) { perror("ioperm"); exit(1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -