Tuesday, 27 July 2010

The Complete Electronic Circuit

(Dancing Lamp #3)

In my previous tutorial, I’ve given you the example program and the LED circuit. But what you’ve got is only a small electronic circuit on your table. How about if you want to use bigger light bulbs instead of using LED. Here is the complete electronic circuit : 

You have to connect parallel port ground pin out to the circuit ground. Just be careful while connecting this circuit to your computer, or it will damage your computer !!! Make sure that everything is in the place.

Using this circuit, if you send a “high” to the data pin out (D0 .. D7), it will trigger the transistor. It will be saturated, and let current flows through the relay and the light bulb will be connected to the electricity and light on. Use this circuit for each data pin out of your parallel port.


Previous tutorials about dancing lamp :

Accessing your PC’s parallel port using Inpout32.dll in Delphi

LED Circuit


Monday, 26 July 2010

LED Circuit

(Dancing Lamp # 2)

To test the program I’ve created in my previous tutorial, I use this circuit (see picture). But be careful while you connect this circuit to your parallel port. Make sure that every component is in the right place or connection, otherwise it will damage your PC !!!

I use 1 KOhm resistors. If you send an integer data = 15 to the parallel port, D0…D3 LED will be light on. And D4…D7 LED will be off.

You can arrange which LED is on or off by writing some codes in Delphi. And you can also set the delay of each step you turn on or off the LED using OnTimer event of Timer component in Delphi. I’ve created an example program for you.

Download the example program here.

Go to previous tutorial (Accessing your PC’s parallel port using Inpout32.dll in Delphi)

Go to next tutorial (The Complete Electronic Circuit)

Monday, 19 July 2010

Accessing your PC’s parallel port using Inpout32.dll in Delphi

(Dancing Lamp # 1)

Before we create a dancing lamp using our PC’s parallel port, we have to know the parallel port female pin-out (see the picture below).

D0 is the LSB (Least Significant Bit) and D7 is the Most Significant Bit (MSB). You can send an integer type data to the D0..D7 pin-outs. And the output will be the binary form of the integer we send. For example : If we send an integer data 15 the output will be :

D7D6D5D4D3D2D1D0
LOWLOWLOWLOWHIGHHIGHHIGHHIGH

15 (byte) = 00001111 (binary)

How To Send Data To The Parallel Port ?

To send data to the parallel port I use a DLL file (Inpout32.dll) that can be downloaded at logix4u.net, and it’s free for non-commercial manner. Place this file in C:\WINDOWS\system or in the same folder with you project you’re going to create.

To use this file you can see my previous tutorial about using a DLL file. This DLL file contains a function called Out32(). The syntax of this function :

                                                    Out32(portaddress,data);

Usually, the port address is $378 (you can check the BIOS setting of your PC) 

Example program :

unit Unit1;

interface

uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   StdCtrls;

type
   TForm1 = class(TForm)
   Edit1: TEdit;
   Label1: TLabel;
   Button1: TButton;
   procedure FormActivate(Sender: TObject);
   procedure Button1Click(Sender: TObject);
private
  { Private declarations }
public
  { Public declarations }
end;

var
   Form1: TForm1;

implementation

{$R *.DFM}
function Out32(wAddr:word;bOut:byte):byte; stdcall; external 'inpout32.dll';

procedure TForm1.FormActivate(Sender: TObject);
begin
  Edit1.Text := '';
  Edit1.SetFocus; 
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Out32($378,StrToInt(Edit1.Text));
end;

end.

You can download the complete code here.

Go to next tutorial (LED Circuit)

Wednesday, 7 July 2010

Pointer

Pointer is a variable that points toward a memory address. So a pointer is a data address. The data is somewhere else. Below picture will show you the relationship between a pointer and a data pointed by a pointer.

To declare a pointer, use the below statement :

Type

   PointerType : ^Type;

In this case, type can be an integer, a real, an array or record. And you can see the example code of using a pointer :


program Project1;
   {$APPTYPE CONSOLE}
uses
   SysUtils;

type
   PointerType = ^integer;

var
   MyPointer : PointerType;
   Data : integer;

begin
  Data := 100;
  MyPointer := @Data;
  writeln('Data pointed toward by the pointer is ', MyPointer^);
  Data := 123;
  writeln('Data pointed toward by the pointer is ', MyPointer^);
  readln;
end.


Disposing pointer allocation

To free the memory that is used by a pointer, you can use dispose statement.

  Dispose(pointer);

Example :

program Project1;
   {$APPTYPE CONSOLE}
uses
   SysUtils;

var
   MyPointer : ^integer;

begin
  New(MyPointer); // allocate memory
  MyPointer^ := 100;
  writeln('Vallue pointed toward by MyPointer is ',MyPointer^);
  Dispose(MyPointer); // free memory allocation
  readln;
end.


You can download the complete code here.

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.