0% found this document useful (0 votes)
18 views146 pages

Mpmc2024-25second Quick Reference

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

Mpmc2024-25second Quick Reference

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

Microprocessor

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

If interrupt event occurs AND interrupt flag for


that event is enabled, AND interrupts are
enabled, then:
1. Current PC is pushed on stack.
2. Program execution continues at the interrupt
vector address for that interrupt.
3. When a RETI instruction is encountered, the
PC is popped from the stack and program
execution resumes where it left off.
Microcontroller 8051 Interrupts

 What if two interrupt sources interrupt at the


same time?
 The interrupt with the highest PRIORITY gets
serviced first.
 All interrupts have a default priority order.
 Priority can also be set to “high” or “low”.
Microcontroller 8051 Interrupts

 8051 has 5 sources of interrupts


 Timer 0 overflow
 Timer 1 overflow
 External Interrupt 0
 External Interrupt 1
 Serial Port events (buffer full, buffer empty, etc)
Microcontroller 8051 Interrupts
Microcontroller 8051 Interrupts
Microcontroller 8051 Interrupts
Microcontroller 8051 Timer/Counter
 8051 has on chip timer/Counter which provides
pulse counting, frequency measuring, pulse
width measurement and Baud rate generation.
 A timer counts machine cycles and provides
reference time or a clock. A machine cycle of
8051 contains 12 oscillator periods and
counting rate of 1/12 of the oscillator
frequency. At 12 MHz frequency, the clock
period will be equal to 1 usec.
Microcontroller 8051 Timer/Counter
 A counter of 8051 increment in response to
transition from 1 to 0 at its external pin( T0 or
T1). 8051 takes 2 machine cycles(24 OSC
periods) to detect 1 to 0 transition at pin.
 When a timer or counter overflows from FFFF
to 0000, it sets a flag and generates an
interrupt.
 Timer has 2 16 bit registers call T0 and T1 and
higher byte referred as THx and lower byte
referred as TLx.
 Thre are two SFRs for timer: TMOD & TCON
Microcontroller 8051 Timer/Counter
Microcontroller 8051 Timer/Counter
Microcontroller 8051 Timer/Counter
Microcontroller 8051 Timer/Counter

Mode0: It is 13 bit timer. This mode is same for timer 0


and timer 1 .Using upper bite THx and lower 5 bits of TLx.
When timer overflows Timer interrupt flag (TF) will set.
To start timer TR bit in TCON is required to be set.
Microcontroller 8051 Timer/Counter
Mode1: It is 16 bit timer. Same as mode 0. This mode is
same for timer 0 and timer 1 .Using upper bite THx and
TLx. When timer overflows Timer interrupt flag (TF) will
set. To start timer TR bit in TCON is required to be set.
The maximum count in this mode is FFFFH.
Microcontroller 8051 Timer/Counter
The Gate flags in TMOD decide whether counting will be
gated by the corresponding external interrupt pin in P3. If the
Gate Flag is cleared, the counter is enabled by the TR flag
alone. If the Gate flag is set, counting also requires the
corresponding external interrupt pin in P3 to be HIGH. This is
useful for measuring pulse widths.
Microcontroller 8051 Timer/Counter
Mode2: This mode provides an 8 bit counter with auto-
reload. It uses the high byte of the count register to store
the count value and the low byte as the actual counter. The
counter is automatically re-loaded from TH when it
overflows. Thus, there is no software overhead for re-
loading the registers. This is convenient for generating
baud rates etc. The timing resolution is much lower in this
mode (only 8 bits). Therefore crystal frequencies have to
be carefully chosen to generate accurate baud rates.
Crystals of 11.059 MHz are often used rather than 12 MHz
for this reason.
Microcontroller 8051 Timer/Counter
Mode2:
Microcontroller 8051 Timer/Counter
Mode3:In this mode Timers T0 and T1 behave quite
differently. T0 acts as two independent 8 bit counters.
Count register TL0 uses the resources (such as the RUN
flag, overflow flag) in TCON, TMOD etc. meant for T0.
Similarly, TH0 uses the resources meant for T1. Thus, TR1
will enable running the 8 bit counter made up of TH0. TF1
will be set whenever TH0 overflows. T1 now has no
control bits at all! It can only be used for services which
require no control, no gating and no interrupts. Thus, T1
can be used for Baud rate generation, while we still have
two timers available (both with 8 bit resolution).
Microcontroller 8051 Timer/Counter
Mode 3:
Microcontroller 8051 External Memory
Microcontroller 8051 External Memory

