![]() |
||||||
| Microcontroller Kits Simple
Mikrokontroller 89s51 Trainer All Item Include
|
4.5. Writing a char serially from PC to LCD Character 2x16
This experiment will be done for process to print character out to LCD Character, in this experiment the delivery is just for one character, you need to modify to write more character. You should learn more about Serial communication RS232.
Figure 4.2. Transmit data serially to LCD Character
Step 1st Step 2nd org 0h
call initserial
To get the data from microcontroller serially, computer must run the program to get data from port communication RS232, in this experiment I have been used Delphi programming: ( Download File Delphi : LCDserial.zip )
unit sendlcd2; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Timer1: TTimer;
Label3: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
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 TForm1.FormCreate(Sender: TObject); begin Initserial; end; procedure TForm1.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;
end.
Step 3rd Comments, questions and discussion about this topic
|
|
||||