Back to Aleksandar Masnikosa HP Back to GeoCities

THIS IS THE Borland Turbo Pascal unit for Driving LED display through parallel port

unit DisPara;

interface
type  TPortArray   = array[0..4,0..6] of byte;
      TScanLine    = array[0..6] of 0..1;
      TScreenArray = array[0..4,0..6] of 0..3;

const NumberImagesArray:
array[$0..9,0..4,0..4] of byte=
                         (((0,(0),1,0,0),
                           (0,(1),0,1,0),
                    {0}    (0,(1),0,1,0),
                           (0,(1),0,1,0),
                           (0,(0),1,0,0)),

                          ((0,(0),1,0,0),
                           (0,(1),1,0,0),
                    {1}    (0,(0),1,0,0),
                           (0,(0),1,0,0),
                           (0,(0),1,0,0)),

                          ((0,(0),1,0,0),
                           (0,(1),0,1,0),
                    {2}    (0,(0),0,1,0),
                           (0,(0),1,0,0),
                           (0,(1),1,1,0)),

                          ((0,(1),1,0,0),
                           (0,(0),0,1,0),
                    {3}    (0,(0),1,0,0),
                           (0,(0),0,1,0),
                           (0,(1),1,0,0)),

                          ((0,(1),0,1,0),
                           (0,(1),0,1,0),
                    {4}    (0,(1),1,1,0),
                           (0,(0),0,1,0),
                           (0,(0),0,1,0)),

                          ((0,(1),1,1,0),
                           (0,(1),0,0,0),
                    {5}    (0,(1),1,0,0),
                           (0,(0),0,1,0),
                           (0,(1),1,0,0)),

                         ((0,(0),1,1,0),
                          (0,(1),0,0,0),
                   {6}    (0,(1),1,0,0),
                          (0,(1),0,1,0),
                          (0,(0),1,0,0)),

                         ((0,(1),1,1,0),
                          (0,(0),0,1,0),
                   {7}    (0,(0),1,0,0),
                          (0,(0),1,0,0),
                          (0,(0),1,0,0)),

                         ((0,(1),1,1,0),
                          (0,(1),0,1,0),
                   {8}    (0,(1),1,1,0),
                          (0,(1),0,1,0),
                          (0,(1),1,1,0)),

                         ((0,(0),1,0,0),
                          (0,(1),0,1,0),
                   {9}    (0,(0),1,1,0),
                          (0,(0),0,1,0),
                          (0,(1),1,0,0)));

      DataPortActiveArray:TPortArray =(($3F,$5F,$6F,$77,$7B,$7D,$7E),
                                       ($3F,$5F,$6F,$77,$7B,$7D,$7E),
                                       ($3F,$5F,$6F,$77,$7B,$7D,$7E),
                                       ($3F,$5F,$6F,$77,$7B,$7D,$7E),
                                       ($BF,$DF,$EF,$F7,$FB,$FD,$FE));

      CtrlPortActiveArray:TPortArray =(($0A,$0A,$0A,$0A,$0A,$0A,$0A),
                                       ($09,$09,$09,$09,$09,$09,$09),
                                       ($0F,$0F,$0F,$0F,$0F,$0F,$0F),
                                       ($03,$03,$03,$03,$03,$03,$03),
                                       ($0B,$0B,$0B,$0B,$0B,$0B,$0B));
      DataPort=$378; {Base addres of parallel port}
      CtrlPort=DataPort+2;
var LastValueOfCtrlPort:byte;
    UsedForBlinking:longint;

Procedure CellOn(xk,yk:byte);
Procedure HorizontalScan(EnteringLine:TScanLine;EnteringRow:byte);
Procedure TheWorldIsYoursScan(EnteringArray:TScreenArray);
Procedure DisplayOff;

implementation

Procedure CellOn(xk,yk:byte);
{Give it coordinates of point you want to be turned on. That diode would 
be lit and every other would be turned off. Appropriate for aplications like
sound osciloscopes, mouse pointers or simple brick and ball game. If you 
want diodes to shine better use the HorizontalScan}
var WriteCtrl,WriteData:byte;
begin
  WriteData:=DataPortActiveArray[yk,xk];
  WriteCtrl:=CtrlPortActiveArray[yk,xk];

  if WriteCtrl=LastValueOfCtrlPort then
     asm
       mov dx,DataPort
       mov al,WriteData
       out dx,al
     end
  else
   asm
     mov dx,DataPort
     mov al,WriteData
     out dx,al
     add dx,2
     mov al,WriteCtrl
     out dx,al
   end;
  LastValueOfCtrlPort:=WriteCtrl;
end;

Procedure HorizontalScan(EnteringLine:TScanLine;EnteringRow:byte);
{Give it a variable of TScanLine type(array [0..6] of 0..1]) 0 for OFF, 
1 for ON, and row you want to be lit.Turns on only EnteringRow leaving 
others rows off}
var i,WriteData,WriteCtrl:byte;
begin
  WriteData:=$7F;
  WriteCtrl:=CtrlPortActiveArray[EnteringRow,0];
  for i:=0 to 6 do
  begin
    if EnteringLine[i]=1 then
       WriteData:=WriteData and DataPortActiveArray[EnteringRow,i];
  end;
  if EnteringRow=4 then WriteData:=WriteData or $80;
  asm
    mov dx,CtrlPort
    mov al,WriteCtrl
    out dx,al
    sub dx,2
    mov al,WriteData
    out dx,al
  end;
end;

Procedure TheWorldIsYoursScan(EnteringArray:TScreenArray);
{Whoooow-Multimedia- it turns on, off or blinks one or more diodes depending}
{on the value of element in EnteringArray:                                  }
{0-turn of       1-turn on      2-blinking     3-not implemented            }
{experiment with UsedForBlinking to adjust it for your computer speed       }
var i,j,WriteData,WriteCtrl:byte;
begin
  WriteCtrl:=CtrlPortActiveArray[0,0];
  inc(UsedForBlinking);
  If UsedForBlinking>1000 then UsedForBlinking:=0; {experiment with different values }
  for i:=4 downto 0 do
  begin
    WriteData:=$7F;
    for j:=0 to 6 do
    begin
      if EnteringArray[i,j]=1 then
         WriteData:=WriteData and DataPortActiveArray[i,j];

      if EnteringArray[i,j]=2 then
         if (UsedForBlinking mod 4000)<250 then    {experiment with different values}
            WriteData:=WriteData and DataPortActiveArray[i,j]
         else
            WriteData:=WriteData or (1 shl j);

      WriteCtrl:=CtrlPortActiveArray[i,0];
    end;
    if i=4 then WriteData:=WriteData or $80;
    asm
      mov dx,CtrlPort
      mov al,WriteCtrl
      out dx,al
      sub dx,2
      mov al,WriteData
      out dx,al;
    end;
  end;
end;

Procedure DisplayOff;
{Turns DisplayOff thus saving your paralel port from unnecessery power }
{disipation. Use it on the begining and end of your application.       }
begin
  Port[DataPort]:=$7F;
  Port[CtrlPort]:=$0B;
end;
begin
  UsedForBlinking:=0;
  LastValueOfCtrlPort:=0;
end.
end.
Author: Aleksandar Masnikosa October '97
E-mail:masnikosa@yahoo.com
1