Microcontroller Kits
Programmer and Target 89s51
Simple Mikrokontroller 89s51 Trainer
Standart
Mikrokontroller 89s51 Trainer
Super Mikrokontroller Trainer 89s51
All Item Include
ย
4.5. Writing a char serially from PC to LCD Character 2×16
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
Build the circuit as shown in figure 4.2. As you seen on figure 4.2. Remember, that all we want to do with this lesson transmit.
Step 2nd
In this step, you must tipe the assembly program to make your serial working, we assume that you have already known the editor, we used MIDE-51 to edit the program. ( Download File asm : exp42.zip ,Download Complete Circuit File : SerialLCD.PDF )
org 0h call initserial
call init_LCD;start: call GetChar
mov r1,#0c0h
acall write_inst
add a,#30h
mov r1,a
acall write_data
sjmp start;GetChar:
detect: jnb ri,detect ; clr ri
mov a,sbuf
ret;
initserial: mov scon,#52h;initialize serial mode 1 mov tmod,#20h;timer1 mode 2 mov th1,#0F3h;Reload value for baud rate 2400 setb tr1 ret;Init_lcd: mov r1,#00000001b ;Display clear acall write_inst ; mov r1,#00111000b ;Function set, ;Data 8 bit,2 line font 5x7 acall write_inst ; mov r1,#00001100b ;Display on,
;cursor off,cursor blink off acall write_inst mov r1,#00000110b ;Entry mode, Set increment acall write_inst ret
Write_inst:
clr P2.0 ; RS = P2.0 = 0, write mode instruction
mov P0,R1 ; D7 s/d D0 = P0 = R1
setb P2.1 ; EN = 1 = P2.1
call delay; call delay time
clr P2.1 ; EN = 0 = P2.1
ret;Write_data:
setb P2.0 ; RS = P2.0 = 1, write mode data
mov P0,R1 ; D7 s/d D0 = P0 = R1
setb P2.1 ; EN = 1 = P2.1
call delay; call delay time
clr p2.1 ; EN = 0 = P2.1
ret;delay: mov R0,#0
delay1:mov R7,#0fh
djnz R7,$
djnz R0,delay1
retend;
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 )
Figure 4.3. Delphi Programming Sends Data to LCD Character
unit sendlcd2;interfaceusesWindows, 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 endend;
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
Safe your assembly program above, and name it with seri2.asm (for example) Compile the program that you have been save by using MIDE-51, see the software instruction.
Step 4th
Download your hex file ( exp42.hex ) into the microcontroller by using Microcontroller ATMEL ISP software, see the instruction.After download this hex file you’ll see the action of serial transmition( of course if your cable connection and your program are corrected ).
Comments, questions and discussion about this topic
ย
ย
ย