CCE 131-Lecture 4
CCE 131-Lecture 4
CCE131
Lecture 4
8051 Microcontroller-1
❑ General-purpose microprocessors Must add RAM, ROM, I/O ports, and timers externally to make them functional
Make the system bulkier and much more expensive. Have the advantage of versatility on the amount of RAM, ROM,
and I/O ports.
Intel introduced 8051, referred as MCS-51, in 1981. The 8051 is an 8-bit processor
The 8051 had
➢ 128 bytes of RAM
➢ 4K bytes of on-chip ROM
➢ Two timers
➢ One serial port
➢ Four I/O ports, each 8 bits wide
➢ 6 interrupt sources
The 8051 became widely popular after allowing other manufactures to make and market any flavor of the 8051, but remaining
code-compatible.
Hardware Connection
❑ 8051 family members Have 40 pins dedicated for various functions such as I/O, -RD, -WR, address, data, and interrupts.
Come in different packages such as DIP(dual in-line package), QFP(quad flat package).
DIP QFP
❑ Some companies provide a 20-pin version of the 8051 with a reduced number of I/O
ports for less demanding applications
❑ The 8051 has an on-chip oscillator but requires an external clock to run it. A quartz crystal oscillator is connected to inputs
XTAL1 (pin19) and XTAL2 (pin18). The quartz crystal oscillator also needs two capacitors of 30 pF value.
If you use a frequency source other than a crystal oscillator, such as a TTL oscillator, it will be connected to XTAL1
while XTAL2 is left unconnected.
❑ RESET pin is an input and is active high (normally low). Upon applying a high pulse to this pin, the microcontroller
will reset and terminate all activities. This is often referred to as a power-on reset
❑ The vast majority of 8051 register are 8-bit registers. The 8 bits of a register are shown from MSB D7 to the LSB D0.
With an 8-bit data type, any data larger than 8 bits must be broken into 8-bit chunks before it is processed.
❑ No member of 8051 family can access more than 64K bytes of opcode because the PC is 16-bit register.
Register banks and stack
There are 128 bytes of RAM in the 8051. Assigned addresses 00 to 7FH
The 128 bytes are divided into three different groups as follows:
1) A total of 32 bytes from locations 00 to 1F hex are set aside for register banks and the stack.
2) A total of 16 bytes from locations 20H to 2FH are set aside for bit-addressable read/write memory.
3) A total of 80 bytes from locations 30H to 7FH are used for read and write storage, called scratch pad
We can switch to other banks by use of the PSW register. Bits D4 and D3 of the PSW are used to select the desired
register bank. Use the bit-addressable instructions SETB and CLR to access PSW.4 and PSW.3
Register banks and stack
❑ Loading the contents of the stack back into a CPU register is called a POP.
With every pop, the top byte of the stack is copied to the register specified
by the instruction and the stack pointer is decremented once.
Example
Example
Structure of Assembly Language
END
This indicates to the assembler the end of the source (asm) file. The END directive is the last line of an 8051 program.
EQU (equate)
This is used to define a constant without occupying a memory location.
DB
The DB directive is the most widely used data directive in the assembler. It is used to define the 8-bit data. When DB is used
to define data, the numbers can be in decimal, binary, hex, ASCII formats.