Mpmc2024-25second Quick Reference
Mpmc2024-25second Quick Reference
Microcontroller
Microcontroller 8051
Intel MCS-51 consists of various
devices and versions. The MCS-51
family member also referred as 8051
microcontroller.
Features of 8051
Microcontroller 8051
Features of 8051
MCS-51 is a family of 8 bit microcontrollers
Operating frequency s 12 MHz
Available in ROM/EPROM/EEPROM versions.
Separate 64K program and 64K data memory.
Multiply and Divide instructions available
Has a Boolean processor and supports bitwise
operations.
Designed with HMOS also available CHMOS
Microcontroller 8051
Features of 8051
32 I/O lines(4 ports each 8 bit wide)
16 bit address and 8 bit data.
128 bites of RAM
4K on-chip ROM
Two timer
6 interrupt sources
One serial port
Microcontroller 8051
Microcontroller 8051
Accumulator(ACC): The accumulator (ACC or
A) acts as an operand register, in case of some
instructions. This may be implicit or specified
by the instruction. It has been allocated an
address in the On-chip RAM.
B register: This is used to store one of the
operand for multiply and divide instructions.
Stack pointer (SP):it is 8-bit wide. It is
incremented during push and Call operations
and decremented during pop and return
instructions. After reset it is initialized to 07H,
i.e, stack begins at 08H
Microcontroller 8051
Program Counter(PC): Instruction
opcodes are fetched from program
memory location addressed by PC.
16-bit wide it can address 64K code
bytes. PC always pointed to
instruction to be fetched and is
automatically incremented after
fetching instruction. PC affected by
JUMP and CALL. Only PC does not
have On chip Address.
Microcontroller 8051
ALU: It performs 8 bit arithmetic and
logical operations.
Boolean Processor: It has its own
instruction set, ACC, and bit
addressable RAM.
Data Pointer: It contains two bytes
DPH and DPL. It is used to access the
off chip data and code with MOVX and
MOVC commands.(INC DPTR)
Microcontroller 8051
Port 0 to Port 3 latches and Drivers:
these four latches and driver pairs are
allotted to each of the four on chip
ports. These latches are allotted
address in the special function
register bank.
Microcontroller 8051
Microcontroller 8051
Microcontroller 8051
Microcontroller 8051
Pins 1 to 8 − These pins are known as Port 1.
This port doesn’t serve any other functions.
Quasi-bi directional I/O. It is internally pulled
up. One has to configure it either i/p or o/p by
writing ‘1’ or ‘0’.
Pin 9 − It is a RESET pin, which is used to
reset the microcontroller to its initial values.
Pins 10 to 17 − These pins are known as Port
3. Quasi-bi directional I/O This port serves
some functions like interrupts, timer input,
control signals, serial communication signals
RxD and TxD, etc.
Microcontroller 8051
Microcontroller 8051
Pins 18 & 19 − These pins are used
for interfacing an external crystal to
get the system clock.
Pin 20(Vss)− it is ground.all the
voltages specified
Pins 21 to 28 − These pins are known
as Port 2. Quasi-bi directional I/O It
serves as I/O port. Higher order
address bus signals are also
multiplexed using this port.
Microcontroller 8051
Pin 29 − This is PSEN pin which
stands for Program Store Enable. It is
used to read a signal from the external
program memory.
Pin 31 − This is EA pin which stands
for External Access input. It is used to
enable/disable the external memory
interfacing.
Microcontroller 8051
Pin 30 − This is ALE pin which stands
for Address Latch Enable. It is used to
demultiplex the address-data signal of
port.
Pins 32 to 39 −true Bi- directional
I/O. These pins are known as Port 0. It
serves as I/O port. Lower order
address and data bus signals are
multiplexed using this port.
Microcontroller 8051
Pin 40 − This pin is used to provide
power supply to the circuit. It is
connected to +5V power supply, with
current rating 125mA(8031/8051)
250ma(8751). For 8051/31 maximum
power dissipation is 1W.
Microcontroller 8051
Microcontroller 8051 I/O ports
Microcontroller 8051 I/O ports
8051 has for 8-bit I/O ports and each port pins
could be addressed individually.
Each port consists of a latch, an output driver
and an input buffer.
Bit latch is shown as D flip-flop. Which clocks in
the a value from internal data bus in response
to the write to latch.
Q output can be read onto internal bus from
reading a latch.
The port pin status can be read onto the
internal bus when CPU gives a read pin.
Microcontroller 8051 I/O ports
Ports 1,2,3 are quasi bidirectional and have
fixed internal pull-up resistors.
When configured as input they are pulled high,
a ‘1’ must be written to a port latch and
external device may pull it low.
The pin status can be read on to the internal
data bus.
Once reset 8051 latches have 1 s written them
and are configured as inputs.
At any time port can be used as output.
Microcontroller 8051 I/O ports
Port 0 not have internal pull-up resistors.
When it configured as input it floats and it is
true bidirectional.
For normal operation pull-up FET if OFF,
provides open drain so it requires external pull-
up resistor.
If a’1’ is written to port 0, either FET go OFF
and pin floats and can be used as high
impedance input.
The pull-up FET only operates in an access to
External Memory.
Microcontroller 8051 Interrupts
Arithmetic Instructions
8- bit arithmetic operations are supported by 8051. it is
possible carryout both signed and unsigned addition
subtraction using OV flag. BCD arithmetic operations can
perform. There are Unsigned Multiplication and division
operations supported by Instructions
Microcontroller 8051 Instuction set
Microcontroller 8051 Instuction set
Microcontroller 8051 Instuction set
Logical Instructions
Bit wise logical AND, OR, EX-OR operations possible.
These instructions accept 8 bit operands and stores the
result in destination.
Single-operand instructions like SETB,CLR, CPL and
Rotate instructions RR,RRC,RL and RLC and swap.
Microcontroller 8051 Instruction set
Microcontroller 8051 Instruction set
Microcontroller 8051 Instruction set
Microcontroller 8051 Instruction set
Microcontroller 8051 Instruction set
Microcontroller 8051 Instruction set
Microcontroller 8051 Instruction set
Microcontroller 8051 Instruction set
Microcontroller 8051 Instruction set
Program Flow Control
• Unconditional jumps (“go to”)
• Conditional jumps
MOV R7,#4
loop1:MOV R0,#40H
MOV R6,#04
loop:MOV A,@R0
INC R0
MOV 50H,@R0
CJNE A,50H,next
SJMP down
next:JC down
MOV @R0,A
DEC R0
MOV @R0,50H
down:DJNZ R6,loop
DJNZ R7,loop1
END
Microcontroller 8051 PCON
PCON (Power Control)
The PCON or Power Control register, as the name suggests is used to control
the 8051 Microcontroller’s Power Modes and is located at 87H of the SFR
Memory Space. Using two bits in the PCON Register, the microcontroller can
be set to Idle Mode and Power Down Mode.
NOTE: PCON register is not bit addressable. During Idle Mode, the
Microcontroller will stop the Clock Signal to the ALU (CPU) but it is given to
other peripherals like Timer, Serial, Interrupts, etc. In order to terminate the Idle
Mode, you have to use an Interrupt or Hardware Reset.
In the Power Down Mode, the oscillator will be stopped and the power will be
reduced to 2V. To terminate the Power Down Mode, you have to use the
Hardware Reset.
Apart from these two, the PCON Register can also be used for few additional
purposes. The SMOD Bit in the PCON Register is used to control the Baud Rate
of the Serial Port.
Microcontroller 8051 programing tools
Microcontroller 8051 SCON
MOV R7,#4
loop1:MOV R0,#40H
MOV R6,#04
loop:MOV A,@R0
INC R0
MOV 50H,@R0
CJNE A,50H,next
SJMP down
next:JC down
MOV @R0,A
DEC R0
MOV @R0,50H
down:DJNZ R6,loop
DJNZ R7,loop1
END
Microcontroller 8051 LED interfacing
Microcontroller 8051 LED interfacing
Microcontroller 8051 LED interfacing
Microcontroller 8051 LED interfacing
Microcontroller 8051 LED interfacing
Seven Segment Display
Seven Segment Display
Seven Segment Display
Seven Segment Display
Seven Segment Display
unsigned char ch[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}
Microcontroller Keyboard Interface
Microcontroller Keyboard Interface
This is a 4×4 matrix keypad or it is also called a hex
keypad, as shown in Figure 1. It has got 8 pins to read
the key pressed.
And out of eight pins, the first 4 pins are called row
pins. R1, R2, R3, and R4 are row pins. And the next 4
pins are called column pins. C1, C2, C3, and C4 are
column pins.
Microcontroller Keyboard Interface
Microcontroller Keyboard Interface
There are 4 column lines and 4-row lines. And in between the row
and a column, a key is implemented.
And when no key is pressed on this keypad the columns and rows
are completely isolated. So, there is no connection at all.
Note that columns C1, C2, C3, and C4 are input to the
microcontroller. Microcontroller code reads C1, C2, C3, and C4
to detect the key pressed. And the pins R1, R2, R3, and R4 are
outputs to the microcontroller.
Microcontroller Keyboard Interface
when the key is pressed there will be a contact between a row and a
column.
Microcontroller Keyboard Interface
Microcontroller Keyboard Interface
Microcontroller Keyboard Interface
#include<reg52.h>
//Keypad Connections
sbit R1 = P1^0;
sbit R2 = P1^1;
sbit R3 = P1^2;
sbit R4 = P1^3;
sbit C1 = P1^4;
sbit C2 = P1^5;
sbit C3 = P1^6;
sbit C4 = P1^7;
//End Keypad Connections
Microcontroller Keyboard Interface
void Delay(int a)
{
int j;
int i;
for(i=0;i<a;i++)
{
for(j=0;j<100;j++)
}
}
Microcontroller Keyboard Interface
Microcontroller Keyboard Interface
C1=1;
C2=1;
C3=1;
C4=1;
R1=0;
R2=1;
R3=1;
R4=1;
if(C1==0){Delay(100);while(C1==0);return ‘*';}
if(C2==0){Delay(100);while(C2==0);return ‘0';}
if(C3==0){Delay(100);while(C3==0);return ‘#';}
if(C4==0){Delay(100);while(C4==0);return ‘D’;}
Microcontroller Keyboard Interface
R1=1;
R2=0;
R3=1;
R4=1;
if(C1==0){Delay(100);while(C1==0);return '4';}
if(C2==0){Delay(100);while(C2==0);return '5';}
if(C3==0){Delay(100);while(C3==0);return '6';}
if(C4==0){Delay(100);while(C4==0);return 'X';}
R1=1;
R2=1;
R3=0;
R4=1;
if(C1==0){Delay(100);while(C1==0);return '1';}
if(C2==0){Delay(100);while(C2==0);return '2';}
if(C3==0){Delay(100);while(C3==0);return '3';}
if(C4==0){Delay(100);while(C4==0);return '-';}
Microcontroller Keyboard Interface
R1=1;
R2=1;
R3=1;
R4=0;
if(C1==0){Delay(100);while(C1==0);return 'C';}
if(C2==0){Delay(100);while(C2==0);return '0';}
if(C3==0){Delay(100);while(C3==0);return '=';}
if(C4==0){Delay(100);while(C4==0);return '+';}
return 0; }
Microcontroller Stepper MOtor Interface
https://upload.wikimedia.org/wikipedia/commons/6/67/StepperMotor.gif
Microcontroller Stepper MOtor Interface
Stepper motor is brushless DC motor, which can be rotated in small
angles, these angles are called steps. Generally stepper motor use 200
steps to complete 360 degree rotation, means its rotate 1.8 degree per
step.
three modes of operation Wave drive mode, full step drive mode and
half step drive mode.
Microcontroller Stepper MOtor Interface
Wave drive mode: In this mode one coil is energised at a time, all
four coil are energised one after another. It produces less torque in
compare with Full step drive mode but power consumption is less.
Microcontroller Stepper MOtor Interface
Full Drive mode: In this, two coil are energised at the same time
producing high torque. Power consumption is higher. We need to give
Logic 1 to two coils at the same time, then to the next two coils and so
on.
Microcontroller Stepper MOtor Interface
Half Drive mode: In this mode one and two coils are energised
alternatively, means firstly one coil is energised then two coils are
energised then again one coil is energised then again two, and so on.
This is combination of full and wave drive mode, and used to increase
the angular rotation of the motor.
Microcontroller Stepper MOtor Interface
Microcontroller Stepper MOtor Interface
// Wave drive Mode
#include<reg51.h>
void msdelay(unsigned int time)
{
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void main()
{
while(1)
{
P2=0x01; // 0001 P2_0=1,P2_1=0,P2_2=0,P2_3=0
msdelay(1);
P2=0x02; //0010
msdelay(1);
P2=0x04; //0100
msdelay(1);
P2=0x08; //1000
msdelay(1);
}}
Microcontroller Stepper MOtor Interface
/ Full
drive Mode
#include<reg51.h>
void msdelay(unsigned int time)
{
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void main()
{
while(1)
{
P2 = 0x03; //0011 P2_0=1,P2_1=1,P2_2=0,P2_3=0
msdelay(1);
P2 = 0x06; //0110
msdelay(1);
P2 = 0x0C; //1100
msdelay(1);
P2 = 0x09; //1001
msdelay(1);
}}
DMA Controller-8257
Features of 8257
•It has four channels which can be used over four I/O devices.
•Each channel has 16-bit address and 14-bit counter.
•Each channel can transfer data up to 64kb.
•Each channel can be programmed independently.
•Each channel can perform read transfer, write transfer and verify transfer
operations.
•It generates MARK signal to the peripheral device that 128 bytes have been
transferred.
•ItItsrequires a single phase clock.
• frequency ranges from 250Hz to 3MHz.
•It operates in 2 modes, i.e., Master mode and Slave mode.
DMA Controller-8257
DMA Controller-8257
DMA Controller-8257
DRQ −DRQ3
These0are the four individual channel DMA request inputs, which are used by the
peripheral devices for using DMA services. When the fixed priority mode is
selected, then DRQ has the highest priority and DRQ has the lowest priority
among them. 0 3
DACK − DACK
o the active-low
These are 3 DMA acknowledge lines, which updates the requesting
peripheral about the status of their request by the CPU. These lines can also act as
strobe lines for the requesting devices.
D −D
o are
These 7 bidirectional, data lines which are used to interface the system bus with
the internal data bus of DMA controller. In the Slave mode, it carries command
words to 8257 and status word from 8257. In the master mode, these lines are used
to send higher byte of the generated address to the latch. This address is further
latched using ADSTB signal.
DMA Controller-8257
IOR
It is an active-low bidirectional tri-state input line, which is used by the CPU to read
internal registers of 8257 in the Slave mode. In the master mode, it is used to read
data from the peripheral devices during a memory write cycle.
IOW
It is an active low bi-direction tri-state line, which is used to load the contents of the
data bus to the 8-bit mode register or upper/lower byte of a 16-bit DMA address
register or terminal count register. In the master mode, it is used to load the data to
the peripheral devices during DMA memory read cycle.
CLK
It is a clock frequency signal which is required for the internal operation of 8257.
RESET
This signal is used to RESET the DMA controller by disabling all the DMA channels.
DMA Controller-8257
A -A
o are
These 3 the four least significant address lines. In the slave mode, they act as an
input, which selects one of the registers to be read or written. In the master mode,
they are the four least significant memory address output lines generated by 8257.
CS
It is an active-low chip select line. In the Slave mode, it enables the read/write
operations to/from 8257. In the master mode, it disables the read/write operations
to/from 8257.
A -A
4 are
These 7 the higher nibble of the lower byte address generated by DMA in the
master mode.
READY
It is an active-high asynchronous input signal, which makes DMA ready by inserting
wait states.
DMA Controller-8257
HRQ
This signal is used to receive the hold request signal from the output device. In the slave
mode, it is connected with a DRQ input line 8257. In Master mode, it is connected with
HOLD input of the CPU.
HLDA
It is the hold acknowledgement signal which indicates the DMA controller that the bus
has been granted to the requesting peripheral by the CPU when it is set to 1.
MEMR
It is the low memory read signal, which is used to read the data from the addressed
memory locations during DMA read cycles.
MEMW
It is the active-low three state signal which is used to write the data to the addressed
memory location during DMA write operation.
ADSTB
This signal is used to convert the higher byte of the memory address generated by the
DMA controller into the latches.
DMA Controller-8257
AEN
This signal is used to disable the address bus/data bus.
TC
It stands for ‘Terminal Count’, which indicates the present DMA cycle to the present
peripheral devices.
MARK
The mark will be activated after each 128 cycles or integral multiples of it from the
beginning. It indicates the current DMA cycle is the 128th cycle since the previous
MARK output to the selected peripheral device.
V
cc
It is the power signal which is required for the operation of the circuit.
Microcontroller 8051 LED interfacing
ORG 0000H
RETURN: MOV PO, #00H
ACALL DELAY
MOV P0, #0FFH
ACALL DELAY
SJUMP RETURN
DELAY: MOV R5, #50H //load register R5 with 50//
DELAY1: MOV R6, #200 //load register R6 with 200//
DELAY2: MOV R7, #229 //load register R7 with 200//
DJNZ R7, $ //decrement R7 till it is zero//
DJNZ R6, DELAY2//decrement R6 till it is zero//
DJNZ R5, DELAY1//decrement R5 till it is zero//
RET //go back to the main program //
END
Microcontroller 8051 serial
communication (UART)
8051 support a full duplex serial port.
8051 has TXD and RXD pins for transmission and
reception of serial data.
ItInsupport RS 232 standard.
serial communication baud rate is an important
factor.
bit.
The baud is the reciprocal of the time to send one
Multiprocessor Communication:
It is possible by setting SM2 bit in SCON register.
It is support in MODE 2 and 3.9 bits transmitted. 9
th bit goes to RB8.
Transmitting processor assumed as Master and all
other as slaves.
When master want to transmit ist sends address
byte of slve. 9th bit is 1 (slave), 0(Mater).
Microcontroller 8051 PCON
Microcontroller 8051 PCON
Bit 7 – SMOD
1 = Baud rate is doubled in UART mode 1, 2 and 3.
0 = No effect on Baud rate.