/*-------------------------------------------------------------------------- * Routines based on Toulouse University Technology Institute * Electronics Engineering Dpt. Hardware * * Written By - Philippe Latu / philippe.latu(at)linux-france.org * $Id: iut_msc1210.h 1142 2007-05-20 16:52:23Z latu $ * * Copyright (C) 2007 Philippe Latu * * 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 FITNES0S 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * *---------------------------------------------------------------------------*/ #ifndef __IUT_MSC1210_H #define __IUT_MSC1210_H /* Custom types definitions */ typedef unsigned long uint32; typedef unsigned int uint16; typedef int int16; typedef unsigned char uint8; typedef signed char int8; /* Device addressing * Addresses are hardware dependant and should be changed * to fit hardware requirements */ __sbit __at (0x80) P0_0; // p0.0 __sbit __at (0x81) P0_1; // p0.1 __sbit __at (0x82) P0_2; // p0.2 __sbit __at (0x83) P0_3; // p0.3 __sbit __at (0x84) P0_4; // p0.4 __sbit __at (0x85) P0_5; // p0.5 __sbit __at (0x86) P0_6; // p0.6 __sbit __at (0x87) P0_7; // p0.7 __sbit __at (0x93) CK_OUT; // p1.3 __sbit __at (0x96) OUT_8; // p1.6 __sbit __at (0x97) OUT_9; // p1.7 __sbit __at (0xb2) IN_9; // p3.2 __sbit __at (0xb3) G_IN; // p3.3 __sbit __at (0xb4) IN_8; // p3.4 unsigned int lecture_10bits(void) { __idata unsigned int dipswitch = 0; G_IN = 0; dipswitch = P0; G_IN = 1; if (P3 & 0x10) dipswitch |= 0x100; if (P3 & 0x04) dipswitch |= 0x200; return dipswitch; } bit lecture_1bit(unsigned char b) { __bit in1bit; if (b < 8) { G_IN = 0; in1bit = (P0 >> b) & 1; G_IN = 1; } else if (b == 8) in1bit = IN_8; else if (b == 9) in1bit = IN_9; else in1bit = 0; return in1bit; } void ecriture_10bits(unsigned int leds) { P0 = leds; CK_OUT = 0; CK_OUT = 1; OUT_8 = (leds & 0x100) >> 8; OUT_9 = (leds & 0x200) >> 9; } void ecriture_1bit(unsigned char b, bit val) { if (b < 8) { switch (b) { case 0: P0_0 = val; break; case 1: P0_1 = val; break; case 2: P0_2 = val; break; case 3: P0_3 = val; break; case 4: P0_4 = val; break; case 5: P0_5 = val; break; case 6: P0_6 = val; break; case 7: P0_7 = val; break; } CK_OUT = 0; CK_OUT = 1; } else if (b == 8) OUT_8 = val; else if (b == 9) OUT_9 = val; } #endif