8051 has 64K external data, 64k Program memory. 256


bytes of internal data memory.
The 64 K program memory is divided into internal and
external memory.
 If EA(bar) is high executes from internal until exceeds
0FFFh. After 1000h through 0FFFFh are executed from
external memory.
 If EA(bar) is low, them 8051 executes instructions from
external memory only.
Microcontroller 8051 External Memory
Microcontroller 8051 External Memory
 64K external data memory can be accessed using MOVX
instruction.
The internal data memory of 8051 is 256 bytes, which is
divided into two parts.
The lower128 bytes called as internal data RAM and
upper 128 bytes consists of SFRs. In case of 8052/32 the
upper 128 bytes also addressable.
Even though the SFRs and upper 128 bytes RAM have
same address space, they are different and accessed through
addressing modes.
Microcontroller 8051 External Memory
Microcontroller 8051 Addressing
modes

It defines the way in which the operands accessed by the


instruction.
There are five addressing modes supported by 8051
Registrar addressing mode
Direct addressing mode
Register indirect addressing mode
Immediate addressing mode
Base register plus Index register addressing mode
Microcontroller 8051 Addressing
modes
In
Registrar addressing mode
 this addressing mode, registers R0- R7 from selected
register bank, accumulator, B-register, Carry bit and DPTR
are used.
Ex: MOVMOV A, Rr
 Rr, A
* Register to register moves using register addressing mode
occur between register and R0 to R7.
Microcontroller 8051 Addressing
modes
In
Direct addressing mode
 this addressing mode, the direct address of operand is
specified in the instruction itself. It uses the 128 bytes of
internal RAM(00-7Fh) and special function registers from
80-FF H.
Ex: MOV A, addr; MOV a,54h
MOV addr, A; MOV Rr,addr
MOV addr,#n;
 MOV A,99H which reads contents of SBUF into
accumulator.
Microcontroller 8051 Addressing
modes
In
Register indirect addressing mode
 this addressing mode, any one of the register R0 or R1
from the selected register bank used as a pointer to the
location in 128 bytes of data memory. Note that the SFRs
are not addressed by this mode, similarly external memory
beyond 256 bytes not addressed. The mnemonic symbol
used for this addressing is at “@”.

EX: MOV a@Rp MOV @Rp,#n

MOV addr, @Rp MOV @Rp,addr


Microcontroller 8051 Addressing
modes
Immediate addressing mode
In this addressing mode Immediate data is part of the
instruction. The symbol “#” preceding the constant
indiactes the immediate data. It copies immediate numbers
to register R0 to R7,a,b, and DPTR.
Ex: MOV Rr,#n MOV R1,#33h
MOV A, #n MOV A,44H
MOV DPTR,#nn MOV DPTR,1234h
Microcontroller 8051 Addressing
modes
Base register plus Index register addressing mode
In this addressing mode, allows a byte to be accessed
from the program memory, whose address is calculated as
the sum of the base register (DPTR or PC) and Index
register Accumulator.
EX: MOVC A,@ A+PC
MOVC A, @A+DPTR
MOVX A,@A+DPTR
Microcontroller 8051 Instuction set

8051 supports 111 instructions. These instructions are


may be single, two and three byte instruction. There are 45
single byte, 45 two byte and 17 three byte instructions.
8051 Instruction set contains
Data transfer Instructions
Arithmetic Instructions
Logical Instructions
Boolean Variable manipulation Instructions
Branching (control Transfer Instructions)
Microcontroller 8051 Instuction set

Data transfer Instructions


 There are MOV, MOVX, MOVC, PUSH, POP, and
exchange XCHG, XCH instruction under Data transfer
instructions.
Microcontroller 8051 Instuction set
Microcontroller 8051 Instuction set

 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

• Call and return


