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

 

5.3. Gets Data ADC - 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 ADC board to Personal computer, as shown in picture bellow.

computer interfacing serial rs232

Delphi Programming ( Download file ex513.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
P2S: TP2S;
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 TP2S.FormCreate(Sender: TObject);
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
; {In this case Port serial has a 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 Receive_Data_Serial;
begin
asm
mov dx,base
in al,dx
mov data,al
end
end; 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 TP2S.Button1Click(Sender: TObject);
begin
initserial;
timer1.enabled:=true;
end; procedure TP2S.Timer1Timer(Sender: TObject);
begin
Repeat
asm
mov dx,base+lsr; { address line status register }
in al,dx
and al,$01 ; {LSR = 00000001b, deteksi bit 0}
mov status,al ; {bit 0 = data ready}
end;
until status = $01 ;{ jika bit 0 = 1 then data ready}
Receive_Data_Serial;
edit1.text:=inttostr(data);
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.

computer interfacing serial rs232

 

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