Serial Port Microcontroller Experiment (SPME)

OBJECTIVE

  1. Students understand the serial port interface circuit
  2. Students understand how to configure serial communication on a PC serial port.
  3. Students understand how to write assembly language for serial port configuration.
  4. Students understand how to write Delphi programming for communication with microcontrollers.


Figure 10.1 Microcontroller serial communication system with PC

One of the most powerful communications to implement in a digital communication system is communication by utilizing the RS232 serial line. The 89s51 microcontroller has a UART facility, so it can communicate serially with the RS2322 level between equipment or with a computer. MAX232 is an IC that functions to change the TTL format to RS232 or vice versa.


Figure 10.2. MAX232 schematic circuit

Experiment 10.1 Sending data serially from PC to microcontroller with LED output

In this experiment, data is sent via the PC serial communication port serially and captured by the microcontroller to be output to the LED.


Experiment 10.1 Sending data serially from PC to microcontroller with LED output

Do some trial steps as follows:

  1. Connect the connector jumper to LED_EN
  2. Connect the Microcontroller Trainer module to the +5V power supply.
  3. Connect the Microcontroller Trainer module to the programmer circuit 
  4. Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
  5. Type the following assembly program: ( download the file prog101a.asm )
    org 0h
               nop
               call initserial
    gets: call inchar
               mov P0,a
               sjmp gets
               ;
    initserial:
               mov scon,#52h ; Konfigurasi komunikasi serial mode 1
               mov tmod,#20h ; Baud rate 2400 BPS
               mov th1,#-13
               setb tr1
               ret
               ;
    inchar:
    detect: jnb ri,detect ; Deteksi bit RI apakah data sudah diterima atau            belum
               clr ri
               mov a,sbuf
               ret
               ;
               End
  6. Open Delphi Program
  7. Type the following Delphi program, to run communication via serial port with base address 3F8h. ( download file Ledserial.asm )

    LED Testing File
    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.Button1Click(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:=1;
               Send_Data_Serial;
    end;
    procedure            TForm1.Button2Click(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:=2;
               Send_Data_Serial;
    end;
    procedure            TForm1.Button3Click(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:=4;
               Send_Data_Serial;
    end;
    procedure            TForm1.Button4Click(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:=8;
               Send_Data_Serial;
    end;
    procedure            TForm1.Button5Click(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:=16;
               Send_Data_Serial;
    end;
    procedure            TForm1.Button6Click(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:=32;
               Send_Data_Serial;
    end;
    procedure            TForm1.Button7Click(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:=64;
               Send_Data_Serial;
     end;
    procedure            TForm1.Button8Click(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:=128;
               Send_Data_Serial;
    end;
    procedure            TForm1.Button9Click(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:=0;
               Send_Data_Serial;
    end;
    procedure            TForm1.Button10Click(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:=255;
               Send_Data_Serial;
    end;
    1. Save the program you typed and name it: prog101a.asm
    2. In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
    3. Program the microcontroller using the ISP Software Program (See Instructions for Use) 
    4. Run the Delphi program by pressing the F9 or RUN button.
    5. Press each button and observe.
    | Button | Keadaan LED ( Nyala/ Padam ) |
    |--------|------------------------------|
    | 1      |                              |
    | 2      |                              |
    | 4      |                              |
    | 8      |                              |
    | 16     |                              |
    | 32     |                              |
    | 64     |                              |
    | 128    |                              |
    | 255    |                              |

Post a Comment

Previous Next

نموذج الاتصال