Microcontroller 8051 Instruction set
• SJMP <rel addr> ; Short jump,
relative address is 8-bit 2’s complement
number, so jump can be up to 127
locations forward, or 128 locations back.
• LJMP <address 16> ; Long jump,
• The LJMP instruction transfers program
execution to the specified 16-bit
address. The PC is loaded with the high-
order and low-order bytes of the address
from the second and third bytes of this
instruction respectively. No flags are
affected by this instruction.
https://www.keil.com/support/man/docs/is51/is51_instructions.htm
Microcontroller 8051 Instruction set

• AJMP <address 11> ; Absolute


jump to anywhere within 2K
block of program memory.
• JMP @A + DPTR ;
Long indexed jump
Microcontroller 8051 Instruction set
 ACALL:The ACALL instruction calls a subroutine located
at the specified address. The PC is incremented twice to
obtain the address of the following instruction. The 16-
bit PC is then stored on the stack (low-order byte first)
and the stack pointer is incremented twice. No flags are
affected.
 LCALL.
Microcontroller 8051 Instruction set
 Conditional jumps
Microcontroller 8051 Instruction set
 Conditional jumps
Microcontroller 8051 Assembler
Directives
EQU directive
The EQU directive is used to replace a number by a symbol.
For example: MAXIMUM EQU 99
SET directive
The SET directive is also used to replace a number by a
symbol. The significant difference
compared to the EQU directive is that the SET directive can
be used an unlimited number of times:
SPEED SET 45
SPEED SET 46
SPEED SET 57
Microcontroller 8051 Assembler
Directives
 ORG (origin):-
 The origin (ORG) directive is used to indicate the
beginning of the addresses the number that comes after
ORG can be either in hex or in decimal if the number is
not followed by H it is decimal and the assembler will
convert it to hex some assembler use “.ORG” instead of
“ORG” for the origin directive.
 END:-
 Important pseudo code is the END directive this indicates
to the assembler at the end of the source (asm) file the
END directive is the last line of an 8051 program
meaning that in the source code anything after the END
directive is ignored by the assembler.
Microcontroller 8051 Assembler
Directives
 DB (Define byte):-
 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 or ASCII format for decimal “D” after the
decimal number, for binary ‘B’ and hexadecimal ‘H’
required. DB directive is the only directive that can be
used to define ASCII strings larger than the character
therefore it should be used for all ASCII data definitions.
 DATA 1: DB 28 (Decimal)
 DATA 2: DB 39H (HEX)
 DATA 3: 0101001 B (Binary)
Microcontroller 8051 simple program
 The following is a simple Assembly Language for 8051
Microcontroller which copies the data from R0 of Bank0
to R0 of Bank3.
 ORG 00H
 MOV R0, #33H
 MOV A, R0
 SETB PSW.3
 SETB PSW.4
 MOV R0, A
 END
Microcontroller 8051 programing tools
Multiplication and Division

MOV A,51H ;get content of memory location 51H to accumulator


MOV 0F0H,52H;get content of memory location 52H to B register
MUL AB ;multiply content of A with content of B
MOV 53H,A ;get lower order byte of product in memory location 53H
MOV54H,0F0H ;get higher order byte of product in memory location
in 54H
MOV A,51H ;get content of memory location 51H to accumulator
MOV 0F0H,52H ;get content of memory location 52H to register B
DIV AB ;divide content of register A with register B
MOV 55H,A ;Copy quotient of result to memory location 55H
MOV 56H,0F0H ;copy remainder of result to memory location 56H
END
Microcontroller 8051 programing tools

main: MOV R0,#0Ah ;N value


MOV R1,#01h
Mov a,00h
loop: ADD A,R1
INC R1
DJNZ R0, loop
MOV R4,A ; Final result is stored in register R4 end
Microcontroller 8051 programing tools
ORG 0000
MOV R1,#04
MOV R7,#01
LCALL FACT
MOV R7,A
FACT:
MOV A,R7
UP:
MOV B,R1
MUL AB
DJNZ R1,UP
RET
END
Microcontroller 8051 programing tools

Sum of 8-bit Numbers Stored in Memory


