View
228
Download
0
Category
Preview:
Citation preview
8/13/2019 Introduction to 8051 Microcontroller
1/35
8/13/2019 Introduction to 8051 Microcontroller
2/35
1. Introduction1. Definition of microcontroller 2. 8051 microcontroller
1. Basics. 2. I/O Ports. 3. Interrupts (Timer, Serial, External Interrupts).
2. How to program 8051. 1. In assembly.
2. In C 3. Basic programming (delay and other pins basic I/O functions).
8/13/2019 Introduction to 8051 Microcontroller
3/35
4. Timer/counter. 1. Basic timer operations2. Timer interrupts. 3. Counter programming.
4. Some basic codes. 5. LCD and Keypad interfacing. 6. Serial Port Programming
1. Basic serial communication.
2. Serial communication modes. 3. Serial communication registers. 4. Basic serial communication programming in C.
7. Other Interrupts Programming. 1. External interrupt programming.
8/13/2019 Introduction to 8051 Microcontroller
4/35
Definition of microcontroller.
CPU
GeneralPurposeMicro-
processor
RAM ROM I/O Ports Timers Serial COMPort
General Purpose Microprocessor System
8/13/2019 Introduction to 8051 Microcontroller
5/35
8/13/2019 Introduction to 8051 Microcontroller
6/35
The 8051 Microcontroller
Feature 8051 8052 8031
ROM (on-chip program
space in bytes)
4K 8K 0K
RAM (Bytes) 128 256 128
Timers 2 3 2
I/O Pins 32 32 32
Serial Port 1 1 1
Interrupt Sources 6 8 6
Comparison with other Intel microcontrollers
8/13/2019 Introduction to 8051 Microcontroller
7/35
Part Number ROM RAM I/O Pins Timer Interrupt Vcc Packaging
AT89C51 4K 128 32 2 6 5V 40
AT89LV51 4K 128 32 2 6 3V 40
AT89C1051 1K 64 15 1 3 3V 20
AT89C2051 2K 128 15 2 6 3V 20
AT89C52 8K 128 32 3 8 5V 40
AT89LV52 8K 128 32 3 8 3V 40
Note: C Indicates the CMOS
8/13/2019 Introduction to 8051 Microcontroller
8/35
Port 0Port 1Port 2Port 3
8/13/2019 Introduction to 8051 Microcontroller
9/35
Interrupt Vector Table for 8051
Interrupt ROM location (HEX) Flag Clearing
Reset 0000 Auto
External hardware interrupt 0 (INT0) 0003 Auto
Timer 0 interrupt 000B Auto
External hardware interrupt 1 (INT1) 0013 Auto
Timer 1 interrupt 001B Auto
Serial COM interrupt (RI and TI) 0023 Programmer clears it.
8/13/2019 Introduction to 8051 Microcontroller
10/35
D7 D0
EA ---- ET2 ES ET1 EX1 ET0 EX0
EA IE7 Disable all interrupts. If EA=0, no interruptis acknowledged. If EA=1 each interruptsource is individually enabled or disabledby setting or clearing its enable bit.
---- IE6 Not ImplementedET2 IE5 Enable or disable Timer 2 overflow or
capture interrupt (8052 only).
ES IE4 Enables or disable serial port interrupt
ET1 IE3 Enables or disable Timer 1 overflowinterrupt
EX1 IE2 Enable or disable external interrupt 1
ET0 IE1 Enables or disable Timer 0 overflowinterrupt
EX0 IE0 Enable or disable external interrupt 0
IE (Interrupt Enabler) Register
8/13/2019 Introduction to 8051 Microcontroller
11/35
8/13/2019 Introduction to 8051 Microcontroller
12/35
MOV Instructionmov destination,source;
ADD Instructionadd A,sourc; add source operand to the accumulatorand store the result in A.
JUMP Instruction
Conditional Jumps.JZ(Jump if Zero if A=0)DJNZ(Decrement and jump if not zero)JNC( Jump if not Carry set CY=0)JC(Jump if carry set CY=1)
8/13/2019 Introduction to 8051 Microcontroller
13/35
Unconditional JumpsLJMP(Long Jump)
It is a 3byte instruction 1 st byte is used for opcodethe remaining 2 bytes are used for address.
SJMP(Short Jump)It is a 2 byte instruction 1 st byte is used for opcodethe remaining 1 byte is used for address.
CALL InstructionsLCALL(Long Call)
It is also a 3 byte instruction.ACALL(Absolute Call)
It is a Two byte instruction used to call a functionoutside the function being executed.
8/13/2019 Introduction to 8051 Microcontroller
14/35
Role of Stack Pointer for Call Instruction
PUSH and POP Instructions
NOP(No operation) Instruction
8/13/2019 Introduction to 8051 Microcontroller
15/35
Include header file#include
The Main FunctionVoid main(void){}
Decision Making Instructionswhile loop
while(condition) //the program remains in the loop whilethe condition is truefor loopfor(initialization;condition;increment/decrement)
8/13/2019 Introduction to 8051 Microcontroller
16/35
The if else statementsif(condition 1){}else if(condition 2){}else{}
8/13/2019 Introduction to 8051 Microcontroller
17/35
Some Basic C programs
8/13/2019 Introduction to 8051 Microcontroller
18/35
Timer 0 and Timer 1D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
D0-D7 are known as TLxD8-D15 are known as THx
8/13/2019 Introduction to 8051 Microcontroller
19/35
The TMOD (Timer Mode) Register(MSB) (LSB)GATE C/T M1 M0 GATE C/T M1 M0
Timer 1 Timer 0
GATE gating control when set. The timer/counter is enabled onlywhen the INTx pin is high and the TRx pin is set.When cleared, the timer is enabled whenever the TRx control bit isset.C/T Timer or Counter selected cleared for timer operation (inputfrom internal system clock). Set for counter operation (input fromTx input pin).M1 Mode bit 1
M0 Mode bit 0
8/13/2019 Introduction to 8051 Microcontroller
20/35
M1 M0 Mode Operation Mode0 0 0 13-bit timer mode 8-bit
timer/counter THx with TLxas 5 bit presaler
0 1 1 16-bit timer mode 16-bittimer/counter THx and TLxare cascaded; there is noprescaler
1 0 2 8-bit auto reload 8 bit autoreload timer/counter;THxholds the value that is to bereloaded into TLx each timeit overflows.
1 1 3 Split timer mode
The TMOD (Timer Mode) Register.
8/13/2019 Introduction to 8051 Microcontroller
21/35
The TCON (Timer Control) RegisterD7 D0TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
TF1 TCON7 Timer 1 overflow flag. Set by hardware when timer/counter 1 overflows. Cleared by hardware as the processor vectors tothe interrupt service routine.
TR1 TCON6 Timer 1 run control bit. Set/cleared by the software to turn timer/counter 1 on/off.
TF0 TCON5 Timer 0 overflow flag. Set by hardware when timer/counter 0 overflows. Cleared by hardware as the processor vectors to theinterrupt service routine.
TR0 TCON4 Timer 0 run control bit. Set/cleared by the software to turn timer/counter 0 on/off.
IE1 TCON3 External interrupt 1 edge flag. Set by CPU when the external interrupt edge (H-to-L transition) is detected.
IT1 TCON2 Interrupt 1 type control bit. Set/cleared by software specify falling edge/low level triggered external interrupt
IE0 TCON1 External interrupt 0 edge flag. Set by CPU when the external interrupt edge (H-to-L transition) is detected.
IT0 TCON0 Interrupt 0 type control bit. Set/cleared by software specify falling edge/low level triggered external interrupt
8/13/2019 Introduction to 8051 Microcontroller
22/35
Timers and Counters Programs
8/13/2019 Introduction to 8051 Microcontroller
23/35
8/13/2019 Introduction to 8051 Microcontroller
24/35
8/13/2019 Introduction to 8051 Microcontroller
25/35
8/13/2019 Introduction to 8051 Microcontroller
26/35
Simplex Serial communication
System 1
Transmitter
System 2
Receiver
8/13/2019 Introduction to 8051 Microcontroller
27/35
Half Duplex Serial Communication
System 1
Transmitter
System 2
Receiver
Receiver Transmitter
8/13/2019 Introduction to 8051 Microcontroller
28/35
System 1
Transmitter
System 2
Receiver
Receiver Transmitter
Full Duplex Serial Communication
8/13/2019 Introduction to 8051 Microcontroller
29/35
8/13/2019 Introduction to 8051 Microcontroller
30/35
The SCON (Serial Control) RegisterSCON 7 SCON 6 SCON 5 SCON 4 SCON 3 SCON 2 SCON 1 SCON 0
SM0 SM1 SM2 REN TB8 RB8 TI RI
SM0 SCON7 Serial port mode specifier
SM1 SCON6 Serial port mode specifier
SM2 SCON5 Used for multiprocessor communication. (Make it 0.)
REN SCON4 Set/cleared by software to enable/disable reception.
TB8 SCON3 Not widely used (Make it 0)
RB8 SCON2 Not widely used (Make it 0)
TI SCON1 Transmit interrupt flag. Set by the hardware at the beginning of the stop bit in mode 1, must becleared by software.
RI SCON0 Receive interrupt flag. Set by the hardware halfway through the stop bit time in mode 1. Must becleared by software.
8/13/2019 Introduction to 8051 Microcontroller
31/35
SM0 SM10 0 Serial mode 0
0 1 Serial Mode 1, 8-bitdata, 1 stop bit, 1start bit
1 0 Serial Mode 2
1 1 Serial Mode 3
The SCON (Serial Control) Register
Serial Communication Modes of 8051
8/13/2019 Introduction to 8051 Microcontroller
32/35
Serial Communication Codes
8/13/2019 Introduction to 8051 Microcontroller
33/35
8/13/2019 Introduction to 8051 Microcontroller
34/35
External Interrupt Programming
8/13/2019 Introduction to 8051 Microcontroller
35/35
Recommended