Escolar Documentos
Profissional Documentos
Cultura Documentos
METRO.
In this project we show that how we design a prototype of the small metro
with auto show the station on the lcd display. This metro is run on the dc
gear motor. With the help of this gear motor we slow down the speed of the
vehicle to show all the function properly. metro train is auto stop on 5
things.
Once you press the start switch train complete one cycle.
VOICE ANNOUNCEMENT
this train we use infra red sensor in the front of the car and in the back of the
car. Two infra red sensor at the bottom of the car to sense the station.
In this project we use ic lm339 with the infra red sensor . Here in this
project four infra red sensor. Two sensor at the bottom of the car and two
track. Data transfer to the lcd in parallel . 8 wires from the microcontroller
auto braking and show the detail of different station on the lcd.
One H bridge circuit to control the movement of the train for forward and
reverse. For this purpose we use four transistor circuit with two npn and two
pnp transistor.
COMPONENTS USED:
MICROCONTROLLER 89S51
SUPPLY.
LCD DISPLAY = TO DISPLAY ALL THE STATION NAME
INFRA RED + PHOTODIODE PAIR( for auto stop, auto reverse, logic)
TRANSISTOR CIRCUIT;
MOTOR.
FABRICATION
V
Circuit working.
In this project we use one microcontroller 89s51 to control all the function of
the this prototype metro. Here we use 89s51 controller. One Dc gear motor
with the microcontroller to run the metro for forward and reverse direction.
display to display all the station name on the lcd. One op-amp amplifier to
interface with the proximity sensor. One voice processor circuit to produce
the pre recorded sound when train leave the station. In this project we
generate a 6 pre recorded sound. We can change the sound any time with
recording facility through external condenser mike. Here we use APR 9600
VOICE PROCESSOR.
V
2
1
+
5
0
8
7 M
H
O
0
7
4
0
1 v
2
1
+
D
.E
L k
0
1
D
D
FM
03
1 I
7
0
4
n
FM
v
2
1
+ v
2
1
+ v
5
+ 294
1 2 1
5
0001
0001
E
0
7
4 9
3
3
8 7
8 6
1
7
3 9
0
1 7
k
3 4
DC motor control:
v
5
+ v
5
+ K
0
1 D
.E
L 6
3
5
3 1
9
3
lM 1 4
3
3 2
1
3
1
e
0
7
4
E
IO
.D
P v
2
-1 v
5
+ 1
5
0
2
C
9
8 2
3 4
1 4561
8
2
E
0
7
4 7
2
5
+
v +
v
5
DEL. R.I
D
.E
L
6
2
k
0
1 v
+
9
3
lM 2 k
1
edoi d.P
v
5
+
e 074
3
2 N
P P
N P
N
v
5
+ E
0
7
4
v
5
+ k
0
1
D
.E
L P
N IK M IK
9
3
lM 1
2 k
1
N
P N
P
e 074
v
+
k
0
1 v
5
+ v
5
+ 3
1
DEL. R.I
D
.E
L k
1
9
3
lM
2 N
P
edoi d.P
e 074
E 074
v
5
+
3 P
N
k
0
1
4 k
1
DEL. R.I
4
1
1
5
6
1 v
2
1
+
7
1 v
+
4
2
5
2 k
1
N
P P
N P
N
S
R
P
E
IC
O
V F
P
7
2
8
1 P
N IK M IK
v
+ k
1
L
A
T
X N
P N
P
0
6
9
R
P
A k
1
9
F 1
P
7
2 N
P
k
1
0
2 P
N
In this project we use slow speed dc motor. This dc motor is attach with the
gear inside to reduce the speed of the vehicle. For controlling the direction
of the motor we use H bridge circuit. With the help of H bridge it is possible
to the right junction then motor moves to one direction. Because due to
positive on base NPN is on and due to negative on base PNP is on. If left
side NPN is on and right side PNP is on then motor moves to the one
direction. If the voltage is reverse on the base point then motor’s moves to
left NPN and right PNP is on and motor moves to the reverse direction.
Now when we attach the H bridge to the logical output of the micro-
the base of the H bridge circuit. Pin no 22 and 23 is connected to the both
PIN NO 14
100k
0
1
k
PIN NO 15 28 27
2
PIN NO 16 3 26
25
PIN NO 17 4 22
100k 470 OHM
APR 9600 220K
PIN NO 24 5 L.E.D
19
4.7MFD
PIN NO 25 6 17
7
18
33K 9
21
100K 10 +V
100K 20 0.1Mfd
0.1mfd 4.7K
14
12 13 26 15 0.1mfd MIKE
4.7K
D
F
M
2
470 OHM 1K
In this project we attach a voice processor with the metro circuit. This voice
track switch. For recording the sound first of all we press the record switch
and then press track switch. After beep sound we record the message in the
track. All the track points are connected with the microcontroller circuit. As
Digital voice recording chips with different features and coding technology
for speech compression and processing are available on the market from a
micro law ( specified by Bell telephone) and vector sum excited linear
prediction.. On the other hand APR 9600 single chip voice recorder and
playback device from Aplus integrated circuits makes use of a proprietary
natural form. The APR 9600 is a good stand lone voice recorder or playback
can record and play multiple message at random or in sequential mode. The
user can select sample rates with consequent quality and recording time
management are some of the features of the APR 9600. Complete chip
control blocks. Voice signal from the microphone is fed into the chip
Out ( pin 21 ) to Ana_in ( pin 20) via an external Dc blocking capacitor C1.
playback, the ground return of this bias network can be connected to the
normally open side of the record switch. Both Mic.in and Mic.Ref ( pins
Recording signal from the external source can also be fed directly into the
chip using Ana-In ( pin 20), but the connection between ana_in ( pin 20) and
selected. Then the signal is processed into the memory array through a
combination of the sample and hold circuits and analogue read/write circuit.
The incoming voice signals are sampled and the instantaneous voltage
samples are stored in the non-volatic flash memory cells in the 8 bit binary
encoded format. During playback, the stored signals are retrived from the
SP+ and SP- ( pins 14 and 15 respectively) is at about 12mw power into 16
ohm impedence. The output from pin 14 ( sp+) is further amplified by the
low power amplifier using LM386 ( IC2) as shown in the figure. The
provides sampling clock to the APR 9600. the frequency od the oscillator
and sampling rate depend on the value of resistor R12 connected across the
Higher sampling rates improve the voice bandwidth requirement and thus
reduce the duration lower sampling rates use fewer memory cells and
sets the AGC attack time. ( the attack time is defined as the delay present
message modes.
1. Random access mode with 2, 4,8 message within the total recording
time.
2. Tape mode with two option: auto rewind and normal operation.
The modes are defined by pins 24, 25 and 9 as shown as table _1 and cannot
in the device status through beeps superimposed on the device output: for
example, the start of recording is indicated by a beep, so the person can now
start speaking into the microphone. This feature is enabled by making pin
11 high
LCD detail:
LCD DETAIL .
Frequently, an 8051 program must interact with the outside world using input and output
devices that communicate directly with a human being. One of the most common devices
attached to an 8051 is an LCD display. Some of the most common LCDs connected to
the 8051 are 16x2 and 20x2 displays. This means 16 characters per line by 2 lines and 20
characters per line by 2 lines, respectively.
Fortunately, a very popular standard exists which allows us to communicate with the vast
majority of LCDs regardless of their manufacturer. The standard is referred to as
HD44780U, which refers to the controller chip which receives data from an external
source (in this case, the 8051) and communicates directly with the LCD.
44780 BACKGROUND
to
As you can see, we've established a 1-to-1 relation between a pin on the 8051 and a line
on the 44780 LCD. Thus as we write our assembly program to access the LCD, we are
going to equate constants to the 8051 ports so that we can refer to the lines by their 44780
name as opposed to P0.1, P0.2, etc. Let's go ahead and write our initial equates:
As we mentioned above, the EN line is used to tell the LCD that you are ready for it to
execute an instruction that you've prepared on the data bus and on the other control lines.
Note that the EN line must be raised/lowered before/after each instruction sent to the
LCD regardless of whether that Thus, before we interact in any way with the LCD we
will always bring the EN line high with the following instruction:
SETB EN
And once we've finished setting up our instruction with the other control lines and data
bus lines, we'll always bring this line back low:
CLR EN
Programming Tip: The LCD interprets and executes our command at the instant
the EN line is brought low. If you never bring EN low, your instruction will never
be executed. Additionally, when you bring EN low and the LCD executes your
instruction, it requires a certain amount of time to execute the command. The time
it requires to execute an instruction depends on the instruction and the speed of
the crystal which is attached to the 44780's oscillator input.
use this code every time we send an instruction to the LCD, it is useful to make it a
subroutine. Let's write the code:
WAIT_LCD:
SETB EN ;Start LCD command
CLR RS ;It's a command
SETB RW ;It's a read command
MOV DATA,#0FFh ;Set all pins to FF initially
MOV A,DATA ;Read the return value
JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy
CLR EN ;Finish the command
CLR RW ;Turn off RW for future commands
RET
Thus, our standard practice will be to send an instruction to the LCD and then call our
WAIT_LCD routine to wait until the instruction is completely executed by the LCD.
This will assure that our program gives the LCD the time it needs to execute instructions
and also makes our program compatible with any LCD, regardless of how fast or slow it
is.
Programming Tip: The above routine does the job of waiting for the LCD, but
were it to be used in a real application a very definite improvement would need to
be made: as written, if the LCD never becomes "not busy" the program will
effectively "hang," waiting for DB7 to go low. If this never happens, the program
will freeze. Of course, this should never happen and won't happen when the
hardware is working properly. But in a real application it would be wise to put
some kind of time limit on the delay--for example, a maximum of 256 attempts to
wait for the busy signal to go low. This would guarantee that even if the LCD
hardware fails, the program would not lock up.
send this 38h command to the LCD we must execute the following 8051 instructions:
SETB EN
CLR RS
MOV DATA,#38h
CLR EN
LCALL WAIT_LCD
Programming Tip: The LCD command 38h is really the sum of a number of
option bits. The instruction itself is the instruction 20h ("Function set"). However,
to this we add the values 10h to indicate an 8-bit data bus plus 08h to indicate that
the display is a two-line display.
We've now sent the first byte of the initialization sequence. The second byte of the
initialization sequence is the instruction 0Eh. Thus we must repeat the initialization code
from above, but now with the instruction. Thus the next code segment is:
SETB EN
CLR RS
MOV DATA,#0Eh
CLR EN
LCALL WAIT_LCD
Programming Tip: The command 0Eh is really the instruction 08h plus 04h to
turn the LCD on. To that an additional 02h is added in order to turn the cursor on.
The last byte we need to send is used to configure additional operational parameters of
the LCD. We must send the value 06h.
SETB EN
CLR RS
MOV DATA,#06h
CLR EN
LCALL WAIT_LCD
Programming Tip: The command 06h is really the instruction 04h plus 02h to
configure the LCD such that every time we send it a character, the cursor position
automatically moves to the right.
So, in all, our initialization code is as follows:
INIT_LCD:
SETB EN
CLR RS
MOV DATA,#38h
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATA,#0Eh
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATA,#06h
CLR EN
LCALL WAIT_LCD
RET
Having executed this code the LCD will be fully initialized and ready for us to send
display data to it.
When the LCD is first initialized, the screen should automatically be cleared by the
44780 controller.
CLEAR_LCD:
SETB EN
CLR RS
MOV DATA,#01h
CLR EN
LCALL WAIT_LCD
RET
How that we've written a "Clear Screen" routine, we may clear the LCD at any time by
simply executing an LCALL CLEAR_LCD.
Programming Tip: Executing the "Clear Screen" instruction on the LCD also
positions the cursor in the upper left-hand corner as we would expect.
WRITING TEXT TO THE LCD
we'll almost certainly want to do over and over--so let's make it a subroutine.
WRITE_TEXT:
SETB EN
SETB RS
MOV DATA,A
CLR EN
LCALL WAIT_LCD
RET
The WRITE_TEXT routine that we just wrote will send the character in the accumulator
to the LCD which will, in turn, display it. Thus to display text on the LCD all we need to
do is load the accumulator with the byte to display and make a call to this routine. Pretty
easy, huh?
Now that we have all the component subroutines written, writing the classic "Hello
World" program--which displays the text "Hello World" on the LCD is a relatively trivial
matter. Consider:
LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT
The above "Hello World" program should, when executed, initialize the LCD, clear the
LCD screen, and display "Hello World" in the upper left-hand corner of the display.
CURSOR POSITIONING
The
Thus, the first character #2 on the first line) is address 01h, etc. This continues until we
reach
SETB EN
CLR RS
MOV DATA,#0C4h
CLR EN
LCALL WAIT_LCD
The above code will position the cursor on line 2, character 10. To display "Hello" in the
upper left-hand corner with the word "World" on the second line at character position 10
just requires us to insert the above code into our existing "Hello World" program. This
results in the following:
LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
SETB EN
CLR RS
MOV DATA,#0C4h
CLR EN
LCALL WAIT_LCD
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT
1. Vss GROUND
6 E ENABLE
7 DB0
8 DB1
9. DB2
10. DB3
11. DB4
12. DB5
13. DB6
14. DB7
2. RETURN HOME
Look around. Notice the smart “intelligent” systems? Be it the T.V, washing
machines, video games, telephones, automobiles, aero planes, power
systems, or any application having a LED or a LCD as a user interface, the
control is likely to be in the hands of a micro controller!
Measure and control, that’s where the micro controller is at its best.
Micro controllers are here to stay. Going by the current trend, it is obvious
that micro controllers will be playing bigger and bigger roles in the different
activities of our lives.
These embedded chips are very small, but are designed to replace
components much bigger and bulky In size. They process information very
intelligently and efficiently. They sense the environment around them. The
signals they gather are tuned into digital data that streams through tributaries
of circuit lines at the speed of light. Inside the microprocessor collates and
calculators. The software has middling intelligence. Then in a split second,
the processed streams are shoved out.
In addition to the various features like the ALU, PC, SP and registers found
on a microprocessor, the micro controller also incorporates features like the
ROM, RAM, Ports, timers, clock circuits, counters, reset functions etc.
write and calculations on data, the micro controller, in addition to the above
The 8051 developed and launched in the early 80`s, is one of the most
popular micro controller in use today. It has a reasonably large amount of
built in ROM and RAM. In addition it has the ability to access external
memory.
The generic term `8x51` is used to define the device. The value of x defining
the kind of ROM, i.e. x=0, indicates none, x=3, indicates mask ROM, x=7,
indicates EPROM and x=9 indicates EEPROM or Flash.
A note on ROM
The early 8051, namely the 8031 was designed without any ROM. This
device could run only with external memory connected to it. Subsequent
developments lead to the development of the PROM or the programmable
ROM. This type had the disadvantage of being highly unreliable.
The next in line, was the EPROM or Erasable Programmable ROM. These
devices used ultraviolet light erasable memory cells. Thus a program could
be loaded, tested and erased using ultra violet rays. A new program could
then be loaded again.
• INTEL These are the first to manufacture microcontrollers. These are not
as sophisticated other microcontrollers but still the easiest one to learn.
Intel 8051
Intel 8051 is CISC architecture which is easy to program in assembly language and also
has a good support for High level languages.
The 8051 microcontroller is in the field for more than 20 years. There are lots of books
and study materials are readily available for 8051.
Derivatives
The best thing done by Intel is to give the designs of the 8051 microcontroller to
everyone. So it is not the fact that Intel is the only manufacture for the 8051 there more
than 20 manufactures, with each of minimum 20 models. Literally there are hundreds of
models of 8051 microcontroller available in market to choose. Some of the major
manufactures of 8051 are
Atmel
Philips
Philips
The Philips‘s 8051 derivatives has more number of features than in any
microcontroller. The costs of the Philips microcontrollers are higher than the Atmel’s
which makes us to choose Atmel more often than Philips
Dallas
Dallas has made many revolutions in the semiconductor market. Dallas’s 8051
derivative is the fastest one in the market. It works 3 times as fast as a 8051 can process.
But we are unable to get more in India.
Atmel
These people were the one to master the flash devices. They are the cheapest
microcontroller available in the market. Atmel’s even introduced a 20pin variant of 8051
named 2051. The Atmel’s 8051 derivatives can be got in India less than 70 rupees. There
are lots of cheap programmers available in India for Atmel. So it is always good for
students to stick with 8051 when you learn a new microcontroller.
Architecture
Architecture is must to learn because before learning new machine it is necessary to learn
the capabilities of the machine. This is some thing like before learning about the car you
cannot become a good driver. The architecture of the 8051 is given below.
The 8051 doesn’t have any special feature than other microcontroller. The only feature is
that it is easy to learn. Architecture makes us to know about the hardware features of the
microcontroller. The features of the 8051 are
The 8051 has a 8-Bit CPU that means it is able to process 8 bit of data at a time. 8051 has
235 instructions. Some of the important registers and their functions are
When the switch is closed or ‘switched on’ the bulb glows. When the switch
is open or ‘switched off’ the bulb goes off
If you are instructed to put the switch on and off every 30 seconds, how
would you do it? Obviously you would keep looking at your watch and
every time the second hand crosses 30 seconds you would keep turning the
switch on and off.
Imagine if you had to do this action consistently for a full day. Do you think
you would be able to do it? Now if you had to do this for a month, a year??
The next step would be, then to make it automatic. This is where we use the
Microcontroller.
But if the action has to take place every 30 seconds, how will the
microcontroller keep track of time?
Execution time
Set p1.0
This instructs the microcontroller to put a value of ‘one’ in bit zero of port
one.
Don’t worry about what bit zero and port one means. We shall learn it in
more detail as we proceed.
There are a set of well defined instructions, which are used while
communicating with the microcontroller. Each of these instructions requires
a standard number of cycles to execute. The cycle could be one or more in
number.
10,000,000/12=833333.33333 cycles.
833333.33333 cycles.
Therefore for one cycle, what would be the time? Try it out.
The instruction clr p1.0 would use one cycle to execute. Similarly, the
Getting back to our bulb example, all we would need to do is to instruct the
seconds, like counting from zero upwards, then switch on the bulb, carry out
Just put the whole thing in a loop, and you have a never ending on-off
sequence.
Let us now have a look at the features of the 8051 core, keeping the above
example as a reference,
Most of the transactions within the microcontroller are carried out through
the ‘A’ register, also known as the Accumulator. In addition all arithmetic
functions are carried out generally in the ‘A’ register. There is another
register known as the ‘B’ register, which is used exclusively for
multiplication and division.
Thus an 8-bit notation would indicate that the maximum value that can be
input into these registers is ‘11111111’. Puzzled?
The value is not decimal 111, 11,111! It represents a binary number, having
an equivalent value of ‘FF’ in Hexadecimal and a value of 255 in decimal.
We shall read in more detail on the different numbering systems namely the
Binary and Hexadecimal system in our next module.
2. 4K on-chip ROM
Once you have written out the instructions for the microcontroller, where do
you put these instructions?
Obviously you would like these instructions to be safe, and not get deleted
or changed during execution. Hence you would load it into the ‘ROM’
The size of the program you write is bound to vary depending on the
application, and the number of lines. The 8051 microcontroller gives you
space to load up to 4K of program size into the internal ROM.
4K, that’s all? Well just wait. You would be surprised at the amount of stuff
you can load in this 4K of space.
This is the space provided for executing the program in terms of moving
data, storing data etc.
4. 32 I/O lines. (Four- 8 bit ports, labeled P0, P1, P2, P3)
In our bulb example, we used the notation p1.0. This means bit zero of port
one. One bit controls one bulb.
Thus port one would have 8 bits. There are a total of four ports named p0,
p1, p2, p3, giving a total of 32 lines. These lines can be used both as input or
output.
These timers can also be used as counters, so that they can count the number
of events, and on reaching the required count, can cause a branch in the main
program.
7. 5- interrupt sources with two priority levels (Two external and three
internal)
During the discussion on the timers, we had indicated that the timers can
trigger a branch in the main program. However, what would we do in case
we would like the microcontroller to take the branch, and then return back to
the main program, without having to constantly check whether the required
time / count has been reached?
This is where the interrupts come into play. These can be set to either the
timers, or to some external events. Whenever the background program has
reached the required criteria in terms of time or count or an external event,
the branch is taken, and on completion of the branch, the control returns to
the main program.
This represents the oscillator circuits within the microcontroller. Thus the
hardware is reduced to just simply connecting an external crystal, to achieve
the required pulsing rate.
5. PORT0 Port 0 occupies a total of 8 pins. Pin no 32 to pin no 39. It can be used
for input or output. We connect all the pins of the port 0 with the pullup
resistor (10 k ohm) externally. This is due to fact that port 0 is an open drain
mode. It is just like a open collector transistor.
PORT 3. Port3 occupies a totoal 8 pins from pin no 10 to pin no 17. It can
be used as input or output. Port 3 does not require any pull up resistor. The
same as port 1 and port2. Port 3 is configured as an output port on reset. Port
3 has the additional function of providing some important signals such as
interrupts. Port 3 also use for serial communication.
ALE ALE is an output pin and is active high. When connecting an 8031 to external
memory, port 0 provides both address and data. In other words, the 8031 multiplexes
address and data through port 0 to save pins. The ALE pin is used for demultiplexing the
address and data by connecting to the ic 74ls373 chip.
PSEN. PSEN stands for program store eneable. In an 8031 based system in which an
external rom holds the program code, this pin is connected to the OE pin of the rom.
EA. EA. In 89c51 8751 or any other family member of the ateml 89c51 series all come
with on-chip rom to store programs, in such cases the EA pin is connected to the Vcc.
For family member 8031 and 8032 is which there is no on chip rom, code is stored in
external memory and this is fetched by 8031. In that case EA pin must be connected to
GND pin to indicate that the code is stored externally.
SPECIAL FUNCTION REGISTER ( SFR) ADDRESSES.
B B REGISTER 0F0H
P0 PORT0 80H
P1 PORT1 90H
P2 PORT2 0A0H
P3 PORT3 0B0H
MOV INSTRUCTIONS
MOV instruction simply copy the data from one location to another location
MOV D,S
ADD INSTRUCTIONS.
ADD instructions adds the source byte to the accumulator ( A) and place the result in the
Accumulator.
MOV A, #25H
ACALL,TARGET ADDRESS
By this instructions we call subroutines with a target address within 2k bytes from the
current program counter.
ACALL is a limit for the 2 k byte program counter, but for upto 64k byte we use
LCALL instructions.. Note that LCALL is a 3 byte instructions.
ACALL is a two byte instructions.
AJMP stand for absolute jump. It transfers program execution to the target address
unconditionally. The target address for this instruction must be
withib 2 k byte of program memory.
LJMP is also for absoltute jump. It tranfer program execution to the target addres
unconditionally. This is a 3 byte instructions LJMP jump to any
address within 64 k byte location.
INSTRUCTIONS RELATED TO THE CARRY
JC TARGET
JNC TARGET
JUMP TO TARGET IF A = 0
JNZ TARGET
RL A
BY this instructions we rotate the bits of A left. The bits rotated out of A are
rotated back into A at the opposite end
RR A
RRC A
This is same as RR A but difference is that the bit rotated out of register first
enter in to carry and then enter into MSB
RLC A
Same as above but but shift the data from MSB to carry and carry to LSB
RET
RET1
PUSH.
This copies the indicated byte onto the stack and increments SP by . This
instructions supports only direct addressing mode.
POP.
This copies the byte pointed to be SP to the location whose direct address is
indicated, and decrements SP by 1. Notice that this instructions supports
only direct addressing mode.
DPTR INSTRUCTIONS.
This instructions load the 16 bit dptr register with a 16 bit immediate value
MOV C A,@A+DPTR
This instructions moves a byte of data located in program ROM into register
A. This allows us to put strings of data, such as look up table elements.
MOVC A,@A+PC
This instructions moves a byte of data located in the program area to A. the
address of the desired byte of data is formed by adding the program counter
INC BYTE
DEC BYTE
DEC A
DEC Rn
DEC DIRECT
ARITHMATIC INSTRUCTIONS.
This performs a logical AND on the operands, bit by bit, storing the result in
the destination. Notice that both the source and destination values are byte –
size only
`
DIV AB
GATE: Gating control when set. Timer/counter is enabled only while the INTX
pin is high and the TRx control pin is set. When cleared, the timer is enabled whenever
the TRx control bit is set
C/T : Timer or counter selected cleared for timer operation ( input from internal
system clock)
M1 Mode bit 1
M0 Mode bit 0
0 0 0 13 BIT TIMER/MODE
If the SMOD IS = 1
CRYSTAL FREQUENCY
TH1 = 256--------------------------------------
192 X BAUD RATE
There are two ways to increase the baud rate of data transfer in the 8051
PCON register is an 8 bit register . Of the 8 bits, some are unused, and some are used for
the power control capability of the 8051. the bit which is used for the serial
communication is D7, the SMOD bit. When the 8051 is powered up, D7 ( SMOD BIT)
OF PCON register is zero. We can set it to high by software and thereby double the
baud rate
-3 FD 9600 19200
-6 FA 4800 9600
-12 F4 2400 4800
-24 E8 1200 2400
If the bit is 0, the corresponding interrupt has a lower priority and if the bit is 1 the
corresponding interrupt has a higher priority
SCON
SM2 : SCON.5
TB8 : SCON.3 The 9th bit that will be transmitted in modes 2 and 3, Set/cleared
By software
RB8 : SCON.2 In modes 2 &3, is the 9th data bit that was received. In mode 1,
If SM2 = 0, RB8 is the stop bit that was received. In mode 0
RB8 is not used
T1 : SCON.1 Transmit interrupt flag. Set by hardware at the end of the 8th bit
Time in mode 0, or at the beginning of the stop bit in the other
Modes. Must be cleared by software
R1 SCON.0 Receive interrupt flag. Set by hardware at the end of the 8th bit
Time in mode 0, or halfway through the stop bit time in the other
Modes. Must be cleared by the software.
TCON TIMER COUNTER CONTROL REGISTER
TF1 TCON.7 Timer 1 overflow flag. Set by hardware when the Timer/Counter 1
Overflows. Cleared by hardware as processor
TR1 TCON.6 Timer 1 run control bit. Set/cleared by software to turn Timer
Counter 1 On/off
TF0 TCON.5 Timer 0 overflow flag. Set by hardware when the timer/counter 0
Overflows. Cleared by hardware as processor
TR0 TCON.4 Timer 0 run control bit. Set/cleared by software to turn timer
Counter 0 on/off.
MUL AB Multiply A and B Result: A <- low byte, B <- high byte. 1 4
Data Transfer
MOVC A,@A+DPTR Move code byte relative to DPTR to ACC (16 bit address).
1 2
MOVC A,@A+PC Move code byte relative to PC to ACC (16 bit address).1 2
Program Branching
Mnemonic Description Size Cycles
CJNE A,#data,rel Compare immediate byte to ACC and jump if not equal.3 2
CJNE Rn,#data,rel Compare immediate byte to register and jump if not equal.32
CJNE @Ri,#data,rel Compare immediate byte to indirect and jump if not equal.32
Other Instructions
NOP No operation. 1 1
LCD_DATA equ P0
input equ P1
bit P2.2
org 0000h
ljmp main
main:
mov p0,#0ffh
mov p1,#0ffh
mov p2,#0ffh
mov p3,#0ffh
clr lcd_rs
clr lcd_rw
clr lcd_en
lcall INIT_LCD
lcall CLR_LCD
mov dptr,#MSG1U
lcall LINE_1
mov dptr,#MSG1L
lcall LINE_2
KEYLOOP:
jb start_key,KEYLOOP
lcall DELAY1
nxt0:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt0
lcall DELAY1
cjne a,#0fch,nxt0
lcall DELAY1
mov dptr,#MSG2U
lcall LINE_1
mov dptr,#MSG2L
lcall LINE_2
lcall DELAY41
nxt1:
mov a,input
cjne a,#0fch,nxt1
lcall DELAY1
cjne a,#0fch,nxt1
lcall DELAY1
mov dptr,#MSG3U
lcall LINE_1
mov dptr,#MSG3L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG1U
lcall LINE_1
mov dptr,#MSG1L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
clr ccw
mov dptr,#MSG4U
lcall LINE_1
mov dptr,#MSG4L
lcall LINE_2
lcall DELAY41
nxt2:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt2
lcall DELAY1
cjne a,#0fch,nxt2
lcall DELAY1
setb ccw
mov dptr,#MSG5U
lcall LINE_1
mov dptr,#MSG5L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG1U
lcall LINE_1
mov dptr,#MSG1L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
clr ccw
mov dptr,#MSG6U
lcall LINE_1
mov dptr,#MSG6L
lcall LINE_2
lcall DELAY41
nxt3:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt3
lcall DELAY1
cjne a,#0fch,nxt3
lcall DELAY1
setb ccw
mov dptr,#MSG7U
lcall LINE_1
mov dptr,#MSG7L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG1U
lcall LINE_1
mov dptr,#MSG1L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
clr ccw
mov dptr,#MSG8U
lcall LINE_1
mov dptr,#MSG8L
lcall LINE_2
lcall DELAY41
nxt4:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt4
lcall DELAY1
cjne a,#0fch,nxt4
lcall DELAY1
setb ccw
mov dptr,#MSG9U
lcall LINE_1
mov dptr,#MSG9L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG10U
lcall LINE_1
mov dptr,#MSG10L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
clr ccw
lcall DELAY41
nxt5:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt5
lcall DELAY1
cjne a,#0fch,nxt5
lcall DELAY1
mov dptr,#MSG1U
lcall LINE_1
mov dptr,#MSG1L
lcall LINE_2
setb ccw
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG8U
lcall LINE_1
mov dptr,#MSG8L
lcall LINE_2
clr acw
lcall DELAY41
lcall DELAY41
nxt6:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt6
lcall DELAY1
cjne a,#0fch,nxt6
lcall DELAY1
setb acw
mov dptr,#MSG9U
lcall LINE_1
mov dptr,#MSG9L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG1U
lcall LINE_1
mov dptr,#MSG1L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
clr acw
mov dptr,#MSG6U
lcall LINE_1
mov dptr,#MSG6L
lcall LINE_2
lcall DELAY41
nxt7:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt7
lcall DELAY1
cjne a,#0fch,nxt7
lcall DELAY1
setb acw
mov dptr,#MSG7U
lcall LINE_1
mov dptr,#MSG7L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG1U
lcall LINE_1
mov dptr,#MSG1L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG4U
lcall LINE_1
mov dptr,#MSG4L
lcall LINE_2
lcall DELAY41
nxt8:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt8
lcall DELAY1
cjne a,#0fch,nxt8
lcall DELAY1
mov dptr,#MSG5U
lcall LINE_1
mov dptr,#MSG5L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG1U
lcall LINE_1
mov dptr,#MSG1L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
clr acw
mov dptr,#MSG2U
lcall LINE_1
mov dptr,#MSG2L
lcall LINE_2
lcall DELAY41
nxt9:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt9
lcall DELAY1
cjne a,#0fch,nxt9
lcall DELAY1
setb acw
mov dptr,#MSG3U
lcall LINE_1
mov dptr,#MSG3L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG10U
lcall LINE_1
mov dptr,#MSG10L
lcall LINE_2
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
lcall DELAY41
mov dptr,#MSG1U
lcall LINE_1
mov dptr,#MSG1L
lcall LINE_2
lcall DELAY41
nxt10:
mov a,input
orl a,#0fch
cjne a,#0fch,nxt10
lcall DELAY1
cjne a,#0fch,nxt10
lcall DELAY1
setb acw
ljmp KEYLOOP
LINE_1:
mov LCD_DATA,#080h
lcall COMMAND_BYTE
lcall DELAY1
lcall WRITE_MSG
ret
LINE_2:
mov LCD_DATA,#0c0h
lcall COMMAND_BYTE
lcall DELAY1
lcall WRITE_MSG
ret
INIT_LCD:
mov LCD_DATA,#038h
lcall COMMAND_BYTE
lcall DELAY1
mov LCD_DATA,#038h
lcall COMMAND_BYTE
lcall DELAY1
mov LCD_DATA,#038h
lcall COMMAND_BYTE
lcall DELAY1
mov LCD_DATA,#038h
lcall COMMAND_BYTE
lcall DELAY1
mov LCD_DATA,#008h
lcall COMMAND_BYTE
lcall DELAY1
mov LCD_DATA,#00ch
lcall COMMAND_BYTE
lcall DELAY1
mov LCD_DATA,#006h
lcall COMMAND_BYTE
lcall DELAY1
ret
CLR_LCD:
mov LCD_DATA,#001h
lcall COMMAND_BYTE
lcall DELAY1
ret
WRITE_MSG:
mov a,#00h
movc a,a+dptr
cjne a,#',WRITE_CONT
ret
WRITE_CONT:
mov LCD_DATA,a
lcall DATA_BYTE
ljmp WRITE_MSG
COMMAND_BYTE:
clr lcd_rs
lcall DELAY
ljmp CMD10
DATA_BYTE:
setb lcd_rs
lcall DELAY
CMD10:
clr lcd_rw
lcall DELAY
setb lcd_en
lcall DELAY
clr lcd_en
lcall DELAY
ret
R_COMMAND_BYTE:
clr lcd_rs
lcall DELAY
ljmp R_CMD10
R_DATA_BYTE:
setb lcd_rs
lcall DELAY
R_CMD10:
setb lcd_rw
lcall DELAY
setb lcd_en
lcall DELAY
lcall DELAY
ret
DELAY:
mov r0,#10d
DEL:
djnz r0,DEL
ret
DELAY1:
mov r0,#0d
mov r1,#20d
DELAY10:
djnz r0,DELAY10
djnz r1,DELAY10
ret
DELAY41:
mov r0,#0d
mov r1,#0d
mov r2,#10d
DLP410:
djnz r0,DLP410
djnz r1,DLP410
djnz r2,DLP410
ret
end