MOV R0,#50H ;get memory location in memory pointer R0
MOV R1,#51H ;get memory location on memory pointer register R1
MOV A,@R0 ;get content of memory location 50H to accumulator
ADD A,@R1 ;add content of A with content of memory location
51H and store result in A
MOV R0,#52H ;get 52H to memory pointer R0
MOV@R0,A ;copy content of A to memory location 52H
END
Microcontroller 8051 programing tools
Add 16-bit Numbers
MOV DPTR,#2040H ; get 2040H into DPTR
MOV A,#2BH ;get lower byte of second 16-bit number on
accumulator
MOV R0,#20H ;get higher byte of second 16-bit number on
accumulator
ADD A,82H ;[A]+[DPL]
MOV 82H,A ;save result of lower byte addition
MOV A,R0 ;get higher byte of second number in A
ADDC A,83H ;[A]+[DPH]
MOV 83H,A ;Save result of higher byte addition
END
Microcontroller 8051 programing tools

Packed to Packed Numbers


MOV R0,50H ;get packed number from memory location 50H
MOV A,R0 ;copy packed number to accumulator
ANL A,#0FH ; mask upper nibble of packed number
MOV 51H,A ;save lower digit to 51H
MOV A,R0 ;get packed number again
ANL A,#0F0H ;mask lower nibble of packed number
SWAP A ;exchange lower and upper nibbles
MOV 52H,A ;save upper digit
END
Microcontroller 8051 programing tools
Sort n Numbers in Ascending Order

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

SCON (Serial Control)


The Serial Control or SCON SFR is used to control the 8051
Microcontroller’s Serial Port. It is located as an address of 98H. Using
SCON, you can control the Operation Modes of the Serial Port, Baud Rate
of the Serial Port and Send or Receive Data using Serial Port.
SCON Register also consists of bits that are automatically SET when a byte
of data is transmitted or received.
Microcontroller 8051 SCON
Microcontroller 8051 SCON
Microcontroller 8051 programing tools
Sort n Numbers in Ascending Order

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

 The start and stop bits used to synchronize the


serial receivers.
https://www.youtube.com/watch?v=oIt-8XQxWKI
Microcontroller 8051 serial
communication
Microcontroller 8051 serial
communication modes
Microcontroller 8051 serial
communication

 Mode 0: It is shift register mode. Only RXD used


for data enter and exit. TXD pin used for clock only.
Eight bits are transmitted and received.
The baud rate is fixed it is fosc/12.
Microcontroller 8051 serial
communication

Mode 1: 10 bits are transmitted through TXD and


received by RXD.
There is a start bit(0) and stop bit(1).
On receiving stop bit goes into RB8 in SCON.
The baud rate is variable =
Microcontroller 8051 serial
communication

Mode 2: It is 11 bits are transmitted through TXD


and received by RXD.
There is a start bit(0) and stop bit(1) and a
programmable 9 th bit(may be parity) can be
transmitted.
On receiving 9th bit goes into RB8 in SCON.
 The baud
Overflow)
rate is variable =2^SMOD/32X(Timer1
Microcontroller 8051 serial
communication

Mode 3:It is 11 bits are transmitted through TXD


and received by RXD.
There is a start bit(0) and stop bit(1) and a
programmable 9 th bit(may be parity) can be
transmitted.
Same as mode 2 baud rate is defined by timer1
Microcontroller 8051 serial
communication

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.

In Power Down mode, the oscillator clock provided to the


system is OFF i.e. CPU and peripherals clock remains inactive in
this mode. Hardware reset can cancel this mode.
In Idle Mode, only the clock provided to the CPU gets
deactivated, whereas the peripherals clock will remain active in
this mode. Interrupt and H/W reset can cancel this mode.
Microcontroller serial communication
Baud Rate calculation:
• To meet the standard baud ratesused.
generally crystal with 11.0592 MHz is

•As we know, 8051 divides crystal frequency by 12 to get a machine cycle


frequency of 921.6 kHz.
•The internal UART block of 8051 divides this machine cycle frequency by
32, which gives the frequency of 28800 Hz which is used by UART.
•To achieve a baud rate of 9600, again 28800 Hz frequency should be
divided by 3.
•This is achieved by using253
Timer1 in mode-2 (auto-reload mode) by putting
in TH1 (8-bit reg.)
•So 28800 Hz will get divided by 3 as the timer will overflow after every 3
cycles.
•we can achieve different baudTH1
rates by putting the division factor in the
register.
Microcontroller serial communication
Baud Rate calculation:
Microcontroller serial communication
Microcontroller serial communication
Microcontroller serial communication

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy