computer interfacing tutorial-printer, serial, game, usb port
 

 

6.2. Simple Experiment on Game Port

6.2.1. Detecting Button Position

This program shows you how to read the buttons state. The main function is only used to display the buttons state, while pressed or not. In this experiment we used 4 button to simulate joystick, these button connected to pin 2,7,10 and 14 as shown in the picture bellow.

Delphi Programming ( Download File exp621.zip )

a.To read the button position, first you should prepare a form with 1 timer, 4 edit and labels component, as shown in the picture bellow. In timer1 component in object inspector, set up for the configuration as shown in the picture bellow.

             

b. Click twice on timer 1, and then insert instruction as shown bellow

procedure TForm1.Timer1Timer(Sender: TObject);
var data,button1,button2,button3,button4:byte;
begin
asm
mov dx,$201
mov al,0
out dx,al {write any value to $201}
mov dx,$201
in al,dx {gets data from $201}
mov data,al
end;
button1:=data and 16;
button2:=data and 32;
button3:=data and 64;
button4:=data and 128;
if button1=1 then edit1.text:='Open'
else edit1.text:='Close';
if button2=1 then edit1.text:='Open'
else edit2.text:='Close';
if button3=1 then edit1.text:='Open'
else edit3.text:='Close';
if button4=1 then edit1.text:='Open'
else edit4.text:='Close';
end;

c. To run the program, you must hit F9 or RUN from main menu, then you will see a picture as shown bellow. Try to simulate the program by pressing the button in the circuit.


        

PREVIOUS NEXT

 

Free Software
Delphi

Lesson 1
Delphi Programming
1.1. IDE Delphi
1.2. Component


Lesson 2
Printer Port
/ LPT
1.1.Basic
1.2.Address
1.3.Port Register
1.4.8 Bit Data Input
1.5.Test Circuitry
1.6.Assignment

Lesson 3
Printer Port / LPT
Experiments

3.1.LED
3.2.Swicht
3.3.Motor Stepper
3.4.DAC
3.5.ADC
3.6.Graph Display

Lesson 4
Serial Port

4.1.Basic
4.2.Hardware
4.3.Port Register

Lesson 5
Serial Port Experiments

5.1.LED
5.2.Stepper Motor
5.3.Swicht
5.4.ADC

Lesson 6
Game Port
Joy Stick
6.1. Basic
6.2. Experiments