Introduction To MCS-51
By
Charoen Vongchumyen
- Department of Computer Engineering
- Faculty of Engineering
- KMITLadkrabang
Introduction To MCS-51 By Charoen Vongchumyen Department of - - PowerPoint PPT Presentation
Introduction To MCS-51 By Charoen Vongchumyen Department of Computer Engineering Faculty of Engineering KMITLadkrabang 8051 Hardware Basic 8051 Hardware Basic Content Content Overview Overview Architechture
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Content Content
Overview
Architechture
Memory map
Register
Interrupt
Timer/Counter
Serial communication
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
What is 8051? What is 8051?
8051 is a famous microcontroller microcontroller series from Intel series from Intel
8 bit architecture and instruction set
Easy to use and learning
Widely use in many application
Suitable for Embedded and Controller application
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
8 Bit architecture
Up to 64KB of external code and data
4KB of internal code, EPROM (8751), ROM (8051), Flash (8951)
128 Bytes of internal RAM
32 bits inport inport/output port /output port
2 Timer/Counter
1 Serial communication (Full Duplex)
6 Sources of interrupt
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Port 0 Port 0
Data and Address bus / Port
Data and Address bus / Port Port 1 Port 1
Bidirectional
Bidirectional port port Port 2 Port 2
Address bus / Port
Address bus / Port Port 3 Port 3
Alternate Function / Port
Alternate Function / Port ALE ALE
Address latch enable
Address latch enable EA\ EA\
External memory access
External memory access RST RST
Reset
Reset PSEN\ PSEN\
Program strobe enable
Program strobe enable XTAL1,2 XTAL1,2
Crystal in/out
Crystal in/out
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Clock Clock
State 1 State 1 S1 S1 State 2 State 2 S2 S2 State 3 State 3 S3 S3 State 4 State 4 S4 S4 State 5 State 5 S5 S5 State 6 State 6 S6 S6 P1 P1 P2 P2 P1 P1 P2 P2 P1 P1 P2 P2 P1 P1 P2 P2 P1 P1 P2 P2 P1 P1 P2 P2
ALE ALE S1 S1 S2 S2 S3 S3 S4 S4 S5 S5 S6 S6
Fetch Fetch Opcode Opcode Fetch Fetch Opcode Opcode
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
(Con Con
t) )
T = ( C * 12 ) / CF T = ( C * 12 ) / CF
C = Machine Cycle of C = Machine Cycle of instrution instrution CF = Crystal Frequency CF = Crystal Frequency
Such as Such as ADD A,R1 ADD A,R1
XTAL 12 MHz XTAL 12 MHz
uSec XTAL 16 MHz XTAL 16 MHz
uSec
Note* Sometime we use XTAL 11.0592 Note* Sometime we use XTAL 11.0592
serial communication serial communication
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Code Memory Code Memory
External Code memory 0000 - 0000 - FFFFh FFFFh
Internal Code memory 0000 - 0FFFh 0000 - 0FFFh
Data Memory Data Memory
External Data memory 0000 - 0000 - FFFFh FFFFh
Internal Data memory
? ? Register Bank
Register Bank 00 - 1Fh 00 - 1Fh
? ? Bit addressable
Bit addressable 20h - 2Fh 20h - 2Fh
? ? Byte addressable
Byte addressable 30h - 7Fh 30h - 7Fh
? ? Special function register
Special function register 80h - 7Fh 80h - 7Fh
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
External code memory External code memory Internal code Internal code EA\ = 1 EA\ = 1 External code External code EA\ = 0 EA\ = 0 0000h 0FFFh 1000h FFFFh
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
External Data External Data Memory Memory Internal Data Internal Data RAM RAM Special Function Special Function Register Register Overlab Overlab Memory Memory
7Fh 80h FFh 0000 FFFFh
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Bank 0 Bank 0 Bank 1 Bank 1 Bank 2 Bank 2 Bank 3 Bank 3 Bit Addressable Bit Addressable RAM RAM Byte Addressable Byte Addressable RAM RAM
8h 8h 10h 10h 18h 18h 20h 20h 20h 20h
Special Function Special Function Register Register
80h 80h FFh FFh 7Fh 7Fh
Extend RAM Extend RAM Access by Access by Indirect addressing Indirect addressing
FFh FFh 80h 80h
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
R0 R0 R1 R1 R2 R2 R3 R3 R4 R4 R5 R5 R6 R6 R7 R7
Bank 0 Bank 0 Bank 1 Bank 1 Bank 2 Bank 2 Bank 3 Bank 3 08h - 0Fh 08h - 0Fh 10h - 17h 10h - 17h 18h - 1Fh 18h - 1Fh 00h - 07h 00h - 07h
Bank 0 -> RS0, 1 = 00 Bank 0 -> RS0, 1 = 00 Bank 1 -> RS0, 1 = 01 Bank 1 -> RS0, 1 = 01 Bank 2 -> RS0, 1 = 10 Bank 2 -> RS0, 1 = 10 Bank 3 -> RS0, 1 = 11 Bank 3 -> RS0, 1 = 11 All bank has same name of register All bank has same name of register R0 R0 R1 R1 R2 R2 R3 R3 R4 R4 R5 R5 R6 R6 R7 R7 R0 R0 R1 R1 R2 R2 R3 R3 R4 R4 R5 R5 R6 R6 R7 R7 R0 R0 R1 R1 R2 R2 R3 R3 R4 R4 R5 R5 R6 R6 R7 R7
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37 30 31 32 33 34 35 36 37 18 19 1A 1B 1C 1D 1E 1F 18 19 1A 1B 1C 1D 1E 1F 28 29 2A 2B 2C 2D 2E 2F 28 29 2A 2B 2C 2D 2E 2F 38 39 3A 3B 3C 3D 3E 3F 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 50 51 52 53 54 55 56 57 60 61 62 63 64 65 66 67 60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77 70 71 72 73 74 75 76 77 58 59 5A 5B 5C 5D 5E 5F 58 59 5A 5B 5C 5D 5E 5F 68 69 6A 6B 66 6D 6E 6F 68 69 6A 6B 66 6D 6E 6F 78 79 7A 7B 7C 7D 7E 7F 78 79 7A 7B 7C 7D 7E 7F 21h 21h 23h 23h 25h 25h 27h 27h 29h 29h 2Bh 2Bh 2Dh 2Dh 2Fh 2Fh 20h 20h 22h 22h 24h 24h 26h 26h 28h 28h 2Ah 2Ah 2Ch 2Ch 2Eh 2Eh
Bit addressable Bit addressable Byte addressable Byte addressable
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
( ) In 8052 Only
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
(con con
t) )
P0 (Port 0, Address 80h, Bit-Addressable)
P1 (Port 1, Address 90h, Bit-Addressable)
P2 (Port 2, Address A0h, Bit-Addressable)
P3 (Port 3, Address B0h, Bit-Addressable)
ACC (Accumulator, Addresses E0h, Bit-Addressable)
B (B Register, Addresses F0h, Bit-Addressable)
SP (Stack Pointer, Address 81h)
DPL/DPH (Data Pointer Low/High, Addresses 82h/83h)
TL0/TH0 (Timer 0 Low/High, Addresses 8Ah/8Bh)
TL1/TH1 (Timer 1 Low/High, Addresses 8Ch/8Dh)
SBUF (Serial Control, Addresses 99h)
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
(con con
t) )
PSW (Program Status Word, Addresses D0h, Bit-Addressable)
PCON (Power Control, Addresses 87h)
TCON (Timer Control, Addresses 88h, Bit-Addressable)
TMOD (Timer Mode, Addresses 89h)
SCON (Serial Control, Addresses 98h, Bit-Addressable)
IE (Interrupt Enable, Addresses A8h)
IP (Interrupt Priority, Addresses B8h, Bit-Addressable)
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Hardware Basic 8051 Hardware Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Register and memory
Addressing mode
Instructionset
Arithmetic
Logical
Boolean
Data transfer
Program control flow
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Register Register
R0
R7
R7
A (Accumulator)
B
DPTR (DPH, DPL)
Memory Memory
General purpose register R0 - R7 (00h - 1Fh)
Bit addressable RAM (20h - 2Fh)
General purpose memory (30 - 7Fh)
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Immediate addressing mode
MOV MOV A,#20h A,#20h
Direct addressing mode
MOV MOV A,20h A,20h
Indirect addressing mode MOV
MOV A,@R0 A,@R0
Register addressing mode MOV
MOV A,R0 A,R0
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Arithmetic instruction set
Logical instruction set
Boolean instruction set
Data transfer instruction set
Program flow control (jump instruction set)
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Byte = register or one byte memory Byte = register or one byte memory
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Accessing internal data memory x, x,xx xx
Accessing external data memory x, x,xx xx
Lookup table read instruction x, x,xx xx
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Accessing internal data memory Accessing internal data memory
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Accessing external data memory Accessing external data memory
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Table Lookup read instruction Table Lookup read instruction
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Uncondition jump jump
jmp jmp, call, ret , call, ret
Condition jump
jz jz, , jnz jnz, , djnz djnz, , cjne cjne
Bit condition jump
jc jc, , jnc jnc, , jb jb, , jnb jnb, , jbc jbc
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Uncondition Uncondition jump jump
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Condition jump Condition jump
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Software Basic 8051 Software Basic
Bit condition jump Bit condition jump
Tong+ Tong+ 02/18/2000 02/18/2000
Defination & Preprocessor & Preprocessor
Lable & Comment & Comment
End statement & Predefine
Assembly
8051 Assembler (SXA51) 8051 Assembler (SXA51)
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Assembler (SXA51) 8051 Assembler (SXA51)
EQU use to define variable or
use to define variable or contant contant value value Counter Counter EQU EQU 20h 20h
Setting Setting EQU EQU 00011010b -> define setting as 1Ah 00011010b -> define setting as 1Ah mov mov
mov mov
DW, DB DB use to define constant value
use to define constant value DB DB
Hello
DW DW
mov mov mov mov
ll get 48h ( get 48h (
H
H
)
)
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Assembler (SXA51) 8051 Assembler (SXA51)
Use
:
to make lable lable to to jmp jmp or call
Use
;
to make comment in code Main: Main: mov mov r0,#05h r0,#05h ;load r0 with 5 ;load r0 with 5 djnz djnz r0,$ r0,$ ;decrement r0 and ;decrement r0 and jmp jmp if = 0 if = 0 cpl cpl P1.4 P1.4 ;complement P1.4 ;complement P1.4 jmp jmp Main Main ;always jump to main ;always jump to main
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Assembler (SXA51) 8051 Assembler (SXA51)
Use END at end of program to indicate end for assembler
Predefine Register Bank Register Bank
. R7 Register Register
SFR SFR
Flag Flag
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Basic Code 8051 Basic Code
Delay Loop
Delay Loop
Delay: Delay: push push ;save register r0 ;save register r0 push push 1 1 ;save register r1 ;save register r1 mov mov r0,#00h r0,#00h ;r0 = 00 ;r0 = 00 Loop: Loop: mov mov r1,#20h r1,#20h ;r1 = 20h ;r1 = 20h djnz djnz r1,$ r1,$ ;loop r1 32 times ;loop r1 32 times djnz djnz r0,Loop r0,Loop ;loop r0 256 times ;loop r0 256 times pop pop 1 1 ;restore register r1 ;restore register r1 pop pop ;restore register r0 ;restore register r0 ret ret ;return ;return
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Basic Code 8051 Basic Code
Delay Loop Cycle Time
Delay Loop Cycle Time
Delay: Delay: push push ;2 ;2 push push 1 1 ;2 ;2 mov mov r0,#00h r0,#00h ;1 ;1 Loop: Loop: mov mov r1,#20h r1,#20h ;1 X 256 = 256 ;1 X 256 = 256 djnz djnz r1,$ r1,$ ;2 X 32 X 256 = 16,384 ;2 X 32 X 256 = 16,384 djnz djnz r0,Loop r0,Loop ;2 X 256 = 512 ;2 X 256 = 512 pop pop 1 1 ;2 ;2 pop pop ;2 ;2 ret ret ;2 ;2 Total time = 2 + 2 + 1 + 256 + 16,384 + 512 + 2 + 2 + 2 = 17,163 Total time = 2 + 2 + 1 + 256 + 16,384 + 512 + 2 + 2 + 2 = 17,163 uS uS
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Basic Code 8051 Basic Code
Delay: Delay: push push push push 1 1 mov mov r0,#00h r0,#00h Loop: Loop: mov mov r1,#20h r1,#20h djnz djnz r1,$ r1,$ djnz djnz r0,Loop r0,Loop pop pop 1 1 pop pop ret ret
Pulse generator Pulse generator
Main: Main: cpl cpl p1.0 p1.0 ;toggle p1.0 ;toggle p1.0 call call delay delay ;delay ;delay jmp jmp Main Main ;infinite loop ;infinite loop
Duty cycle = 50% Duty cycle = 50% Pulse width = 17,163 Pulse width = 17,163 uS uS Frequency = 58.26 Hz Frequency = 58.26 Hz Cystals Cystals = 12 MHz = 12 MHz
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Basic Code 8051 Basic Code
Pulse generator use timer Pulse generator use timer
ORG ORG 0000H 0000H jmp jmp Main Main ORG ORG 000BH 000BH jmp jmp T0_ISR T0_ISR Main: Main: setb setb EA EA setb setb ET0 ET0 mov mov TMOD,#00000010 TMOD,#00000010 mov mov TH,#20h TH,#20h mov mov TL,#20h TL,#20h setb setb TR0 TR0 jmp jmp $ $
T0_ISR:
T0_ISR: push push psw psw cpl cpl p1.0 p1.0 pop pop psw psw ret ret
Duty cycle = 50% Duty cycle = 50% Pulse width = 32 Pulse width = 32 uS uS Frequency = 31250 Hz Frequency = 31250 Hz Cystals Cystals = 12 MHz = 12 MHz
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Basic Code 8051 Basic Code
External Interrupt External Interrupt
ORG ORG 0000H 0000H jmp jmp Main Main ORG ORG 0003H 0003H jmp jmp INT0_ISR INT0_ISR Main: Main: setb setb EA EA setb setb EX0 EX0 setb setb IT0 IT0 mov mov P0,#0 P0,#0 jmp jmp $ $ INT0_ISR: INT0_ISR: push push psw psw inc inc P0 P0 pop pop psw psw reti reti Count pulse on INT0 pin (external Count pulse on INT0 pin (external Interrupt 0) and display counter on Interrupt 0) and display counter on
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
C1, C2 20 - 40 C1, C2 20 - 40 pF pF
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
Power On Reset Power On Reset
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
External Program Memory Read Cycle External Program Memory Read Cycle
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
Exteranl Exteranl Data Memory Read Cycle Data Memory Read Cycle
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
Exteranl Exteranl Data Memory Write Cycle Data Memory Write Cycle
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
8051 8051 P1-P3 P1-P3 P0 P0 VCC VCC 10K 10K
Input/Output Input/Output
Mov Mov a,P0 a,P0 Mov Mov P1,a P1,a
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
8051 8051 P1-P3 P1-P3 P0 P0 VCC VCC 10K 10K VCC VCC LED LED 300 300
Input with switch, Output with LED Input with switch, Output with LED Mov Mov a,P0 a,P0 Mov Mov P1,a P1,a Mov Mov P1,#00 P1,#00 Mov Mov P1,# P1,#FFh FFh
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
8051 8051 P1.0, Row0 P1.0, Row0 P1.1, Row1 P1.1, Row1 P1.2, Row2 P1.2, Row2 P1.3, Col0 P1.3, Col0 P1.4, Col1 P1.4, Col1 P1.5, Col2 P1.5, Col2
Matrix keyboard by scanning Matrix keyboard by scanning techinque techinque
Mov Mov P1,# P1,#FEh FEh Jnb Jnb P1.3,Key1 P1.3,Key1 Jnb Jnb P1.4,Key2 P1.4,Key2 Jnb Jnb P1.5,Key3 P1.5,Key3 Mov Mov P1,# P1,#FDh FDh Jnb Jnb P1.3,Key4 P1.3,Key4 Jnb Jnb P1.4,Key5 P1.4,Key5 Jnb Jnb P1.5,Key6 P1.5,Key6 Mov Mov P1,# P1,#FBh FBh Jnb Jnb P1.3,Key7 P1.3,Key7 Jnb Jnb P1.4,Key8 P1.4,Key8 Jnb Jnb P1.5,Key9 P1.5,Key9 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
8051 8051 8 8 P1 P1 P2.0 P2.0 P2.1 P2.1 P2.2 P2.2 P2.3 P2.3 7-Segment (common Anode) 7-Segment (common Anode)
7-Segment Display by Scan 7-Segment Display by Scan Tecnique Tecnique
Loop: Loop: Mov Mov P1,#Num1 P1,#Num1 Mov Mov P2,#00h P2,#00h Call Delay Call Delay Mov Mov P1,#Num2 P1,#Num2 Mov Mov P2,#01h P2,#01h Call Delay Call Delay Mov Mov P1,#Num2 P1,#Num2 Mov Mov P2,#01h P2,#01h Call Delay Call Delay Mov Mov P1,#Num2 P1,#Num2 Mov Mov P2,#01h P2,#01h Call Delay Call Delay Jmp Jmp Loop Loop
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
8051 8051 TX TX RX RX GND GND PC PC Use null modem connector Use null modem connector And XTAL = 11.0592MHz And XTAL = 11.0592MHz
Serial Communication Via RS-232C Port Serial Communication Via RS-232C Port
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
Serial Communication Via RS-232C Port Serial Communication Via RS-232C Port
ORG ORG 0000H 0000H Jmp Jmp Start Start ORG ORG 0023H 0023H Jmp Jmp Serial_ISR Serial_ISR ORG ORG 0040H 0040H Start: Start: Clr Clr PCON.7 ;clear SMOD PCON.7 ;clear SMOD Mov Mov SCON,#52h ;set mode SCON,#52h ;set mode Mov Mov TMOD,#20h;timer mode 2 TMOD,#20h;timer mode 2 Mov Mov TH1,# TH1,#FDh FDh ;set reload value ;set reload value Setb Setb EA EA ;enable all ;enable all Int Int. . Setb Setb REN REN ;enable Receive ;enable Receive Setb Setb TR1 TR1 ;start Timer ;start Timer Mov Mov DPTR,#0000h DPTR,#0000h
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
Serial Communication Via RS-232C Port Serial Communication Via RS-232C Port
Serial_ISR: Serial_ISR: Push Push PSW PSW Push Push Acc Acc Jnb Jnb RI,TX_ RI,TX_Evnt Evnt Mov Mov A,SBUF A,SBUF jnb jnb TI,$ TI,$ Mov Mov SBUF,A SBUF,A Clr Clr TI TI Jmp Jmp End_ISR End_ISR TX_ TX_Evnt Evnt: : Inc Inc DPTR DPTR End_ISR: End_ISR: Pop Pop Acc Acc Pop Pop PSW PSW Reti Reti
Tong+ Tong+ 02/18/2000 02/18/2000 8051 Interface 8051 Interface
Baud Rate Baud Rate
Bubble Sort Bubble Sort 0000h = Counter, 0001h - 00xxh = External Data (< 256 bytes)
0000h = Counter, 0001h - 00xxh = External Data (< 256 bytes) Start Start N = Data[0] N = Data[0] Data = Data[1-N] Data = Data[1-N] For I = 1 to N-1 For I = 1 to N-1 For J = 1 to I-1 For J = 1 to I-1 If I > J then If I > J then Swap Swap End End