You are on page 1of 8

4.1.

Basic Turn LED On-Off Serially- RS232 Serial

org 0h
nop
call initserial
gets: call inchar
mov P2,a
sjmp gets
;
initserial:
mov scon,#52h
mov tmod,#20h
mov th1,#-13
setb tr1
ret
;
inchar:
detect: jnb ri,detect;
clr ri
mov a,sbuf
ret
;
End
4.2. Controlling Rotation of LED Serially - RS232 Serial

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

4.3. Taking data of DIP Swicht serially.- Serial RS232

org 0h
nop
call initserial
gets: call inchar
mov P2,a
sjmp gets
;
initserial:
mov scon,#52h
mov tmod,#20h
mov th1,#-13
setb tr1
ret
;
inchar:
detect: jnb ri,detect;
clr ri
mov a,sbuf
ret
;
End

4.4. Send ADC data to PC serially - RS 232

org 0h
call initserial
;
start: mov a,p2; ambil data dari adc
call Sendout
sjmp start
;
Sendout:
detect: jnb ti,detect;
clr ti ;
mov sbuf,a ;
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
end

4.5. Writing a char serially from PC to LCD Character 2x16

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
ret
end
;

You might also like