rendered paste body/**
*LED_v2.c
*
*
*Januar 29, 2007
*Autor: Kevin Heim
*E-mail: badboyKevin@web.de
*/
/**ACHTUNG: DAS PROGRAMM LAEUFT NUR MIT DER ROOT BERECHTIGUNG!!!!!!!*/
#include <stdio.h>
#include <sys/io.h>
/* base addresses of the serial ports */
#define PORT_COM1 0x3F8
#define PORT_COM2 0x2F8
/* modem control register (base address + 4) */
#define REG_MCR( port ) ( port + 4 )
#define REG_LCR( port ) ( port + 3 )
#define REG_MSR( port ) ( port + 6 )
/* bit pattern to set the RTS bit */
#define BIT_RTS 0x02
#define BIT_DTR 0x01
#define BIT_TXD 0x40
#define BIT_CTS 0x10
#define BIT_DSR 0x20
#define BIT_RI 0x40
#define BIT_DCD 0x80
/* bit pattern to clear the RTS bit */
#define BIT_CLR_RTS 0x00
/* define to set 1 ( TRUE ) */
#define TRUE 1
#define START_RTS outb( BIT_RTS, REG_MCR( PORT_COM1 ) );
#define STOP_RTS outb( BIT_CLR_RTS, REG_MCR( PORT_COM1 ) );
int main()
{
ioperm( PORT_COM1, 8, 1 );
// to rewind the programm
while ( TRUE )
{
int auswahl;
printf ("------------------------------------------------------------\n");
printf ("Dies ist eine Simulation zwischen verschiedener Logikgattern\n");
printf ("------------------------------------------------------------\n");
printf ("Achtung um Volladdierer auszuführen brauchen sie eine \n");
printf ("Platine und eine Serielleschnittstelle und sie brauchen\n");
printf ("Root Rechte! Diese Pins werden gebraucht! DCD DSR CTS \n" );
printf ("TxD DTR RTS!! \n");
printf ("------------------------------------------------------------\n");
printf ("Volladdierer --> 1\n");
printf ("Hilfe --------> 2\n");
printf ("Simulation ----> 3\n");
printf ("Exit --------> 4\n");
printf ("Eingabe : ");
scanf ("%d",&auswahl );
if ( auswahl == 1 ) activate_volladdierer();
if ( auswahl == 2 ) activate_help();
if ( auswahl == 3 ) activate_simu();
if ( auswahl == 4 ) return ( 0 );
if ((auswahl <=0 ) || (auswahl >= 5 ))
{
printf ("Ihre eingabe ist Ungültig!\n");
}
}
}
int activate_volladdierer()
{
// to activate the input pins
START_RTS;
unsigned char read_msr,dsr,cts,dcd;
// read the register and read the bits of cts dsr dcd
read_msr = inb( REG_MSR( PORT_COM1) );
cts = read_msr & BIT_CTS;
dsr = read_msr & BIT_DSR;
dcd = read_msr & BIT_DCD;
//check the input pins
if ( cts == 0x00 & dsr == 0x00 & dcd == 0x00)
{
printf ( "Die Summe ist 0\n" );
printf ( "Der Übertrag ist 0\n" );
}
if ( cts == 0x00 & dsr == 0x00 & dcd == 0x80)
{
printf ( "Die Summe ist 1\n" );
printf ( "Der Übertrag ist 0\n" );
outb( BIT_DTR, REG_MCR( PORT_COM1 ) );
sleep( 2 );
}
if ( cts == 0x00 & dsr == 0x20 & dcd == 0x00)
{
printf ( "Die Summe ist 1 Dezimal\n" );
printf ( "Der Übertrag ist 0\n" );
outb( BIT_DTR, REG_MCR( PORT_COM1 ) );
sleep( 2 );
}
if ( cts == 0x00 & dsr == 0x20 & dcd == 0x80)
{
printf ( "Die Summe ist 0 Dezimal\n" );
printf ( "Der Übertrag ist 1\n" );
outb( BIT_TXD, REG_MCR( PORT_COM1 ) );
sleep( 2 );
}
if ( cts == 0x10 & dsr == 0x00 & dcd == 0x00)
{
printf ( "Die Summe ist 1 Dezimal\n" );
printf ( "Der Übertrag ist 0\n" );
outb( BIT_DTR, REG_MCR( PORT_COM1 ) );
sleep( 2 );
}
if ( cts == 0x10 & dsr == 0x00 & dcd == 0x80)
{
printf ( "Die Summe ist 1 Dezimal\n" );
printf ( "Der Übertrag ist 0\n" );
outb( BIT_DTR, REG_MCR( PORT_COM1 ) );
sleep( 2 );
}
if ( cts == 0x10 & dsr == 0x20 & dcd == 0x00)
{
printf ( "Die Summe ist 0 Dual\n" );
printf ( "Der Übertrag ist 1\n" );
outb( BIT_TXD, REG_MCR( PORT_COM1 ) );
sleep( 2 );
}
if ( cts == 0x10 & dsr == 0x20 & dcd == 0x80)
{
printf ( "Die Summe ist 1 Dual\n" );
printf ( "Der Übertrag ist 1\n" );
outb( BIT_DTR, REG_MCR( PORT_COM1 ) );
outb( BIT_TXD, REG_MCR( PORT_COM1 ) );
sleep( 2 );
}
STOP_RTS;
}
int activate_help()
{
printf ( "Diese Pins werden für Folgende zwecke verwendet:\n" );
printf ( "CTS = x \n" );
printf ( "DSR = y \n" );
printf ( "DCD = Cin oder Übertrag\n" );
printf ( "DTR = S oder Summe \n" );
printf ( "TXD = Cout oder entstandener Übertrag\n" );
printf ( "RTS = Stromversorgung für CTS DSR DCD \n" );
printf ( "Mit diesem Programm können sie einen Volladdierer Simulieren\n" );
printf ( "Sie brauchen dazu nur eine Serielle Schnittstelle\n");
printf ( "und eine geeignete platine zum einlesen und ausgeben aller Pins\n");
printf ( "\n");
printf ( "Bei einer Simulation brauchen sie keine Platine oder eine Serielle Schnittstelle\n");
printf ( "Wenn sie nicht wissen was ein Volladdierer ist\n" );
printf ( "Dann informieren sie sich bitte auf wikipedia!\n" );
printf ( "Dieses Programm wurde geschrieben von Kevin Heim \n");
}
int activate_simu()
{
int a,b,c;
printf ( "Bitte alles in Dualzahlen eingeben!\n");
printf ( "Geben sie x ein: ");
scanf ( "%d",&a );
printf ( "Geben sie y ein: ");
scanf ( "%d",&b );
printf ( "Geben sie den Übertrag ein: ");
scanf ( "%d",&c );
//check the input of scanf
if ( (a >= 2 | a <= -1)|(b >= 2 | b <= -1)|(c >= 2 | c <= -1) )
{
printf ( "Falsche eingabe!\n");
return ( 0 );
}
//check of the input vars
else
{
if ( a == 0 & b == 0 & c == 0 )
{
printf ( "Die Summe ist 0\n" );
printf ( "Der Übertrag ist 0\n" );
return ( 0 );
}
if ( a == 0 & b == 0 & c == 1 )
{
printf ( "Die Summe ist 1\n" );
printf ( "Der Übertrag ist 0\n" );
return ( 0 );
}
if ( a == 0 & b == 1 & c == 0 )
{
printf ( "Die Summe ist 1 Dezimal\n" );
printf ( "Der Übertrag ist 0\n" );
return ( 0 );
}
if ( a == 0 & b == 1 & c == 1 )
{
printf ( "Die Summe ist 0 Dezimal\n" );
printf ( "Der Übertrag ist 1\n" );
return ( 0 );
}
if ( a == 1 & b == 0 & c == 0 )
{
printf ( "Die Summe ist 1 Dezimal\n" );
printf ( "Der Übertrag ist 0\n" );
return ( 0 );
}
if ( a == 1 & b == 0 & c == 1 )
{
printf ( "Die Summe ist 1 Dezimal\n" );
printf ( "Der Übertrag ist 0\n" );
return ( 0 );
}
if ( a == 1 & b == 1 & c == 0 )
{
printf ( "Die Summe ist 0 Dual\n" );
printf ( "Der Übertrag ist 1\n" );
}
if ( a == 1 & b == 1 & c == 1 )
{
printf ( "Die Summe ist 1 Dual\n" );
printf ( "Der Übertrag ist 1\n" );
return ( 0 );
}
}
}