THE 8051 MICROCONTROLLER ARCHITECTURE, PROGRAMMING AND APPLICATIONS
1 Introduction 1 Chapter Objectives 1 11 Introduction 1 12 Microprocessor 2 121 Microprocessor-Based System 2 13 Microcontroller 3 131 General Architecture 3 132 Software Protection in Microcontrollers 4 133 Brief History of Intel Microcontrollers 4 14 MCS-51 Family 4 141 Princeton and Harvard Architectures 5 142 Comparison Between 8085 and MCS-51 5 15 Power Management 7 16 Microcontroller Packaging 8 161 Plastic Dual-Inline Package (PDIP) 8 162 Quad Flat Package (QFP) 8 163 Plastic-Leaded Chip Carrier (PLCC) 8 164 Plastic Quad Flat Pack (PQFP) 8 165 Thin Quad Flat Pack (TQFP) 9 17 Future Trend 9 Summary 9 Points to Remember 9 Review Questions 10 Evaluate Yourself 10 Search for Answers 10 Think and Solve 11 2 General Architecture 13 Chapter Objectives 13 21 External Features 13 22 Pins and Signals 14 23 Internal Architecture 16 24 Program Memory Organization 16 241 Pipeline Architecture 17 242 Program Lock Bits 17 25 Data Memory Organization 17 251 Register Banks 18 252 Bit-Addressable Area 20 253 Scratch-Pad Area 21 26 System Clock 21 27 Reset 22 Summary 24 Points to Remember 24 Review Questions 24 Evaluate Yourself 24 Search for Answers 25 Think and Solve 25 3 I/O Ports and Special Function Registers 27 Chapter Objectives 27 31 Introduction 27 32 SFR Map 27 33 SFR Functions 28 34 Processor Status Word 29 341 Comparison with 8085 Flags 30 35 Accumulator (Register A) 30 36 Register B 31 37 Stack Pointer 31 38 Port Registers (P0, P1, P2 and P3) 31 381 Comparing 8255 PPI with MCS-51 Ports 32 382 Architecture of MCS-51 Ports 32 383 DC Characteristics of MCS-51 Ports 35 39 Power Management (PCON) 36 310 Solved Examples 37 Summary 37 Points to Remember 38 Review Questions 38 Evaluate Yourself 38 Search for Answers 38 Think and Solve 38 4 Addressing Modes and Data Move Operations 41 Chapter Objectives 41 41 Instructions and Instruction Groups of MCS-51 41 42 Addressing Modes 42 421 Immediate Addressing Mode 43 422 Direct Addressing Mode 44 423 Register Direct Addressing Mode 44 424 Register Indirect Addressing Mode 45 43 Data Transfer Mnemonics 46 44 Forms of MOV Instruction 46 441 16-Bit Data Load 47 442 8-Bit Data Load 48 443 Precautions in Hexadecimal Representations 48 444 Format of MOV Instruction 48 445 Comparison with 8085 Mnemonics 48 446 Operand Expressions 49 447 Restrictions in Addressing Modes 49 448 Reading from I/O Ports 50 45 Solved Examples 50 Summary 53 Points to Remember 53 Review Questions 53 Evaluate Yourself 53 Search for Answers 54 Think and Solve 54 5 Arithmetic Operations 57 Chapter Objectives 57 51 Introduction 57 52 ADD Instruction 58 53 ADDC Instruction 60 54 SUBB Instruction 62 55 INC Instruction 63 56 DEC Instruction 64 Summary 64 Points to Remember 65 Review Questions 65 Evaluate Yourself 65 Search for Answers 65 Think and Solve 66 6 Program Branching 67 Chapter Objectives 67 61 Program Branching Instructions 67 62 Unconditional Jumps 68 621 LJMP Instruction 68 622 AJMP Instruction 69 623 SJMP Instruction 70 624 Application of AJMP and SJMP 71 63 Conditional Branching 72 631 JZ Instruction 72 632 JNZ Instruction 73 633 CJNE Instruction 74 634 DJNZ Instruction 75 635 Labels in Program Listing 76 64 NOP Instruction 77 65 Solved Examples 77 Summary 78 Points to Remember 78 Review Questions 79 Evaluate Yourself 79 Search for Answers 79 Think and Solve 80 7 Programming Examples-I 81 Chapter Objectives 81 71 Introduction 81 72 Copy Block 81 73 Shift Block 83 74 Count No of Nulls 84 75 Find Checksum 86 76 Sum of Natural Numbers 87 77 Sum of a Series 88 78 Fibonacci Series 90 79 Generate a Series 91 Summary 93 Points to Remember 93 Review Questions 93 Evaluate Yourself 93 Search for Answers 94 Think and Solve 94 8 Subroutines and Stack 95 Chapter Objectives 95 81 Need of Subroutines 95 82 LCALL Instruction 96 83 RET Instruction 97 84 ACALL Instruction 98 85 Mechanism of Subroutines 98 86 Nesting of Subroutines 99 87 Stack 100 88 PUSH Instruction 100 89 POP Instruction 101 810 Other Applications of Subroutine 102 811 Comparison with 8085 102 812 Solved Examples 103 813 Parameter Passing in Subroutines 106 Summary 106 Points to Remember 106 Review Questions 107 Evaluate Yourself 107 Search for Answers 108 Think and Solve 108 9 Logical Operations 109 Chapter Objectives 109 91 Introduction 109 92 ANL Instruction 110 93 ORL Instruction 112 94 XRL Instruction 113 95 CLR Instruction 114 96 CPL Instruction 114 97 RL Instruction 115 98 RLC Instruction 116 99 RR Instruction 116 910 RRC Instruction 116 911 Solved Examples 117 Summary 120 Points to Remember 120 Review Questions 120 Evaluate Yourself 120 Search for Answers 121 Think and Solve 121 10 Boolean Variable Manipulation 123 Chapter Objectives 123 101 Introduction 123 1011 Source and Destination of Boolean Operations 124 102 Boolean Data Loading and Movement 124 1021 CLR Instruction 125 1022 SETB Instruction 125 1023 MOV Instruction 127 103 Bit-Oriented Program Branching 129 1031 JC Instruction 129 1032 JNC Instruction 130 1033 JB Instruction 131 1034 JNB Instruction 132 104 Bit-Oriented Logical Operations 133 1041 ANL Instruction 133 1042 ORL Instruction 134 1043 CPL Instruction 135 105 Solved Examples 137 Summary 138 Points to Remember 138 Review Questions 138 Evaluate Yourself 138 Search for Answers 139 Think and Solve 139 11 Programming Examples-II 141 Chapter Objectives 141 111 Introduction 141 112 Count 1s in a Byte 141 113 Unpack a BCD Number 142 114 Pack BCD Digits 144 115 Pack Array of Unpacked BCD Digits 144 116 Find Largest and Smallest Integers of an Array 146 117 Bubble Sorting 148 118 Find the Sum of Factorials 151 119 Sort Out Numbers Divisible by 4 153 Summary 154 Points to Remember 154 Review Questions 155 Evaluate Yourself 155 Search for Answers 155 Think and Solve 155 12 Advanced Instructions 157 Chapter Objectives 157 121 Introduction 157 122 MOVC Instruction 158 123 MOVX Instruction 159 124 XCH Instruction 162 125 XCHD Instruction 164 126 MUL Instruction 164 127 DIV Instruction 166 128 DA A Instruction 167 129 JMP Instruction 168 1210 SWAP Instruction 169 1211 JBC Instruction 170 1212 RETI Instruction 170 1213 Solved Examples 170 Summary 172 Points to Remember 172 Review Questions 172 Evaluate Yourself 172 Search for Answers 173 Think and Solve 173 13 Programming Examples-III 175 Chapter Objectives 175 131 Compare with External Array 175 132 Find Sum of a Series 176 133 Reverse an Array 177 134 HEX to BCD Conversion 179 135 Update Clock Display 180 136 Display Shift for Right Entry 181 137 Count Number of Words 183 138 Generate Prime Numbers 185 Summary 188 Points to Remember 188 Review Questions 188 Evaluate Yourself 188 Search for Answers 189 Think and Solve 189 14 External Interrupts 191 Chapter Objectives 191 141 Introduction 191 1411 What is an Interrupt? 191 1412 Vectored Interrupt 192 142 External Interrupts of 8051 192 143 SFRs for External Interrupt 193 1431 TCON (bits 0, 1, 2 and 3) 193 1432 IE (bits 0, 2 and 7) 195 1433 IP (bits 0 and 2) 195 144 Interrupt Service Routine (ISR) 196 1441 Checklist for INT0 196 1442 Checklist for INT1 197 145 Software Interrupts 197 146 Bene ts of Interrupt 197 147 Solved Examples 198 Summary 201 Points to Remember 202 Review Questions 202 Evaluate Yourself 202 Search for Answers 203 Think and Solve 203