autumn 2013c.-s. shieh, ec, kuas, taiwan1 the 8051 family microcontroller chin-shiuh shieh csshieh...
TRANSCRIPT
![Page 1: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/1.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 1
The 8051 Family Microcontroller
Chin-Shiuh Shiehhttp://bit.kuas.edu.tw/~csshieh
Department of Electronic EngineeringNational Kaohsiung University of Applied Sciences, Taiwan
![Page 2: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/2.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 2
Microcontrollers
• Microprocessors, such as 8086 family, have only CCU and ALU in them. External RAM, ROM, and I/O are required.
• Microcontrollers, such as 8051 family, encompass CCU, ALU, RAM, ROM, and I/O in a single chip, also called single-chip.
• Microcontrollers have limited computational power, but their low-cost make them prevalent in consumer products and small-scale control systems.
![Page 3: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/3.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 3
Microcontrollers (cont)
• We adopt 8051 family microcontroller in our class for its general structure and manageable system complexity.
• A large number of manufactures offer different variants of 8051 family microcontroller.
![Page 4: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/4.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 4
ATMEL AT89C51
• AT89C51 / AT89S51 is a popular member of the 8051 family microcontroller from ATMEL.
![Page 5: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/5.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 5
Features
• 8-bit CPU optimized for control applications
• 128 bytes of on-chip Data RAM, 4K bytes of on-chip Program Memory (Flash Memory/ROM)
• 64K Program Memory address space, 64K Data Memory address space
![Page 6: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/6.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 6
Features (cont)
• 32 bidirectional and individually addressable I/O lines
• Two 16-bit timer/counters
• Full duplex programmable UART
• 6-source/5-vector interrupt structure with two priority levels
![Page 7: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/7.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 7
Pin Configurations
![Page 8: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/8.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 8
Pin Configurations (cont)
• Vcc, GND: supply voltage (5V), ground
• XTAL1, XTAL2: crystal connections for system clock
• RST: reset input
• EA: External Access, EA=5V to enable internal ROM.
![Page 9: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/9.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 9
Pin Configurations (cont)• Basic hardware configuration
Power-On self reset
![Page 10: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/10.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 10
Pin Configurations (cont)
• P0.0~P0.7: Port 0, bidirectional bit-addressable with open drain
• P1.0~P1.7: Port 1, bidirectional bit-addressable with internal pull-ups
• P2.0~P2.7: Port 2, bidirectional bit-addressable with internal pull-ups
• P3.0~P3.7: Port 3, bidirectional bit-addressable with internal pull-ups
![Page 11: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/11.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 11
Pin Configurations (cont)
![Page 12: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/12.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 12
Pin Configurations (cont)
• MOV P2,#0Ah ;Copy 0A16 to P2
• MOV P2,#08 ;Copy 08 to P2
• MOV P2,#00110100b;Copy 3416 to P2
• SETB P2.0 ;Set P2.0 to “1”• CLR P2.1 ;Clear P2.1 to “0”• MOV A,P1 ;Copy P1 to A• JB P3.2,LOOP ;Jump to LOOP if P3.1 is “1”
![Page 13: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/13.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 13
Pin Configurations (cont)
• P0 is open-drain– SETBP0.0;P0.0 = high impedance – CLR P0.1;P0.1 = 0V
• P1, P2, and P3 have internal pull-ups– SETBP1.0;P1.0 = 5V– CLR P1.1;P1.1 = 0V
![Page 14: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/14.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 14
• "MOV P2,A" will turn on LEDs on P2 whose corresponding bits in A is "0". Notice that I/O port source current is limited.
• If an I/O port is used for input, it's output latch must set to "1". For example, "MOV P1,#0FFh", then "MOV A,P1" will read P1 status into A.
• MOV P1,#0FFh• MOV A,P1
![Page 15: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/15.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 15
• P0 is open-drain. Pull-up resistor is required. "SETB P0.0" will turn on the relay and "CLR P0.0" will turn it off.
• For button applications, de-bounce circuitry and code is required (5RC=10mS~20mS).
![Page 16: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/16.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 16
ORG 0000hLOOP: SETB P2.0
LCALL DELAYCLR P2.0LCALL DELAYLJMP LOOP
DELAY:MOV R0,#0FFh
L1: MOV R1,#0FFhL2: DJNZ R1,L2 ; Decrease and jump if not zero
DJNZ R0,L1RETEND
![Page 17: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/17.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 17
for(R0=255;R0>=0;R0--)
for(R1=255;R1>=0;R1--)
{
}
![Page 18: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/18.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 18
• For button applications, de-bounce circuitry and code is required (5RC=10mS~20mS).
![Page 19: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/19.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 19
![Page 20: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/20.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 20
Check Button
• CHECK_BUTTON:
JB P3.2,CBRET
; Task for button pressed
WAIT_BUTTON_RELEASE:
JNB P3.2,WAIT_BUTTON_RELEASE
CBRET:
![Page 21: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/21.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 21
![Page 22: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/22.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 22
Wait Button
• Wait Button
WAIT_BUTTON:
JB P3.2,WAIT_BUTTON
WAIT_RELEASE:
JNB P3.2,WAIT_RELEASE RET
![Page 23: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/23.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 23
Pin Configurations
![Page 24: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/24.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 24
Pin Configurations (cont)
• Alternative Functions of Port 3
![Page 25: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/25.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 25
• Polling I/O• Interrupt-driven I/O
– Interrupt Service Subroutine
![Page 26: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/26.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 26
Pin Configurations (cont)
• PSEN: Program Store Enable, read strobe for external program memory
• ALE: Address Latch Enable, for multiplexing AD0~AD7
• A8~A15(P2.0~P2.7): high-byte address bus for external addressing
• AD0~AD7(P0.0~P0.7): multiplexed low-byte address bus and data bus for external addressing
![Page 27: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/27.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 27
Memory Organization
• Separation of program addressing space and data addressing space.
![Page 28: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/28.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 28
Program Memory
![Page 29: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/29.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 29
Data Memory
![Page 30: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/30.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 30
Internal Data Memory
• MOV 12h,#05h• MOV A,3Ch• MOV 0E0h,3Ch; MOV A,3Ch• MOV 90h,#0Fh; MOV P1,#0Fh
• MOV A,R0
• MOV 20h,#05h• SETB 03h• MOV A,20h; A==0D
![Page 31: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/31.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 31
Special Function Register Map
![Page 32: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/32.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 32
• MOV SBUF,#’H’ ;== MOV SBUF,#48h
• MOV SBUF,#’e’
![Page 33: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/33.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 33
Special Function Register Map (cont)
![Page 34: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/34.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 34
Special Function Register Map (cont)
• MOV P2,#55h == MOV 0A0h,#55h• SETB P1.0• CLR P1.0
• SETB SBUF.1;Incorrect!
![Page 35: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/35.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 35
Special Function Register Map (cont)
• MOV SBUF,A = MOV 99h,0E0h • MOV 99h,A
![Page 36: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/36.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 36
Special Function Registers
• A, (ACC): Accumulator – MOV A,#02h– ADD A,#03h ; ADD B,R0 incorrect!– B: B Register – MUL AB
• MOV A,#03h• MOV R0,#02h• MUL AB ; MUL AR0 Incorrect!
– DIV AB• SP: Stack Pointer • DPTR(DPH,DPL): Data Pointer
– MOV DPTR,#4000h– MOVX A,@DPTR– MOVX @DPTR,A
![Page 37: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/37.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 37
Special Function Registers (cont)
• P0: Port 0
• P1: Port 1
• P2: Port 2
• P3: Port 3
![Page 38: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/38.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 38
Special Function Registers (cont)
• TH0: Timer/Counter 0 High Byte
• TL0: Timer/Counter 0 Low Byte
• TH1: Timer/Counter 1 High Byte
• TL1: Timer/Counter 1 Low Byte
• SBUF: Serial Data Buffer – MOV SBUF,A– MOV SBUF,#’H’;
![Page 39: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/39.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 39
Special Function Registers (cont)
• PSW: Program Status Word • PCON: Power Control Register • IE: Interrupt Enable Register • IP: Interrupt Priority Register • TCON: Timer/Counter Control Register • TMOD: Timer/Counter Mode Control
Register • SCON: Serial Port Control Register
![Page 40: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/40.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 40
PSW: Program Status Word
![Page 41: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/41.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 41
PSW: Program Status Word (cont)
• SETB RS1• CLR RS0• MOV R0,#5Fh
![Page 42: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/42.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 42
PCON: Power Control Register
![Page 43: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/43.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 43
PCON: Power Control Register (cont)
• SETB SMOD ; Incorrect• MOV A,PCON• ORL A,#10000000b• MOV PCON,A
• CLR GF0 ; Incorrect• MOV A,PCON• ANL A,#11111011b• MOV PCON,A
![Page 44: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/44.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 44
IE: Interrupt Enable Register
; Enable External Interrupt 0 with high prioritySETB EX0SETB EASETB PX0
![Page 45: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/45.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 45
IP: Interrupt Priority Register
![Page 46: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/46.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 46
TCON: Timer/Counter Control Register
![Page 47: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/47.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 47
TMOD: Timer/Counter Mode Control Register
![Page 48: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/48.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 48
TMOD: Timer/Counter Mode Control Register (cont)
TH1 TL1
FD FD
FF• 8-bit Auto-reload mode
• MOV SBUF,A
• MOV SBUF,B
![Page 49: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/49.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 49
SCON: Serial Port Control Register
![Page 50: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/50.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 50
• MOV SBUF,A• MOV A,SBUF
• MOV SBUF,#’H’• MOV SBUF,#’e’• MOV SBUF,#’l’• MOV SBUF,#’l’• MOV SBUF,#’o’
![Page 51: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/51.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 51
PC: Program Counter
• PC: Program Counter – 16-bit register– Instruction fetching– Auto increase
![Page 52: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/52.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 52
Interrupt Mechanism
![Page 53: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/53.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 53
Pin Configurations
![Page 54: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/54.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 54
![Page 55: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/55.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 55
Pin Configurations
![Page 56: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/56.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 56
Interrupt Mechanism (cont)
![Page 57: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/57.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 57
Interrupt Mechanism (cont)
![Page 58: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/58.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 58
Addressing Mode
• Immediate: MOV A,#20h
• Register: MOV A,R0
• Direct: MOV A,30h
• Indirect: MOV A,@R0
• External Data Indirect: MOVX A,@DPTR
• Code Indirect: MOVC A,@A+DPTR
![Page 59: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/59.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 59
• MOV DPTR,#0A05Ch
• MOVX A,@DPTR
• MOVX @DPTR,A
![Page 60: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/60.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 60
• MOV A,#00h
• ADD A,00h
• ADD A,01h
• ADD A,02h
• …
• ADD A,09h
![Page 61: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/61.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 61
• int x[10];• int sum;
• sum=0;• sum=sum+x[0];• sum=sum+x[1];• sum=sum+x[2];• …• sum=sum+x[9];
![Page 62: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/62.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 62
• int x[10];• int sum;• for(i=0;i<10;i++)
– sum=sum+x[i];
![Page 63: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/63.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 63
MOV A,00h
MOV R0,#09h
LOOP:
ADD A,@R0
DJNZ R0,LOOP
![Page 64: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/64.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 64
• int x[10],sum;
• sum=sum+x[0];
• sum=sum+x[1];
• sum=sum+x[2];
• …
• sum=sum+x[9];
![Page 65: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/65.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 65
• int x[10],sum,i;
• for(i=0i<10;i++)– sum=sum+x[i];
![Page 66: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/66.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 66
Instruction Set
• ASEM51 v1.3– Assembler Directives
• ORG• EQU
• Emulator 8051 V1.0 or JSIM-51
![Page 67: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/67.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 67
• ADD vs. ADDC
![Page 68: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/68.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 68
• JB bit, rel
• JNB bit, rel
• JC rel
• JNC rel
• JZ rel ; Jump if A==0
• JNZ rel
![Page 69: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/69.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 69
• ADD B,R0
• ANL A,#00001111b
• MOV A,PCON
• ANL A,#01111111b
• MOV PCON,A
![Page 70: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/70.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 70
• MOV A,00h
• ADD A,04h
• MOV 08h,A
• MOV A,01h
• ADDC A,05h
• MOV 09h,A
![Page 71: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/71.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 71
• MOV R0,#10
• LOOP:
• …
• …
• …
• DEC R0
• CJNE R0,#00, LOOP
![Page 72: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/72.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 72
• JB bit, rel • JNB bit, rel
• JC rel• JNC rel
• JZ rel • JNZ rel
• JB bit, rel vs. JBC bit, rel
![Page 73: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/73.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 73
?
• SP
• DA A
• JMP @A+DPTR
• POP direct
• PUSH direct
• XCHD A, @Ri
![Page 74: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/74.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 74
• RL A
• RLC A
![Page 75: Autumn 2013C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh csshieh Department of Electronic Engineering](https://reader036.vdocument.in/reader036/viewer/2022062320/56649c745503460f949280ae/html5/thumbnails/75.jpg)
Autumn 2013 C.-S. Shieh, EC, KUAS, Taiwan 75