📄 hardware.c
字号:
/* Classic Ladder Project *//* Copyright (C) 2001 Marc Le Douarain *//* mavati@club-internet.fr *//* http://www.multimania.com/mavati/classicladder *//* January 2002 *//* Last update : 19 January 2002 *//* ------------------ *//* Hardware Interface *//* ------------------ *//* This library is free software; you can redistribute it and/or *//* modify it under the terms of the GNU Lesser General Public *//* License as published by the Free Software Foundation; either *//* version 2.1 of the License, or (at your option) any later version. *//* This library 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 *//* Lesser General Public License for more details. *//* You should have received a copy of the GNU Lesser General Public *//* License along with this library; if not, write to the Free Software *//* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <asm/io.h>#include "classicladder.h"#include "vars_access.h"#include "hardware.h"/* hardware support wanted ? */#ifdef HARDWARE_SUPPORTvoid ReadPhysicalInputs(){ unsigned char RegPar1 = 0x00; unsigned char RegPar2 = 0x00; unsigned char Mask; unsigned char InputNum;#ifdef USE_PARPORT1 RegPar1 = inb(PARPORT1_IO_ADDRESS + 1); RegPar1 = ~RegPar1; /* S7 is inverted */ if (RegPar1 & 0x80) RegPar1 = RegPar1 & 0x7F; else RegPar1 = RegPar1 | 0x80;#endif#ifdef USE_PARPORT2 RegPar2 = inb(PARPORT2_IO_ADDRESS + 1); RegPar2 = ~RegPar2; /* S7 is inverted */ if (RegPar2 & 0x80) RegPar2 = RegPar2 & 0x7F; else RegPar2 = RegPar2 | 0x80;#endif /* Inputs of parallel port 1 : S3->S7 are mapped on I3->I7 */ Mask = 0x01; for (InputNum=0; InputNum<8; InputNum++) { WriteVar(VAR_PHYS_INPUT,InputNum,(RegPar1 & Mask)?1:0); Mask = Mask<<1; } /* Inputs of parallel port 2 : S3->S7 are mapped on I23->I27 */ Mask = 0x01; for (InputNum=20; InputNum<28; InputNum++) { WriteVar(VAR_PHYS_INPUT,InputNum,(RegPar2 & Mask)?1:0); Mask = Mask<<1; }}void WritePhysicalOutputs(){ unsigned char RegPar1 = 0x00; unsigned char RegPar2 = 0x00; unsigned char Mask; unsigned char OutputNum; /* Outputs of parallel port 1 : D0->D7 are mapped on Q0->Q7 */ Mask = 0x01; for (OutputNum=0; OutputNum<8; OutputNum++) { if (ReadVar(VAR_PHYS_OUTPUT,OutputNum)) RegPar1 = RegPar1|Mask; Mask = Mask<<1; } /* Outputs of parallel port 2 : D0->D7 are mapped on Q20->Q27 */ Mask = 0x01; for (OutputNum=20; OutputNum<28; OutputNum++) { if (ReadVar(VAR_PHYS_OUTPUT,OutputNum)) RegPar2 = RegPar2|Mask; Mask = Mask<<1; }#ifdef USE_PARPORT1 outb(RegPar1,PARPORT1_IO_ADDRESS);#endif#ifdef USE_PARPORT2 outb(RegPar2,PARPORT2_IO_ADDRESS);#endif}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -