PIC 'N UP THE PACE
1 Computers, Microprocessors and Microcontrollers – An Introduction 11 Introduction 1 12 Common Terminologies Associated with Computing Systems 2 13 Microprocessors and Microcontrollers 4 14 CISC and RISC Systems 6 15 Computing Languages 7 16 Memory 7 161 Random Access Memory (RAM) 8 162 Read-Only Memory (ROM) 9 163 Cache Memory 10 164 Memory Latency 10 17 Computer Architecture: Harvard and von Neumann 10 171 von Neumann Architecture: Princeton Architecture 10 172 Harvard Architecture 11 18 Evolution of Microcontrollers – 4 bit to 32 bit 12 181 Selection of a Microcontroller 12 182 4-Bit Microcontrollers 12 183 8-Bit Microcontrollers 13 184 16-Bit and 32-Bit Microcontrollers 13 Summary 14 Questions 14 2 Data Representation 21 Introduction 15 22 Number System 15 221 Binary System 16 222 Octal System 16 223 Hexadecimal System 16 224 Conversion from Decimal to Radix r 18 23 Decimal Representation 19 24 Complements 20 241 (r ? 1)’s Complement 20 242 r’s Complement 20 243 Subtraction of Unsigned Numbers Using r’s Complement 21 25 Fixed-Point Representation 22 251 Signed Integer Representation 22 252 Arithmetic Addition of Signed Numbers 22 253 Arithmetic Subtraction of Signed Numbers 23 254 Decimal Fixed-Point Representation 24 26 Floating-Point Representation 25 27 Other Binary Codes 26 271 Gray Code 26 1 15 272 Other Decimal Codes 26 273 Alphanumeric Codes 27 Summary 30 Questions 30 3 8051 Architecture 31 Introduction 31 32 Block Diagram of 8051 31 33 Pin Diagram of 8051 34 34 Clock and Machine Cycle for 8051 34 35 Registers of 8051 36 351 Program Counter (PC) 36 352 Data Pointer (DPTR) 36 353 A and B Registers 37 354 Program Status Word (PSW) Register 37 355 Special Function Registers (SFR’s) 39 36 The 8051 Internal Memory 39 361 Internal RAM 39 362 Internal ROM 41 363 External Memory 41 364 Memory Address Decoding 43 37 Stack and Stack Pointer 48 38 Timers and Counters 49 381 Basic Timer Registers 49 382 Timer Operation 49 383 Timer SFR’s 49 384 TMOD Register 50 385 Timer Modes 52 386 TCON Register 54 39 I/O Ports 54 391 Port 0 (P0: Address 80H) 54 392 Port 1 (P1: Address 90H) 55 393 Port 2 (P2: Address A0H) 56 394 Port 3 56 395 Writing to a Port 57 396 Reading a Port 57 310 Serial Input/Output 58 3101 Basic Concepts in Serial I/O 58 3102 Serial Port Control (SCON) Register 59 3103 Power Mode Control (PCON) SFR 60 3104 SBUF Register 61 3105 Data Transmission and Reception 61 3106 Serial Data Transmission Modes 61 311 Interrupts 64 3111 8051 Interrupts 65 3112 Interrupt Destination 65 3113 Interrupt Enable (IE) SFR 66 31 3114 Polling Sequence 66 3115 Interrupt Priority (IP) SFR 66 312 Supply Voltage 67 313 Status of SFR’s on Reset 68 314 Machine Cycles 68 315 Detailed Pin Description 71 Summary 71 Questions 72 4 Assembly Language Programming I: Addressing Modes and Data Transfer 41 Introduction 73 42 Assembly Language 74 421 Structure of Assembly Language 74 422 Steps to Create an ALP 75 423 Program Code in ROM 75 424 Execution of the Program by 8051 76 43 Flow Charts and Algorithm 77 44 8051 Data Types and Directives 78 441 Directives 78 45 Addressing Modes 79 451 Immediate Addressing Mode 80 452 Register Addressing Mode 80 453 Direct Addressing Mode 81 454 Indirect Addressing Mode 83 455 Indexed Addressing Mode for ROM Access 84 46 Data Transfer with Stack 85 461 PUSH Instruction 85 462 POP Instruction 86 47 Data Exchange 87 48 Complete Set of Data Transfer Instructions 89 Summary 90 Questions 90 5 Assembly Language Programming II: Arithmetic and Logic Operators 51 Introduction 93 52 Addition 93 521 Addition of Unsigned Numbers 94 522 Addition of 16-bit Numbers 95 523 Signed Addition 97 53 Incrementing and Decrementing 97 54 Subtraction 98 55 Multiplication 99 56 Division 100 57 Decimal Addition 101 58 Summary of Arithmetic Operations of 8051 106 59 Logical Operations: Byte Level 107 591 AND Operation 107 73 93 592 OR Operation 108 593 Exclusive OR Operation 108 510 CLEAR and COMPLEMENT Accumulator 111 5101 Clear Accumulator 111 5102 Complement Accumulator 111 511 Bit-Level Logical Operations 112 5111 Bit-Level AND 113 5112 Bit-Level OR 113 5113 Complement Bits 113 5114 Clear Bits 113 5115 Data Transfer into Bits 113 5116 Set Addressed Bits 113 512 Rotate Operation 114 5121 Rotate Accumulator Right 114 5122 Rotate through the Carry 115 5123 Serialize Data 116 513 Swap Operation 117 514 Summary of Bit-Level Logical Operations 119 Summary 120 Questions 120 6 Assembly Language III: Jump and Call Instructions 61 Introduction 123 62 Address Range of Jump and Call Instruction 123 621 Relative Range 123 622 Short Absolute Range 124 623 Long Absolute Range 125 63 Jump Instructions 125 631 Unconditional Jump 125 632 Bit Jump Instructions 125 633 Byte Jump Instructions 127 64 CALL Instruction 131 641 Subroutine 132 642 Sequence of Events in CALL Execution 132 Summary 133 Questions 133 7 Programming 8051 with C 71 Introduction 135 711 Advantages of Programming in C for Microcontrollers 135 712 Disadvantages of Programming in C 136 72 Declaring Variables 136 721 Data Types in 8051 C 136 722 Arrays and Strings 136 723 Number Representation 138 73 Writing a Simple C Program 138 74 Delay Generation in C 142 75 Programming Ports of 8051 with C 147 123 135 76 Operators in 8051 C 154 77 Serial Port Programming using Shift Operators 159 78 Code Conversions in C & ALP 164 79 Code Space 172 Summary 173 Questions 173 8 Timers/Counters and Serial Port in 8051 81 Introduction 175 82 Time Delay Generation Using Timers 176 821 Procedure for Time Delay Generation 176 822 Generation of Square Wave 179 823 Timer Mode 0 Programming 181 824 Large Time Delays 185 83 Application of Timers in Mode 2 188 84 Counter Application 192 85 Serial Data Transfer 203 851 8051 Connection to RS232 204 852 Special Function Registers of Serial Port 204 853 Review of Working of Serial Port 204 854 Procedure to Program the 8051 to Transfer Data Serially 205 855 Procedure for Programming the 8051 to Receive Data Serially 214 856 Procedure for Doubling the Baud Rate in the 8051 215 86 Second Serial Port in 8051 218 861 Features of Second Serial Port 219 Summary 225 Questions 225 9 Interrupts 91 Introduction 227 92 Review of Interrupts in 8051 228 921 Execution of an Interrupt by 8051 (On the Receipt of Interrupt Request) 228 93 External Interrupts 240 931 Level Triggered Interrupt Mode 240 932 Edge Triggered Interrupts Mode 243 94 Serial Communication Interrupt 246 95 Priority Implementation for 8051 Interrupts 250 951 Changing Interrupt Priority 252 Summary 260 Questions 260 10 Interfacing the 8051 101 Introduction 261 102 Interfacing a LED and a 7-Segment Display to an 8051 261 1021 Multiplexed 7-Segment Display 264 1022 LCD Display 265 103 Interfacing a Single Key (Push Button) to the 8051 278 104 Matrix Keypad or Interfacing Keyboard to the 8051 283 175 227 261 105 Stepper Motor Interfacing to 8051 287 106 Interfacing a DAC to an 8051 296 107 DC Motor Interfacing to 8051 305 1071 Features of a DC Motor 305 1072 Interfacing DC Motors Using Optoisolators 309 1073 PWM Control of DC Motor 310 108 Analog-to-Digital Converters (ADC) 312 1081 Parameters of ADC 312 1082 Interfacing ADC 0804 to 8051 313 1083 ADC 0808/0809 315 1084 ADC 0848 317 1085 Serial ADCs 319 Summary 323 Questions 323 11 Simulation of 8051 Using Keil Software (Lab Manual) 111 Introduction 327 112 Features of the 8051 Version Used 327 1121 Processor Features 327 113 Creating and Compiling a ? Vision2 Project 328 114 Programming in ALP 330 115 Digital-to-Analog Converter (DAC) Interfacing to 8051 358 1151 Ramp-Wave Generation 358 1152 Triangular Waveform Generation 359 1153 Sine Waveform Generation 360 1154 Square Wave Generation 360 1155 Square Wave with Programmable Amplitude and Programmable Frequency 361 Summary 373 Questions 373 12 MSP Microcontroller: Introduction and Key Features 121 Introduction 375 1211 Motivation for MSP430 375 1212 Key Features 376 122 Low-Power Applications 376 1221 Why Low Power? 376 1222 Practices for Low-Power Consumption 377 1223 Low-Power RF Capabilities 377 1224 Target Applications 377 123 MSP430 RISC CPU Architecture 378 124 Details of 16-Bit RISC CPU 378 1241 Registers 378 1242 Peripheral Overview 379 1243 Communication Interfaces 380 125 Clock System 381 1251 Clock Sources 381 1252 Clock Outputs 381 1253 Choice of Clock Source 382 327 375 126 Memory Subsystem 382 127 Key Differentiating Factors between Different Families 384 128 Digital I/O Ports 386 1281 Registers for Port P1 of MSP430F2xx 388 1282 Port Interrupts 389 1283 I/O Ports Programming using C and assembly 389 129 Muxing Scheme for MSP430 Pins 392 Summary 393 Questions 393 13 On-Chip Peripherals, Interfacing and Applications of MSP430 131 Watchdog Timer 395 1311 Applications of WDT 396 1312 WDT Interrupts 397 1313 WDT+ Enhancements 397 132 Data Acquisition 397 1321 Comparator 398 1322 Successive-Approximation ADC (SAR) 398 1323 Sigma–Delta ADC (SD) 398 133 Comparator_A 398 1331 Input Analog Switches 398 1332 Output Filter 399 1333 Voltage Reference Generator 399 1334 Comparator_A Interrupts 400 1335 Comparator_A Registers 400 134 ADC10 Successive-Approximation ADC 400 1341 Simplified Block Diagram of the ADC10 400 1342 Core 400 1343 Clock 401 1344 Input Selection 401 1345 Conversion Trigger 401 1346 Voltage Reference Generator 401 1347 Interrupts 401 1348 Conversion Modes 402 135 The SD16_A Sigma–Delta ADC 402 1351 SD ADC Core 402 1352 Analog Input Range and PGA 403 1353 Voltage Reference Generator 403 1354 Analog Input Pair Selection 403 1355 Digital Filter 403 1356 Conversion Memory Register (SD16MEM0) 403 1357 Output Data Format 404 1358 Conversion Modes 404 1359 SD16_A Interrupts 404 136 Operational Amplifiers 404 1361 Operational Amplifiers Registers 405 1362 Topologies Configuration 405 395 137 Timers 406 1371 Basic Timer 406 138 Real-Time Clock 407 139 DAC: Digital-to-Analog Conversion 408 1310 Direct Memory Access (DMA) 409 13101 DMA Controller Features 410 13102 System Interrupts 411 13103 DMA Controller Interrupts 411 13104 DMA Registers 411 13105 Organization of the Software Application for DMA 411 1311 LCD Controller 411 13111 Clock and Bias for the LCD Controller 413 13112 Blinking the LCD 413 13113 LCD Memory 413 13114 Interfacing LCD with MSP430 413 1312 Case Studies of Applications of MSP430 – Data Acquisition System 414 1313 Sensor Networks 415 13131 Wireless Sensor Networks 416 13132 Wired Sensor Networks 417 Summary 418 Questions 418 14 Programming the MSP430 141 Addressing Modes 419 1411 Register Mode 420 1412 Indexed Mode 420 1413 Symbolic Mode (PC Relative) 420 1414 Absolute Mode 420 1415 Indirect Register Mode 421 1416 Indirect Autoincrement Mode 421 1417 Immediate Mode 421 142 Instruction Set of MSP430 422 143 Double Operand Core Instructions 422 1431 Arithmetic Instructions 422 1432 Logical and Register Control Instructions 422 1433 Data Instructions 423 144 Single Operand Core Instructions (Format II) 423 1441 Logical and Register Control Instructions 423 1442 Program Flow Control Instructions 423 145 Program Flow Control – Jumps: Core Instructions (Format III) 423 146 Emulated Instructions 424 1461 Arithmetic Instructions 424 1462 Logical and Register Control Instructions 424 1463 Data Instructions 424 1464 Program Flow Control 425 147 Movement Instructions 425 1471 General MOV 425 1472 Stack Operations 425 419 148 Implementation of Decimal Arithmetic 425 149 Shift and Rotate Instructions 426 1410 Code Composer Essentials 427 14101 CCE Installation 427 14102 Creating and Assembling a MSP430 Project 429 1411 Programming in ALP 431 14111 Program 1 432 14112 Program 2: Byte Data Transfer 433 14113 Program 3: Block Words Transfer 434 14114 Program 4: Data Transfer with Overlapping Locations 435 14115 Program 5: Exchange of data 436 14116 Program 6: Bubble Sort 437 14117 Program 7: Code Conversion 438 14118 Program 8: Counters 440 1412 C and Assembly+C Projects for MSP430 Microcontrollers 441 14121 Mixing C and Assembly Language 443 1413 Interrupts and Interrupt Programming 443 14131 What Happens when an Interrupt Is Requested? 444 14132 Interrupt Programming 445 1414 Low-Power Modes and Low-Power Programming 446 14141 Low Power Modes 446 14142 Low Power Programming 446 1415 Interfacing LED/LCD/External Memory 447 14151 Interfacing External Memory 447 14152 Interfacing LED 447 14153 Interfacing Seven-Segment Display 447 Summary 448 Questions 449 15 Application Development Using 8051 151 Support Structure for 8051-Based Product Development 451 152 Lab-Based Experiments: Design and Testing 452 153 Development of Mini Projects Based on 8051 453 1531 Monitor Switch Status 454 1532 Data Acquisition and Display 456 1533 Remote Control 457 154 Implementation of Real-World Projects Using Sensors and Actuators 459 1541 Automatic Irrigation System 459 1542 Theft Detection while Transporting Liquid Products 459 1543 Automated System for LPG Gas-Leakage Detection and Refill Booking 463 1544 Colour Reflectance-Based Blood Analyzer for Blood Sugar 465 1545 Wireless Home Security System Using PIR Sensor 466 155 Trends in Usage of 8051 in 32-bit Applications 467 Summary 468 Questions 468