Sunday, August 23, 2009

LED Controlled by Parallel Port Using C#

This is my first article so if you are facing any problem or any other topic on which you want help then contact me my email address is
osama222_1@hotmail.com

This is my 3rd article for running this program or interfacing the parallel port through VB or C#.NET you need a dll file if you need it then do inform me on my email address or you can find it by your self the name of the dll is inpout32.dll

Parallel Port
A parallel port is a type of interface found on computers (personal and otherwise) for connecting various peripherals. It is also known as a printer port or Centronics port. The IEEE 1284 standard defines the bi-directional version of the port।
Port Address
Traditionally IBM PC systems have allocated their first three parallel ports according to the configuration in the table below.
PORT NAME
LPT1
LPT2
LPT3




Starting I/O
0x3bc
0x378
0x278


Ending I/O
0x3bf
0x37f
0x27f





if there is an unused LPTx slot, the port addresses of the others are moved up. (For example, if a port at 0x3bc does not exist, the port at 0x378 will then become LPT1.)[5] The IRQ lines, however, remain fixed (therefore, 0x378 at LPT1 would use IRQ 7)[citation needed]. Unfortunately the default IRQ used by the first two addresses is the same, and it's difficult to get correct interrupt behavior if both of these addresses are in use. The port addresses assigned to each LPTx slot can be determined by reading the BIOS Data Area (BDA) at 0000:0408.


Parallel port modes
The IEEE 1284 Standard which has been published in 1994 defines five modes of data transfer for parallel port. They are,
1) Compatibility Mode 2) Nibble Mode 3) Byte Mode 4) EPP 5) ECP


The programs, circuits and other information found in this tutorial are compatible to almost all types of parallel ports and can be used without any problems (Not tested, just because of confidence ! ). More information on parallel port operating modes can be found
HardwareThe pin outs of DB25 connector is shown in the picture below
The lines in DB25 connector are divided in to three groups, they are
1) Data lines (data bus) 2) Control lines 3) Status lines




As the name refers , data is transferred over data lines , Control lines are used to control the peripheral and of course , the peripheral returns status signals back computer through Status lines. These lines are connected to Data, Control And Status registers internally . The details of parallel port signal lines are given below


Running Condition








Interface or Layout Design




Code


Note: i just made a class of parallel_port in which i define the function so if you want to run the program then you have to made a class it is very simple just go to project menu then add class from there and the name of the class will be parallel_port and the class code will be given below just paste it and most important thing you must have to download inpout32.dll if you not find it then send me email i will send you i hope you enjyou it.....

Class Code


using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Controlling_home_appliance_SMS
{
class parallel_port_interfacing
{
//Call OutPut function from DLL file.
[DllImport("inpout32.dll", EntryPoint = "Out32")]
public static extern void Output(int adress, int value);
//Call Input functionfrom DLL file
[DllImport("inpout32.dll", EntryPoint = "Inp32")]
public static extern void Input(int adress);
}
class parallel_port
{
public void reset()
{
//heneral addresss are 888 and 632
parallel_port_interfacing.Output(888, 0);
}
public void light1()
{
parallel_port_interfacing.Output(888, 1);
}
public void light2()
{
parallel_port_interfacing.Output(888, 2);
}
public void light3()
{
parallel_port_interfacing.Output(888, 4);
}
public void light4()
{
parallel_port_interfacing.Output(888, 8);
}
public void light5()
{
parallel_port_interfacing.Output(888, 16);
}
public void all()
{
parallel_port_interfacing.Output(888, 31);
}
}
}


Main Form Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Controlling_home_appliance_SMS
{
public partial class Form1 : Form
{
parallel_port led = new parallel_port();
public Form1()
{
InitializeComponent();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
led.light1();
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
led.light2();
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
led.light3();
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
led.light4();
}
private void timer1_Tick(object sender, EventArgs e)
{

}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "light1")
{
led.light1();
label4.Text="light "+1+" On";
}
else if (textBox1.Text == "light2")
{
led.light2();
label4.Text = "light " + 2 + " On";
}
else if (textBox1.Text == "light3")
{
led.light3();
label4.Text = "light " + 3 + " On";
}
else if (textBox1.Text == "light4")
{
led.light4();
label4.Text = "light " + 4 + " On";
}
else if (textBox1.Text == "light5")
{
led.light5();
label4.Text = "light " + 5 + " On";
}
else if (textBox1.Text == "all")
{
led.all();
label4.Text = "all lights On";
}
else
{
led.reset();
label4.Text = "";
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
{
Application.Exit();
}
private void panel3_Paint(object sender, PaintEventArgs e)
{
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
led.light5();
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
led.all();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}




1 comment:

  1. When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from
    now on whenever a comment is added I get 4 emails with the same comment.
    There has to be an easy method you are able to remove me from that service?

    Many thanks!

    my site ... rent bar code scanners

    ReplyDelete