Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Introduction To 8051 Microcontroller

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 35

1. Introduction 1. 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).

4. Timer/counter. 1. Basic timer operations 2. 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.

Definition of microcontroller.

CPU General Purpose Microprocessor RAM ROM I/O Ports Timers Serial COM Port

General Purpose Microprocessor System

CPU

RAM

ROM

I/O Ports

Timer

Serial COM Port

Microcontroller

The 8051 Microcontroller Comparison with other Intel microcontrollers


Feature ROM (on-chip program space in bytes) 8051 4K 8052 8K 8031 0K

RAM (Bytes) Timers I/O Pins Serial Port Interrupt Sources

128 2 32 1 6

256 3 32 1 8

128 2 32 1 6

Part Number

ROM

RAM

I/O Pins

Timer

Interrupt

Vcc

Packaging

AT89C51 AT89LV51 AT89C1051

4K 4K 1K

128 128 64

32 32 15

2 2 1

6 6 3

5V 3V 3V

40 40 20

AT89C2051

2K

128

15

3V

20

AT89C52 AT89LV52

8K 8K

128 128

32 32

3 3

8 8

5V 3V

40 40

Note: C Indicates the CMOS

Port 0 Port 1 Port 2 Port 3

Interrupt Vector Table for 8051 Interrupt Reset External hardware interrupt 0 (INT0) ROM location (HEX) 0000 0003 Flag Clearing Auto Auto

Timer 0 interrupt

000B

Auto

External hardware interrupt 1 (INT1)

0013

Auto

Timer 1 interrupt Serial COM interrupt (RI and TI)

001B 0023

Auto Programmer clears it.

IE (Interrupt Enabler) Register


D7 EA ---ET2 ES ET1 EX1 ET0 EX0 D0

EA

IE7

Disable all interrupts. If EA=0, no interrupt is acknowledged. If EA=1 each interrupt source is individually enabled or disabled by setting or clearing its enable bit. Not Implemented Enable or disable Timer 2 overflow or capture interrupt (8052 only). Enables or disable serial port interrupt Enables or disable Timer 1 overflow interrupt Enable or disable external interrupt 1 Enables or disable Timer 0 overflow interrupt Enable or disable external interrupt 0

---ET2

IE6 IE5

ES ET1 EX1 ET0 EX0

IE4 IE3 IE2 IE1 IE0

MOV Instruction mov destination,source; ADD Instruction add A,sourc; add source operand to the accumulator and 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)

Unconditional Jumps LJMP(Long Jump) It is a 3byte instruction 1st byte is used for opcode the remaining 2 bytes are used for address. SJMP(Short Jump) It is a 2 byte instruction 1st byte is used for opcode the remaining 1 byte is used for address. CALL Instructions LCALL(Long Call) It is also a 3 byte instruction. ACALL(Absolute Call) It is a Two byte instruction used to call a function outside the function being executed.

Role of Stack Pointer for Call Instruction

PUSH and POP Instructions

NOP(No operation) Instruction

Include header file #include<reg51.h> The Main Function Void main(void){ } Decision Making Instructions while loop while(condition) //the program remains in the loop while the condition is true for loop for(initialization;condition;increment/decrement)

The if else statements if(condition 1) {} else if(condition 2) {} else {}

Some Basic C programs

Timer 0 and Timer 1


D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

D0-D7 are known as TLx D8-D15 are known as THx

The TMOD (Timer Mode) Register


(MSB) GATE (LSB) C/T M1 Timer 1 M0 GATE C/T M1 Timer 0 M0

GATE gating control when set. The timer/counter is enabled only when the INTx pin is high and the TRx pin is set. When cleared, the timer is enabled whenever the TRx control bit is set. C/T Timer or Counter selected cleared for timer operation (input from internal system clock). Set for counter operation (input from Tx input pin). M1 Mode bit 1 M0 Mode bit 0

The TMOD (Timer Mode) Register.


M1 0 M0 0 Mode 0 Operation Mode 13-bit timer mode 8-bit timer/counter THx with TLx as 5 bit presaler 16-bit timer mode 16-bit timer/counter THx and TLx are cascaded; there is no prescaler 8-bit auto reload 8 bit auto reload timer/counter;THx holds the value that is to be reloaded into TLx each time it overflows. Split timer mode

The TCON (Timer Control) Register


D7 TF1 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 TCON7 TCON6 TCON5 TCON4 TCON3 TCON2 TCON1 TCON0 D0 TR1 TF0 TR0 IE1 IT1 IE0 IT0

Timer 1 overflow flag. Set by hardware when timer/counter 1 overflows. Cleared by hardware as the processor vectors to the interrupt service routine. Timer 1 run control bit. Set/cleared by the software to turn timer/counter 1 on/off. Timer 0 overflow flag. Set by hardware when timer/counter 0 overflows. Cleared by hardware as the processor vectors to the interrupt service routine. Timer 0 run control bit. Set/cleared by the software to turn timer/counter 0 on/off. External interrupt 1 edge flag. Set by CPU when the external interrupt edge (H-to-L transition) is detected. Interrupt 1 type control bit. Set/cleared by software specify falling edge/low level triggered external interrupt External interrupt 0 edge flag. Set by CPU when the external interrupt edge (H-to-L transition) is detected. Interrupt 0 type control bit. Set/cleared by software specify falling edge/low level triggered external interrupt

Timers and Counters Programs

LCD and Keypad Interfacing Programs

Simplex Serial communication System 1 System 2

Transmitter

Receiver

Half Duplex Serial Communication


System 1 Transmitter Receiver System 2 Receiver Transmitter

Full Duplex Serial Communication System 1 Transmitter Receiver System 2 Receiver Transmitter

The SBUF Serial Buffer Register

The SCON (Serial Control) Register


SCON 7 SM0 SCON 6 SM1 SCON 5 SM2 SCON 4 REN SCON 3 TB8 SCON 2 RB8 SCON 1 TI SCON 0 RI

SM0 SM1 SM2 REN TB8 RB8

SCON7 SCON6 SCON5 SCON4 SCON3 SCON2

Serial port mode specifier Serial port mode specifier Used for multiprocessor communication. (Make it 0.) Set/cleared by software to enable/disable reception. Not widely used (Make it 0) Not widely used (Make it 0) Transmit interrupt flag. Set by the hardware at the beginning of the stop bit in mode 1, must be

TI SCON1 cleared by software.

RI SCON0 cleared by software.

Receive interrupt flag. Set by the hardware halfway through the stop bit time in mode 1. Must be

The SCON (Serial Control) Register


Serial Communication Modes of 8051 SM0 0 0 SM1 0 1 Serial mode 0 Serial Mode 1, 8-bit data, 1 stop bit, 1 start bit Serial Mode 2 Serial Mode 3

1 1

0 1

Serial Communication Codes

External Interrupt Programming

You might also like