0% found this document useful (0 votes)
54 views10 pages

Assi 1

The document discusses an assignment for an electrical engineering microcontroller lab, describing the basic components and registers of an 8051 microcontroller including the accumulator, R registers, B register, data pointer, program counter, stack pointer, and flags. It explains the functions of these components such as temporary storage, addressing memory, program flow, and arithmetic operations.

Uploaded by

Xzxz Wahsh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views10 pages

Assi 1

The document discusses an assignment for an electrical engineering microcontroller lab, describing the basic components and registers of an 8051 microcontroller including the accumulator, R registers, B register, data pointer, program counter, stack pointer, and flags. It explains the functions of these components such as temporary storage, addressing memory, program flow, and arithmetic operations.

Uploaded by

Xzxz Wahsh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Ministry of Higher Education and Scientific Research

University of Technology
Department of Electrical Engineering
Microcontroller Lab

Assignment 1

Written by

Mohammed Jawad Kamil

Date: July 5, 2020


1.
2.
3.
4.

5.

6.
Embedded system: is a combination of computer hardware and software designed for a specific
function or functions within a larger system. The systems can be programmable or with fixed
functionality. Industrial machines, consumer electronics, agricultural and process industry
devices, automobiles, medical equipment, cameras, household appliances, airplanes, vending
machines and toys, as well as mobile devices, are possible locations for an embedded system.
7.

8.
9.
A total of 32 bytes of RAM are set aside for the register banks and the stack. These 32 bytes are
divided into four register banks in which each bank has 8 registers, R0–R7. RAM locations from
0 to 7 are set aside for bank 0 of R0–R7 where R0 is RAM location 0, R1 is RAM location 1, R2
is location 2, and so on, until the memory location 7, which belongs to R7 of bank 0. The second
bank of registers R0–R7 starts at RAM location 08 and goes to locations OFH. The third bank of
R0–R7 starts at memory location 10H and goes to location to 17H. Finally, RAM locations 18H
to 1FH are set aside for the fourth bank of R0–R7.
Register bank 0 is the default when the 8051 is powered up. We can switch to the other banks
using PSW register. D4 and D3 bits of the PSW are used to select the desired register bank, since
they can be accessed by the bit addressable instructions SETB and CLR. For example, "SETB
PSW.3" will set PSW.3 = 1 and select the bank register 1.

RS1 RS2 Bank Selected

0 0 Bank0

0 1 Bank1

1 0 Bank2

1 1 Bank3

10.
a. Accumulator
The accumulator, register A, is used for all arithmetic and logic operations. If the accumulator is
not present, then every result of each calculation (addition, multiplication, shift, etc.) is to be
stored into the main memory. Access to main memory is slower than access to a register like the
accumulator because the technology used for the large main memory is slower (but cheaper) than
that used for a register.
b. The "R" Registers
The "R" registers are a set of eight registers, namely, R0, R1 to R7. These registers function as
auxiliary or temporary storage registers in many operations. Consider an example of the sum of
10 and 20. Store a variable 10 in an accumulator and another variable 20 in, say, register R4. To
process the addition operation, execute the following command −
ADD A,R4
After executing this instruction, the accumulator will contain the value 30. Thus "R" registers are
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 meant for temporarily storage of values.
Let us take another example. We will add the values in R1 and R2 together and then subtract the
values of R3 and R4 from the result.
MOV A,R3 ;Move the value of R3 into the accumulator
ADD A,R4 ;Add the value of R4
MOV R5,A ;Store the resulting value temporarily in R5
MOV A,R1 ;Move the value of R1 into the accumulator
ADD A,R2 ;Add the value of R2
SUBB A,R5 ;Subtract the value of R5 (which now contains R3 + R4)
As you can see, we used R5 to temporarily hold the sum of R3 and R4. Of course, this is not 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.

c. 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 used only by two 8051 instructions: MUL AB and DIV AB. 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. Apart from using MUL and DIV instructions, the
"B" register is often used as yet another temporary storage register, much like a ninth R register.
d. The Data Pointer
The Data Pointer (DPTR) is the 8051’s only user-accessible 16-bit (2-byte) register. The
Accumulator, R0–R7 registers and B register are 1-byte value registers. DPTR is meant for
pointing to data. It is used by the 8051 to access external memory using the address indicated by
DPTR. DPTR is the only 16-bit register available and is often used to store 2-byte values.
e. The Program Counter
The Program Counter (PC) is a 2-byte address which tells the 8051 where the next instruction to
execute can be found in the memory. PC starts at 0000h when the 8051 initializes and is
incremented every time after an instruction is executed. PC is not always incremented by 1.
Some instructions may require 2 or 3 bytes; in such cases, the PC will be incremented by 2 or 3.
Branch, jump, and interrupt operations load the Program Counter with an address other than
the next sequential location. Activating a power-on reset will cause all values in the register to be
lost. It means the value of the PC is 0 upon reset, forcing the CPU to fetch the first opcode from
the ROM location 0000. It means we must place the first byte of upcode in ROM location 0000
because that is where the CPU expects to find the first instruction.
f. The Stack Pointer (SP)
The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-byte) value. The
Stack Pointer tells the location from where the next value is to be removed from the stack. When
a value is pushed onto the stack, the value of SP is incremented and then the value is stored at the
resulting memory location. When a value is popped off the stack, the value is returned from the
memory location indicated by SP, and then the value of SP is decremented.
This order of operation is important. SP will be initialized to 07h when the 8051 is initialized. If
a value is pushed onto the stack at the same time, the value will be stored in the internal RAM
address 08h because the 8051 will first increment the value of SP (from 07h to 08h) and then will
store the pushed value at that memory address (08h). SP is modified directly by the 8051 by six
instructions: PUSH, POP, ACALL, LCALL, RET, and RETI.
8051 flags:
 CY, the carry flag − This carry flag is set (1) whenever there is a carry out from the D7
bit. It is affected after an 8-bit addition or subtraction operation. It can also be reset to 1
or 0 directly by an instruction such as "SETB C" and "CLR C" where "SETB" stands for
set bit carry and "CLR" stands for clear carry.
 AC, auxiliary carry flag − If there is a carry from D3 and D4 during an ADD or SUB
operation, the AC bit is set; otherwise, it is cleared. It is used for the instruction to
perform binary coded decimal arithmetic.
 P, the parity flag − The parity flag represents the number of 1's in the accumulator
register only. If the A register contains odd number of 1's, then P = 1; and for even
number of 1's, P = 0.
 OV, the overflow flag − This flag is set whenever the result of a signed number
operation is too large causing the high-order bit to overflow into the sign bit. It is used
only to detect errors in signed arithmetic operations.

You might also like