logo

Select Sidearea

Populate the sidearea with useful widgets. Itโ€™s simple to add images, categories, latest post, social media icon links, tag clouds, and more.
[email protected]
+1234567890
 

Tutorial Microcontroller MCS-51 ATMEL ISP

Tutorial Microcontroller MCS-51 ATMEL ISP

image

Microcontroller Kits
Programmer and Target 89s51
image

Simple Mikrokontroller 89s51 Trainer
image

Standart
Mikrokontroller 89s51 Trainer
image

Super Mikrokontroller Trainer 89s51
image

All Item Include

Programmer
Via USB

image

ย 

ย 

BACKNEXT

4.2. Controlling Rotation of LED Serially – RS232 Serial

Standart communication using serial data RS232 is very efective way to minimize cable connection. This experiment will be done to arrange the rotation direction of LED by using DELPHI Programming and conducted serially.

Microcontroller Serial RS 232 communication

Figure 4.1. Sending Command to LED

ย 

Step 1st
Build the circuit as shown in figure 4.1. As you seen on figure 4.1. Remember, that all we want to do with this lesson is send data out trough PC serially, to direct LED rotation.

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 and hex : rotateRL.zipDownload Complete Circuit File : SerialLED.PDF )

     org 0h
nop
call initserial
gets:call inchar
cjne a,#1,rotR
sjmp rotL
sjmp gets

rotR:mov P2,#11111110b;
call delay
mov P2,#11111101b;
call delay ;
mov P2,#11111011b;
call delay ;
mov P2,#11110111b;
call delay ;
mov P2,#11101111b;
call delay ;
mov P2,#11011111b;
call delay ;
mov P2,#10111111b;
call delay ;
mov P2,#01111111b;
call delay ;
sjmp gets

rotL:mov P2,#01111111b;
call delay
mov P2,#10111111b;
call delay ;
mov P2,#11011111b;
call delay ;
mov P2,#11101111b;
call delay ;
mov P2,#11110111b;
call delay ;
mov P2,#11111011b;
call delay ;
mov P2,#11111101b;
call delay ;
mov P2,#11111110b;
call delay ;
sjmp gets

initserial:
mov scon,#52h ;serial mode 1 configuration
mov tmod,#20h ; Baud rate 2400 BPS
mov th1,#-13
setb tr1
ret

inchar:
detect: jnb ri,detect;detecting do data have been accepted or not yet. clr ri
mov a,sbuf
ret

delay:
MOV R7,#00H
again2: MOV R6,#00H
again1: MOV R5,#00H
again: INC R5
CJNE R5,#50H,again
INC R6
CJNE R6,#50H,again1
INC R7
CJNE R7,#50H,again2
RET

End

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 : rotateLED.zip )

image

(a)

image

(b)
Figure 4.2. Delphi Programming for Left or Right Rotate

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}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
; {In this case Port Serial have}
; { 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:=0;
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:=1;
Send_Data_Serial;
end;

Step 3rd
Safe your assembly program above, Compile the program that you have been save by using MIDE-51, see the software instruction.

Step 4th
Download your hex file (rotateRL.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

BACKNEXT

ย 

ย 

ย 

ย imageimageimageimage