8051 Micro Controller Project Report
8051 Micro Controller Project Report
Session 2009-2010
Reported
We are living in the Embedded World. You are surrounded with many
embedded products and your daily life largely depends on the proper
functioning of these gadgets. Television, Radio, CD player of your living
room, Washing Machine or Microwave Oven in your kitchen, Card
readers, Access Controllers, Palm devices of your work space enable
you to do many of your tasks very effectively. Apart from all these,
many controllers embedded in your car take care of car operations
between the bumpers and most of the times you tend to ignore all
these controllers.
In the 8 bit segment, the most popular and used architecture is Intel's
8031. Market acceptance of this particular family has driven many
semiconductor manufacturers to develop something new based on this
particular architecture. Even after 25 years of existence, semiconductor
manufacturers still come out with some kind of device using this 8031 core.
8051 Microcontrollers:-
4K byte of ROM.
ALE/PROG: Address Latch Enable output pulse for latching the low byte
of the address during accesses to external memory. ALE is emitted at a
constant rate of 1/6 of the oscillator frequency, for external timing or
clocking purposes, even when there are no accesses to external
memory. (However, one ALE pulse is skipped during each access to
external Data Memory.) This pin is also the program pulse input (PROG)
during EPROM programming.
PSEN: Program Store Enable is the read strobe to external Program
Memory. When the device is executing out of external Program
Memory, PSEN is activated twice each machine cycle (except that two
PSEN activations are skipped during accesses to external Data
Memory). PSEN is not activated when the device is executing out of
internal Program Memory.
All four ports in the 80C51 are bidirectional. Each consists of a latch
(Special Function Registers P0 through P3), an output driver, and an
input buffer. The output drivers of Ports 0 and 2, and the input buffers
of Port 0, are used in accesses to external memory. In this application,
Port 0 outputs the low byte of the external memory address, time-
multiplexed with the byte being written or read. Port 2 outputs the high
byte of the external memory address when the address is 16 bits wide.
Otherwise, the Port 2 pins continue to emit the P2 SFR content.
All the Port 3 pins are multifunctional. They are not only port pins, but
also serve the functions of various special features as listed below:
Accumulator:
ACC is the Accumulator register. The mnemonics for Accumulator-
Specific instructions, however, refer to the Accumulator simply as A.
B Register:
The B register is used during multiply and divide operations. For other
instructions it can be treated as another scratch pad register.
Program Status Word:
The PSW register contains program status information as detailed in
Figure.
BIT SYMBOL FUNCTION:-
NOTE: The contents of (RS1, RS0) enable the working register banks as
follows:
(0, 0)— Bank 0 (00H–07H)
(0, 1)— Bank 1 (08H–0fH)
(1, 0)— Bank 2 (10H–17H)
(1, 1)— Bank 3 (18H–17H)
Stack Pointer:-
The Stack Pointer register is 8 bits wide. It is incremented before data is
stored during PUSH and CALL executions. While the stack may reside
anywhere in on-chip RAM, the Stack Pointer is initialized to 07H after a
reset. This causes the stack to begin at locations 08H.
Data Pointer:-
The Data Pointer (DPTR) consists of a high byte (DPH) and a low byte
(DPL). Its intended function is to hold a 16-bit address. It may be
manipulated as a 16-bit register or as two independent 8-bit registers.
Serial Data Buffer:-
The Serial Buffer is actually two separate registers, a transmit buffer
and a receive buffer. When data is moved to SBUF, it goes to the
transmit buffer and is held for serial transmission. (Moving a byte to
SBUF is what initiates the transmission.) When data is moved from
SBUF, it comes from the receive buffer.
Timer Registers Basic to 80C51:-
Register pairs (TH0, TL0), and (TH1, TL1) are the 16-bit Counting
registers for Timer/Counters 0 and 1, respectively.
Control Register for the 80C51:-
Special Function Registers IP, IE, TMOD, TCON, SCON, and PCON
contain control and status bits for the interrupt system, the
Timer/Counters, and the serial port. They are described in later
sections.
Basic Registers:-
A number of 8052 registers can be considered "basic." Very little can be
done without them and a detailed explanation of each one is warranted
to make sure the reader understands these registers before getting into
more complicated areas of development.
The Accumulator:-
If you've worked with any other assembly language you will be familiar
with the concept of an accumulator register.
The Accumulator, as its name suggests, is used as a general register to
accumulate the results of a large number of instructions. It can hold an
8-bit (1-byte) value and is the most versatile register the 8052 has due
to the sheer number of instructions that make use of the accumulator.
More than half of the 8052's 255 instructions manipulate or use the
Accumulator in some way.
For example, if you want to add the number 10 and 20, the resulting 30
will be stored in the Accumulator. Once you have a value in the
Accumulator you may continue processing the value or you may store it
in another register or in memory.
The "R" Registers:-
The "R" registers are sets of eight registers that are named R0, R1,
through R7. These registers are used as auxiliary registers in many
operations. To continue with the above example, perhaps you are
adding 10 and 20. The original number 10 may be stored in the
Accumulator whereas the value 20 may be stored in, say, register R4.
To process the addition you would execute the command:
ADD A, R4
After executing this instruction the Accumulator will contain the value
30. You may think of the "R" registers as very important auxiliary, or
"helper", registers. The Accumulator alone would not be very useful if it
were not for these "R" registers.
The "R" registers are also used to store values temporarily. For
example, let’s say you want to add the values in R1 and R2 together and
then subtract the values of R3 and R4. One way to do this would be:
MOV A, R3 ; Move the value of R3 to accumulator
ADD A, R4 ; add the value of R4
MOV R5, A ; Store the result in R5
MOV A, R1 ; Move the value of R1 to Acc
ADD A, R2 ; add the value of R2 with A
SUBB A, R5 ; Subtract the R5 (which has R3+R4)
As you can see, we used R5 to temporarily hold the sum of R3 and R4.
Of course, this isn't the most efficient way to calculate (R1+R2) - (R3
+R4) but it does illustrate the use of the "R" registers as a way to store
values temporarily.
As mentioned earlier, there are four sets of "R" registers-register bank
0, 1, 2, and 3. When the 8052 is first powered up, register bank 0
(addresses 00h through 07h) is used by default. In this case, for
example, R4 is the same as Internal RAM address 04h. However, your
program may instruct the 8052 to use one of the alternate register
banks; i.e., register banks 1, 2, or 3. In this case, R4 will no longer be the
same as Internal RAM address 04h. For example, if your program
instructs the 8052 to use register bank 1, register R4 will now be
synonymous with Internal RAM address 0Ch. If you select register bank
2, R4 is synonymous with 14h, and if you select register bank 3 it is
synonymous with address 1Ch.
The concept of register banks adds a great level of flexibility to the
8052, especially when dealing with interrupts (we'll talk about
interrupts later). However, always remember that the register banks
really reside in the first 32 bytes of Internal RAM.
The B Register:-
The "B" register is very similar to the Accumulator in the sense that it
may hold an 8-bit (1-byte) value. The "B" register is only used implicitly
by two 8052 instructions: MUL AB and DIV AB. Thus, if you want to
quickly and easily multiply or divide A by another number, you may
store the other number in "B" and make use of these two instructions.
Aside from the MUL and DIV instructions, the "B" register are
often used as yet another temporary storage register much like a ninth
"R" register.
The Program Counter:-
The Program Counter (PC) is a 2-byte address that tells the 8052 where
the next instruction to execute is found in memory. When the 8052 is
initialized PC always starts at 0000h and is incremented each time an
instruction is executed. It is important to note that PC isn't always
incremented by one. Since some instructions are 2 or 3 bytes in length
the PC will be incremented by 2 or 3 in these cases.
The Program Counter is special in that there is no way to directly
modify its value. That is to say, you can't do something like PC=2430h.
On the other hand, if you execute LJMP 2430h you've effectively
accomplished the same thing.
It is also interesting to note that while you may change the value of PC
(by executing a jump instruction, etc.) there is no way to read the value
of PC. That is to say, there is no way to ask the 8052 "What address are
you about to execute?" As it turns out, this is not completely true:
There is one trick that may be used to determine the current value of
PC. This trick will be covered in a later chapter.
The Data Pointer:-
The Data Pointer (DPTR) is the 8052ís only user-accessible 16-bit (2-
byte) register. The Accumulator, "R" registers, and "B" register are all 1-
byte values. The PC just described is a 16-bit value but isn't directly
user-accessible as a working register.
DPTR, as the name suggests, is used to point to data. It is used by a
number of commands that allow the 8052 to access external memory.
When the 8052 accesses external memory it accesses the memory at
the address indicated by DPTR.
While DPTR is most often used to point to data in external memory or
code memory, many developers take advantage of the fact that it's the
only true 16-bit register available. It is often used to store 2-byte values
that have nothing to do with memory locations.
The Stack Pointer:-
The Stack Pointer, like all registers except DPTR and PC, may hold an 8-
bit (1-byte) value. The Stack Pointer is used to indicate where the next
value to be removed from the stack should be taken from.
When you push a value onto the stack, the 8052 first increments the
value of SP and then stores the value at the resulting memory location.
When you pop a value off the stack, the 8052 returns the value from
the memory location indicated by SP, and then decrements the value of
SP.This order of operation is important. When the 8052 is initialized SP
will be initialized to 07h. If you immediately push a value onto the
stack, the value will be stored in Internal RAM address 08h. This makes
sense taking into account what was mentioned two paragraphs above:
First the 8051 will increment the value of SP (from 07h to 08h) and then
will store the pushed value at that memory address (08h).
Addressing Modes:-
The addressing modes in the 80C51 instruction set are as follows:
Direct Addressing:-
In direct addressing the operand is specified by an 8-bit address field in
the instruction. Only internal Data RAM and SFRs can be directly
addressed.
Indirect Addressing:-
In indirect addressing the instruction specifies a register which contains
the address of the operand. Both internal and external RAM can be
indirectly addressed. The address register for 8-bit addresses can be R0
or R1 of the selected bank, or the Stack Pointer. The address register
for 16-bit addresses can only be the 16-bit “data pointer” register,
DPTR.
Register Instructions:-
The register banks, containing registers R0 through R7, can be accessed
by certain instructions which carry a 3-bit register specification within
the opcode of the instruction. Instructions that access the registers this
way are code efficient, since this mode eliminates an address byte.
When the instruction is executed, one of the eight registers in the
selected bank is accessed. One of four banks is selected at execution
time by the two bank select bits in the PSW.
Register-Specific Instructions:-
Some instructions are specific to a certain register. For example, some
instructions always operate on the Accumulator, or Data Pointer, etc.,
so no address byte is needed to point to it. The opcode itself does that.
Instructions that refer to the Accumulator as A assemble as
accumulator specific opcodes.
Immediate Constants:-
The value of a constant can follow the opcode in Program Memory.
For example,
MOV A, #100
Loads the Accumulator with the decimal number 100. The same
number could be specified in hex digits as 64H.
Indexed Addressing:-
Only program Memory can be accessed with indexed addressing, and it
can only be read. This addressing mode is intended for reading look-up
tables in Program Memory A 16-bit base register (either DPTR or the
Program Counter) points to the base of the table, and the Accumulator
is set up with the table entry number. The address of the table entry in
Program Memory is formed by adding the Accumulator data to the
base pointer. Another type of indexed addressing is used in the “case
jump” instruction. In this case the destination address of a jump
instruction is computed as the sum of the base pointer and the
Accumulator data.
What is L.C.D.?
It is a liquid crystal display of thin flat panel used for electronically
displaying information such as text, images and moving pictures.
Television.
LCD DISPLAY IMAGE GRAFITTE
PIN DIAGRAM OF L.C.D.
L.C.D.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Vss Vcc Vee RS R/W E DB0 DB1DB2 DB3DB4 DB5 DB6 DB7 LED+ LED-
1 Vss -- GROUNDED
R/W=1,for read
6 E I/O Enable
10K
POT
Circuit Diagram for displaying ’SPICE’
GROUND
Regulator
+5V
12 V
D.C. Voltag e
L.C.D.
Vss Vcc Vee RS R/W E DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 LED+ LED-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
POT 10.0k
33.0p
33.0p
10.0k
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
P1.O P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 R ST P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7 XTALT2 XTAL1 GN D
8051 MCU
Vc c P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 EA / VppALE PSEN P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0
P0.0
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
5.0
S1 S2 S3 S4
100.0
100.0
100.0
100.0
100.0
100.0
100.0
100.0
led 1N1183
led 1N1183
led 1N1183
led 1N1183
led 1N1183
led 1N1183
led 1N1183
led 1N1183
10.0k
10.0k
10.0k
10.0k
Circuit Description
In this interfacing we use the port 3 as a LCD control and port 1 as a LCD
data. Switches connected on port 3 and LED connected on port 1.
Whenever we use port 0 we have to connect pull up register externally
to make it by directional because of by default port 0 is unidirectional
i.e. only input port .
Vcc
10
K
P0.0
P0.1 Port 0
P0.2
P0.3
8051 P0. 4
P0.5
MCU P0.6
P0.7
Port 0 is also designated as AD0 –AD7 allowing it to be used for both
address and data when connection and 8051 to an external memory
port 0 provides both address and data .The 8051 multiplexes address
and data through port 0 to save pins.
List of hardware.
S.NO. Name of Hardware. Quantity
1. 40 pin IC base 1
2. 8051 p89B51RD2FN MCU 1
3. XTAL(11.0592Mhz) 1
4. Capacitor 30pF 2
5. 10k POT 1
6. LCD 1
7. 7085 regulator 1
8. Pull-up resistor 1
9. G.P. PCB 1
10. Berg strip As required.
11. LED 8
12. Wires As required
13. Resistance As required
14. Multimeter
15. 12v DC supply source 1
16. Soldering wires, soldering iron ,Flux
#include<reg51.h>
pin of port-2//
{
rs=0;
e=0;
e=0;
}
{
int i,j;
for(i=0;i<10;i++)
for(j=0;j<5000;j++);
}
void main()
{
s1=0;
s2=0;
s3=0;
s4=0;
//FOR SCROLLING //
{
{
while(1)
{
int k,l;
comddisply();
delay();
comddisply();
delay();
comddisply();
delay();
comddisply();
delay();
{
}
for(k=0;k<=4;k++)
{
P1=a[k];
datadisply();
delay();
}
for(l=0;l<=15;l++)
{
comddisply();
delay();
}
}
}
//FOR BOUNCING//
if(s2==1)
{
P1=0x38;
comddisply();
delay();
P1=0x0e;
comddisply();
delay();
P1=0x06;
comddisply();
delay();
P1=0x80;
comddisply();
delay();
for(k=0;k<=4;k++)
{
P1=a[k];
datadisply();
delay();
}
while(1)
{
if(s4==1)
{
goto bond;
}
for(l=1;l<=11;l++)
{
P1=0x1c;
comddisply();
delay();
}
for(m=11;m>=1;m--)
{
comddisply();
delay();
}
}
}
{
while(1)
{
int a;
delay();
if(s4==1)
{
goto bond;
}
for(a=0;a<=7;a++)
{
delay();
}
}
}
}
CONCLUSION:-
Knowing about the microcontroller has always been the matter of
excitement for all of us. And summer training during the June 2009 was
the one of the good opportunity to fulfill this. The training was as
fruitful as expected.
There we got the exposure about the 8051 microcontroller and its
various basic electronics components used in developing an embedded
system. We worked on keil tool software which is used to developed
program for embedded system. The work experience in the
Advanced Technology was quite nice. The trainers those were assigned
to us were quite experience