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

 

5.1. Simple Experiment with LED - Serial Port

In this experiment we will show you how easy to transfer data serially. In this experiment we used a converter serial to parallel that we build up by using microcontroller chip. Data will be transfered serially from computer to LEDs board, as shown in picture bellow.

 

computer interfacing serial rs232

Delphi Programming ( Download file ex511.zip )

a. Puts 1 Edit Components, 1 Timer and label on Form, as shown in picture bellow. Configure Object Inspector for Timer1 as Enabled = True, Interval = 1000 ms, as shown in the picture bellow.

    computer interfacing serial rs232          computer interfacing serial rs232      

b.Click on timer1 component to insert with the program as shown bellow

var
 data,status:byte;
const
 base = $3f8;{base address port serial}
 lcr = 3; {line control register}
 dll = 0; {divisor lacht low byte}
 dlh = 1; {divisor lacht high byte}
 lsr = 5; {line status register}

implementation

{$R *.DFM}


Procedure Initserial;
begin
asm
mov dx,base+lcr; {address line control register}
mov al,$80 ; {10000000b = access bit divisor lacht}
out dx,al
;
mov dx,base+dll; {address divisor lacht low byte}
mov al,$30 ; {DLLB = 30h}
out dx,al
;
mov dx,base+dlh; {address divisor lacht high byte}
mov al,$00 ; {DLLH = 00h}
out dx,al
; {Pada saat ini Port serial}
; {memp.baud rate = 2400 bps}
mov dx,base+lcr; {address line control register}
mov al,$03 ; {00000011b =}
out dx,al ; {bit 7=0, access to Rx buffer & Tx
; {bit 6=0, set break disable
; {bit 5-4-3=000, no parity
; {bit 2=0, one stop bit
; {bit 1-0=11,data lenght 8 bit}
end;
end;
Procedure Send_Data_Serial;
begin
asm
mov dx,base
mov al,data
out dx,al
end
end; procedure TStoP.Timer1Timer(Sender: TObject);
begin
repeat
asm
mov dx,base+lsr ; {address line status register }
in al,dx
and al,$20 ; {00100000b =not masking bit 5}
mov status,al ; {bit5=Empty Transmitting holding reg}
end;
until status = $20; { If ETHR = 1 then data ready tobe send }
data:=strtoint(edit1.text);
Send_Data_Serial; end;

c. To run the program, you can hits F9 or RUN menu, and then you will show a picture as shown bellow, and try to simulate the program by writing a data on edit1 with range value 0 .. 255 in decimal.

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