You are on page 1of 35

8051 PROGRAMMING

Ravi K Biradar

1
8051 Programming
Program for Seven Segment Display.
Program for LCD.
Program to rotate Stepper Motor.

2
Interfacing with
8051

3
LCD DISPLAY
Interfacing with
8051

4
 Liquid Crystal Display
(LCD)

Light wave is
polarized and twisted
when no voltage is
applied

Light wave is blocked


when voltage is
applied

5
6
7
8
9
10
11
12
13
14
15
Program for
ORG 0000H
LCD
; PROGRAM TO DISPLAY MESSAGE ON LCD

LJMP START
START: MOV A,#38H ; Initialize 2 line display of 5X7
matrix.
LCALL CMD
MOV A,#0EH ; Display On, Cursor On.
LCALL CMD
MOV A,#01H ; Clear display.
LCALL CMD
MOV A,#06H ; Shift Cursor to right.
LCALL CMD
MOV A,#83H ; Mov Cursor to begining of 1st
line.
LCALLof
Addresses CMD
LCD display individual
locations
80 81 82 83 . . . . . 8F
C0 . . .. .. .. . . . CF
16
MOV A,#'W' ;W
LCALL DISP
MOV A,#'E' ;E
LCALL DISP
MOV A,#'L' ;L
LCALL DISP
MOV A,#'C' ; C
LCALL DISP
MOV A,#'O' ;O
LCALL DISP
MOV A,#'M' ;M
LCALL DISP
MOV A,#'E' ;E
LCALL DISP
MOV A,#‘ ' ; SPACE
LCALL DISP
MOV A,#0C2H ; Mov Cursor to begining of 2nd
line.
LCALL CMD
17
MOV A,#'P' ;P
LCALL DISP
MOV A,#'I' ;I
LCALL DISP
MOV A,#'I' ; I
LCALL DISP
MOV A,#'T' ;T
LCALL DISP
MOV A,#',' ; COMMA
LCALL DISP
MOV A,#' ' ; SPACE
LCALL DISP

18
CMD: MOV P0,A
MOV P1,#0F4H ; E = 1 & RS = 0
LCALL DELAY
MOV P1,#0F0H ; E = 0 & RS = 0
LCALL DELAY
RET E R/W RS
1 1 1 1 0 1 0 0 F4H
1 1 1 1 0 0 0 0 F0H
DISP: MOV P0,A
MOV P1,#0F5H ; E = 1 & RS = 1
LCALL DELAY
MOV P1,#0F1H ; E = 0 & RS = 1
LCALL DELAY
RET E R/W RS
1 1 1 1 0 1 0 1 F5H
DELAY: MOV A,#0FFH
1 1 1 1 0 0 0 1 F1H
BACK: DEC A
JNZ BACK
RET
END

19
LST
FILE

20
LST
FILE

21
LST
FILE

22
LST
FILE

23
STEPPER MOTOR
Interfacing with
8051

24
•Normally the motor with which we deal in our daily
life are DC motors.

•They rotates in a constant velocity and we can not


determine the angle of rotation.

•But a stepper motor divides a full rotation into


numbers of small steps and the position and the
angle of the rotor can be controlled by the user.

25
The unipolar stepper motors has four coils . The
opposite two coils are connected with each
other (Shorted) as you can see in the picture.
You will notice while working with a stepper
motor that it has six wires. Two of them are the
common terminal as mentioned and they need
to be connected to Vcc or GND .

26
A Unipolar Stepper Motor is rotated by energizing the stator coils in a
sequence. In unipolar stepper, the direction of current in stator coils is
not required to be controlled by the driving circuit. Just applying the
voltage signals across the motor coils or motor leads in a sequence is
sufficient to drive the motor.

A two phase unipolar stepper motor has a total of six wires/leads of


which four are end wires (connected to coils) and two are common wires.
The color of common wires in the stepper motor used here is Green.

27
In present case the common (Green) wires are connected to Vcc. The
end points receive the control signals as per the controller's output in a
particular sequence to drive the motor.
Signal sequence for Wave Drive Stepping Mode
St Yellow lead Blue lead Red lead White lead
ep (End point 1 (End point 2 (End point 1 (End point 2 of
of Phase1) of Phase1) of Phase2) Phase2)
1 1 0 0 0
2 0 0 1 0
3 0 1 0 0
4 0 0 0 1

28
 Full Drive Stepping
Mode
The Full Drive Stepping can be achieved by energizing two endpoints of
different phases simultaneously. 
Signal sequence for Full Drive Stepping Mode
St Yellow lead Blue lead Red lead White lead
ep (End point 1 (End point 2 (End point 1 (End point 2 of
of Phase1) of Phase1) of Phase2) Phase2)
1 1 0 1 0
2 0 1 1 0
3 0 1 0 1
4 1 0 0 1

29
Half Drive Stepping
Mode
The Half Drive Stepping is achieved by combining the
steps of Wave and Full Drive Stepping Modes. This
divides the stepping angle by half.
Signal sequence for Half Drive Stepping Mode
St Yellow lead Blue lead Red lead White lead
ep (End point 1 of (End point 2 of (End point 1 of (End point 2 of
Phase1) Phase1) Phase2) Phase2)
1 1 0 0 0
2 1 0 1 0
3 0 0 1 0
4 0 1 1 0
5 0 1 0 0
6 0 1 0 1
7 0 0 0 1
8 1 0 0 1 30
31
❖The stepping angle depends upon the resolution
of the stepper motor. The direction of rotation and
size of steps is directly related to the order and
number of input sequence. 

❖ The shaft rotation speed depends on the


frequency of the input sequence. The torque is
proportional to the number of magnets
magnetized at a time.

32
33
Program for Stepper
Motor;********* DELAY ********
; PROGRAM TO ROTATE STERRPER
MOTOR IN CLOCKWISE DIRECTION DELAY: MOV A, #0FFh
ORG 0000H PUSH ACC
LJMP START DLY1: MOV A, #0FFh
START: MOV P1, #08H NOP
LCALL DELAY DLY2: NOP
MOV P1, #04H DEC A
LCALL DELAY JNZ DLY2
MOV P1, #02H POP ACC
LCALL DELAY NOP
MOV P1, #01H DEC A
LCALL DELAY JZ DLYEND
LJMP START NOP
PUSH ACC
JMP DLY1
NOP
DLYEND:NOP
RET
LJMP START
34
END
LST
FILE

35

You might also like