logging in or signing up chapter1_DEK3133[1] dgkanade72 Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 18 Category: Education License: All Rights Reserved Like it (0) Dislike it (0) Added: April 03, 2011 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Chapter 1 : Chapter 1 Introduction to Microcontroller Review on Microprocessor System : 2 Review on Microprocessor System The P system components include a CPU, RAM, ROM and I/O ports Its interconnections comprise an address bus, a data bus and control lines These buses are required to handle the data transfer between the CPU, memory and ports Review on Microprocessor System : 3 Review on Microprocessor System Figure 1.1: Microprocessor-based system Review on Microprocessor System : 4 Review on Microprocessor System Program execution- - The ROM and RAM contain program and data in numbered locations. - Each instruction and operand are stored in sequential locations. - The program instruction codes are fetched into the CPU and decoded. Review on Microprocessor System : 5 Review on Microprocessor System Program execution (con..) - The CPU then sets up the internal and external control lines as necessary and carries out the operation specified in the program. - The instructions are executed in order of their addresses, unless the instruction itself causes a jump to another point in the program, or an interrupt is received. Review on Microprocessor System : 6 Review on Microprocessor System Figure 1.2: Program execution sequence Review on Microprocessor System : 7 Review on Microprocessor System PC Engineering Applications - Can be used as a standard hardware platform in a variety of engineering systems by fitting special interfacing hardware and programming the PC to control an external system through I/O. - increasingly used in manufacturing systems; control a machine tool, robot or assembly system. - considered to be powerful computer machines. Review on Microprocessor System : 8 Review on Microprocessor System PC Engineering Applications - PC also has the advantage of using a standard operating system and programming languages that allow control programs to be written in high level languages such as ‘C’ or Visual Basic. - Graphical programming tools are also available for designing control and instrumentation applications without any conventional programming at all. The Microcontroller : 9 The Microcontroller The microprocessor can provide, in a simplified form, all the main elements of the conventional microprocessor system on one chip. Less complex applications can be designed and built quickly and cheaply. A working system can consist of a microcontroller chip and just a few external components for feeding data in and out, and generating the clock. The Microcontroller : 10 The Microcontroller A Microcontroller Application - Used to control a small system. - calculator, automatic washing machine, message display, electronic lock or similar application. The Microcontroller : 11 The Microcontroller Figure 1.3: Microcontroller-based system The Microcontroller : 12 The Microcontroller Programming a Microcontroller - Normally have ROM program memory, into which the program must be loaded before the chip is placed in the application circuit. - The program is written and converted to machine code in the host, and downloaded via a serial data link. - The chip is then removed from the programming unit and inserted into the application hardware. Microcontroller Vs Microprocessor : 13 Microcontroller Vs Microprocessor Microcontroller Vs Microprocessor : 14 Microcontroller Vs Microprocessor Microcontroller Vs Microprocessor : 15 Microcontroller Vs Microprocessor Picking a PIC Microcontroller : Picking a PIC Microcontroller Choosing a PIC microcontroller for your application requires taking into account a variety of factors. These factors include: The number of I/O pins required The peripherals needed (i.e. CCP module, USART, etc.) The memory size (program memory, RAM, EEPROM) Microcontroller speed Physical size (form factor) 16 PIC16F87x : PIC16F87x 17 Slide 18: 18 8-bit Microcontroller Motorola – M68HC05, HC08, HC11 Intel – 8051 Atmel Philips Dallas Cygnal Zilog etc Microchip – PIC Atmel - AVR PIC Product Overview : PIC Product Overview 19 Current Main Architecture : Current Main Architecture 20 Harvard Architecture Von Neuman Architecture CPU CPU Program and Data Memory Data Memory Program Memory 8-bit PIC Microcontroller : 8-bit PIC Microcontroller 21 PIC microcontroller architecture is based on a modified Harvard RISC instruction set that provides an easy migration path from 6 to 80 pins and from 384 bytes to 128K bytes of program memory. By combining the RISC features with a modified Harvard dual-bus architecture, Microchip's fast and flexible 10 MIPS PIC16F core is the most popular architecture for new microcontroller designs. Central Processing Unit (CPU) : 22 Central Processing Unit (CPU) CPU is the brain of a microprocessor where all of the arithmetic and logical operations are performed. CPU has a role of connective element between other blocks in the microcontroller. It coordinates the work of other blocks and executes the user program. The control unit controls the internal operations of the microprocessor and sends out control signals to other parts of the microprocessor to carry out the required instructions. A generic CPU has a set of registers (memory of CPU), an arithmetic logic unit (ALU), memory interface and timing circuits Central Processing Unit (CPU) : 23 Central Processing Unit (CPU) Central Processing Unit (CPU) : 24 Central Processing Unit (CPU) This is a unit which monitors and controls all processes inside the microcontroller. It consists of several smaller subunits, of which the most important are: Instruction Decoder is a part of the electronics which recognizes program instructions and runs other circuits on the basis of that. The “instruction set” which is different for each microcontroller family expresses the abilities of this circuit. It decodes the binary code in an instruction and passes the necessary control signals to the CU to complete the operations specified by the instruction. Central Processing Unit (CPU) : Central Processing Unit (CPU) Arithmetical Logical Unit (ALU) performs all mathematical and logical operations upon data. Example of arithmetic operations are add, subtract, multiply and divide. In low-end microprocessors, multiply and divide may not be implemented. Example of logical operations are AND, OR, and XOR. The ALU also performs shift and rotate operations that may either be arithmetic or logical in nature. 25 Central Processing Unit (CPU) : Central Processing Unit (CPU) Accumulator is a SFR closely related to the operation of the ALU. It is a kind of working desk used for storing all data upon which some operation should be performed (addition, shift/move etc.). It also stores the results ready for use in further processing. One of the SFRs, called a Status Register (PSW), is closely related to the accumulator. It shows at any given moment the “status” of a number stored in the accumulator (number is greater or less than zero etc.). 26 Central Processing Unit (CPU) : 27 Central Processing Unit (CPU) Register Registers refer to a set of internal storage locations within the CPU. These include: 1. Control and Status Registers that are used by the control unit to control the operation of CPU, such as: - Program Counter (PC) - Instruction Register (IR) Central Processing Unit (CPU) : 28 Central Processing Unit (CPU) 2. User-Visible Registers that can be accessed by programmer using machine language, such as: - General-purpose Register - Special Function Register - Address Register - Data Register - Flag Register Special Function Register (SFRs) & GPR. : 29 Special Function Register (SFRs) & GPR. Memory System : Memory System 30 Each memory address corresponds to one memory location. The content of any location becomes known by its addressing. Memory can either be written to or read from. There are several types of memory within the microcontroller. Memory is part of the microcontroller used for data storage. The easiest way to explain it is to compare it with a filing cabinet with many drawers. Suppose, the drawers are clearly marked so that it is easy to access any of them. It is easy enough to find out the contents of the drawer by reading the label on the front of the drawer. Memory System : 31 Memory System There are two groups of memory Program memory – stores all the program code and this memory is usually non-volatile (data is not lost after the removal of power) Data memory – stores the temporary user data during the arithmetic and logical operations. PIC Program Memory – Flash Program Memory : 32 PIC Program Memory – Flash Program Memory 0000h -> 1FFFh = 8Kbyte of memory size 8K = 8192 lines of programming codes. Each line of code only take 1 word (14bits) of memory size. Memory System : 33 Memory System RAM (Random Access Memory) – a general purpose memory which usually stores user data. RAM is volatile. ROM (Read Only Memory) – usually holds program of fixed user data. ROM are programmed at the factory and their contents cannot be changed by the user. ROM are only useful if we have developed program and wish to order several thousand copies of it. Memory System : 34 Memory System EPROM (Erasable Programmable ROM) – similar to ROM but it can be programmed using a suitable programming device. Has a small clear window on the chip where the data can be erased under a UV light. Many development versions of microcontrollers are manufactured with EPROM memories where the user program are usually stored. Memory System : 35 Memory System Some versions of EPROM, known as OTP (One Time Programmable), can be programmed using a suitable programmer device but these memories cannot be erased. OTP memories cost less than the EPROM and it is useful after a project has been developed completely and it is required to make hundred of copy of the program memory. Memory System : 36 Memory System EEPROM (Electrical EPROM) – These memory can be erased and also can be programmed under program control. EEPROMs are used to save configuration information, maximum and minimum values, identification data etc. Some microcontrollers have built-in EEPROM memories (e.g. PIC16F84 contains a 64-byte EEPROM memory where each byte can be program and erase directly by software). EEPROM memories are usually very slow. Memory System : 37 Memory System Flash EEPROM – very popular and is used in many microcontrollers (e.g. PIC16F77A contain 8K bytes of flash memory) to store the data program. The data on a flash EEPROM is erased and programmed using a programming device. The entire contents of the memory should be erased and then reprogrammed. Flash EEPROMs are usually very fast. Bus : 38 Bus System bus is a collection of wires carrying information within a computer system. There are three types of system busses: address, data and control busses. Address Busses are wires that carry the CPU-generated address signals out to memory and to I/O devices. It is an uni-directional. The size of the memory space that a microprocessor can access depends on the number of address lines. Bus : 39 Bus No of address lines Size of memory space 8 16 20 24 32 Bus : 40 Bus Data buses refer to data signals that travel out of and into the microprocessor. Thus, data bus is bi-directional. The number of wires in the data bus depends on the word size that the microprocessor operates with. An 8-bit microprocessor will have a data bus consisting of 8 wires while a 32-bit microprocessor will have a data bus with 32 wires. Bus : 41 Bus Control Bus consists of wires, some of which carry signals from the CPU to external devices, while other carry signals from external devices to the CPU. The number of wire present in the control bus varies from microprocessor to microprocessor. Example of control buses signals are READ/WRITE, WAIT, READY and HOLD. Bus : 42 Bus I/O Modules : 43 I/O Modules I/O modules provide interface between the computer system and the ‘real world’. An external device connected to an I/O modules is often referred to as a peripheral device. Three broad classes of I/O devices are: Human-readable I/Os: suitable for communication with the user. E.g. Monitor, keyboard, mouse, joystick, video display terminals, printer, scanner, microphone and speaker I/O Modules : 44 I/O Modules Machine-readable I/Os: Suitable for communicating with equipment E.g. magnetic disk, optical disk, sensors and actuators. Communication I/Os: Suitable for communication with remote devices. E.g. infra-red (IR) interface, radio frequency (RF) interface, Bluetooth device and wireless LAN. I/O Modules : 45 I/O Modules Serial Communications : 46 Serial Communications Some microcontrollers contain hardware to implement a serial asynchronous communications interface. The baud rate and the data format can usually be selected in software. If serial input/output hardware is not provided, it is easy to develop software to implement serial data transfer using any I/O pin of a microcontroller. Some microcontrollers incorporate SPI(Serial Peripheral Interface) or IC bus interfaces. These enable a microcontroller to interface to other comptible devices easily. 2 Serial Communications : 47 Serial Communications Serial Communication : 48 Serial Communication The Clock : 49 The Clock All microcontrollers require an oscillator (clock) to operate. Most microcontrollers will operate with a crystal and two capacitors. Some will operate with resonators or with external resistor-capacitor pair. Some microcontrollers have built-in resistor-capacitor type oscillators and they do not require any external timing components PIC Clock Source. : PIC Clock Source. 50 The value of capacitors ranges from 15pf to 33 pf The Clock : 51 The Clock Watchdog Timer : 52 Watchdog Timer Watchdog is a mechanism which microcontroller uses to defend itself against programs getting stuck. As with any other electrical circuit, so with a microcontroller too can occur failure, or some work impairment. Unfortunately, microcontroller also has program where problems can occur as well. When this happens, microcontroller will stop working and will remain in that state until someone resets it. Because of this, watchdog mechanism has been introduced. After a certain period of time, watchdog resets the microcontroller (microcontroller in fact resets itself). Watchdog works on a simple principle: if timer overflow occurs, microcontroller is reset, and it starts executing a program all over again. In this way, reset will occur in case of both correct and incorrect functioning. Watchdog Timer : Watchdog Timer 53 Analogue-to-digital Converter : 54 Analogue-to-digital Converter Some microcontrollers are equipped with analogue-to-digital converter circuits. Usually these converters are 8 bits, but some microcontrollers have 10- or even 12-bit converters. A/D converters usually generate interrupts when a conversion is complete so that the user program can read the converted data very quickly. A/D converters are very useful in control and monitoring applications since most sensors produce analogue output voltages. Analogue-to-digital Converter : 55 Analogue-to-digital Converter Analogue-to-digital Converter : Analogue-to-digital Converter External signals are usually fundamentally different from those the microcontroller understands (Ones and Zeros), so that they have to be converted in order for the microcontroller to understand them. An analogue to digital converter is an electronic circuit which converts continuous signals to discrete digital numbers. This module is therefore used to convert some analogue value into binary number and forwards it to the CPU for further processing. In other words, this module is used for input pin voltage measurement (analogue value). The result of measurement is a number (digital value) used and processed later in the program. 56 Program : 57 Program Microcontroller needs a program that would be executed. A program is a logical sequence of instructions stored in the memory of the system. In its operations, the CPU fetches an instruction from memory, decodes the instruction and carries out the operation or operations specified by the instruction. A Microcontroller 16F877A : 58 A Microcontroller 16F877A World of Numbers : World of Numbers 59 World of Numbers : World of Numbers 60 Binary Number System Hexadecimal Number System World of Numbers : World of Numbers 61 Hexadecimal to Decimal Number Conversion Decimal to Binary Number Conversion World of Numbers : World of Numbers 62 Marking Numbers The hexadecimal numbering system is along with binary and decimal number systems considered to be the most important for us. It is easy to make conversion of any hexadecimal number to binary and it is also easy to remember it. However, these conversions may cause confusion. For example, what does the statement “It is necessary to count up 110 products on assembly line” actually mean? Depending on whether it is about binary, decimal or hexadecimal, the result could be 6, 110 or 272 products, respectively! Accordingly, in order to avoid misunderstanding, different prefixes and suffixes are directly added to the numbers. The prefix $ or 0x as well as the suffix h marks the numbers in hexadecimal system. For example, hexadecimal number 10AF may look as follows $10AF, 0x10AF or 10AFh. Similarly, binary numbers usually get the suffix % or 0b, whereas decimal numbers get the suffix D. Comparative table below contains the values of numbers 0-255 in three different numbering systems. World of Numbers : World of Numbers 63 Byte A byte or a program word consists of eight bits grouped together. All mathematical operations can be performed upon them, like upon common decimal numbers. The largest value has the leftmost bit called the most significant bit (MSB). The rightmost bit has the least value and is therefore called the least significant bit (LSB). Since eight zeros and units of one byte can be combined in 256 different ways, the largest decimal number which can be represented by one byte is 255 (one combination represents zero). A nibble is referred to as half a byte. Depending on which half of the byte we are talking about (left or right), there are “high” and “low” nibbles. Summary : 64 Summary The CPU communicates with the main system chip via a shared set of address and data bus lines. The address lines select the device and location for the data to be transferred on the data bus. The microcontroller provides, in simplified form, most of the features of a conventional microprocessor system on one chip. Summary : 65 Summary The PC consists of data input, storage, processing and output devices. The main unit is a modular system, consisting of the motherboard, power supply, disk drives and expansion cards containing interfacing circuits plugged into the motherboard. The motherboard carries the microprocessor (CPU) chip, RAM module, a BIOS ROM, ISD and keyboard interface. Summary : 66 Summary The microcontroller consist of: CPU Memory Unit Buses Clock (Timer, Watchdog) I/O Modules Serial Communication PWM (Pulse Width Modulation) A/D Converter Summary : Summary PIC Applications: Automotive industries Controlling home appliances Controlling industrial instruments Remote sensors Electric door locks Safety devices Smart cards Many more…………. 67 You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
chapter1_DEK3133[1] dgkanade72 Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 18 Category: Education License: All Rights Reserved Like it (0) Dislike it (0) Added: April 03, 2011 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Chapter 1 : Chapter 1 Introduction to Microcontroller Review on Microprocessor System : 2 Review on Microprocessor System The P system components include a CPU, RAM, ROM and I/O ports Its interconnections comprise an address bus, a data bus and control lines These buses are required to handle the data transfer between the CPU, memory and ports Review on Microprocessor System : 3 Review on Microprocessor System Figure 1.1: Microprocessor-based system Review on Microprocessor System : 4 Review on Microprocessor System Program execution- - The ROM and RAM contain program and data in numbered locations. - Each instruction and operand are stored in sequential locations. - The program instruction codes are fetched into the CPU and decoded. Review on Microprocessor System : 5 Review on Microprocessor System Program execution (con..) - The CPU then sets up the internal and external control lines as necessary and carries out the operation specified in the program. - The instructions are executed in order of their addresses, unless the instruction itself causes a jump to another point in the program, or an interrupt is received. Review on Microprocessor System : 6 Review on Microprocessor System Figure 1.2: Program execution sequence Review on Microprocessor System : 7 Review on Microprocessor System PC Engineering Applications - Can be used as a standard hardware platform in a variety of engineering systems by fitting special interfacing hardware and programming the PC to control an external system through I/O. - increasingly used in manufacturing systems; control a machine tool, robot or assembly system. - considered to be powerful computer machines. Review on Microprocessor System : 8 Review on Microprocessor System PC Engineering Applications - PC also has the advantage of using a standard operating system and programming languages that allow control programs to be written in high level languages such as ‘C’ or Visual Basic. - Graphical programming tools are also available for designing control and instrumentation applications without any conventional programming at all. The Microcontroller : 9 The Microcontroller The microprocessor can provide, in a simplified form, all the main elements of the conventional microprocessor system on one chip. Less complex applications can be designed and built quickly and cheaply. A working system can consist of a microcontroller chip and just a few external components for feeding data in and out, and generating the clock. The Microcontroller : 10 The Microcontroller A Microcontroller Application - Used to control a small system. - calculator, automatic washing machine, message display, electronic lock or similar application. The Microcontroller : 11 The Microcontroller Figure 1.3: Microcontroller-based system The Microcontroller : 12 The Microcontroller Programming a Microcontroller - Normally have ROM program memory, into which the program must be loaded before the chip is placed in the application circuit. - The program is written and converted to machine code in the host, and downloaded via a serial data link. - The chip is then removed from the programming unit and inserted into the application hardware. Microcontroller Vs Microprocessor : 13 Microcontroller Vs Microprocessor Microcontroller Vs Microprocessor : 14 Microcontroller Vs Microprocessor Microcontroller Vs Microprocessor : 15 Microcontroller Vs Microprocessor Picking a PIC Microcontroller : Picking a PIC Microcontroller Choosing a PIC microcontroller for your application requires taking into account a variety of factors. These factors include: The number of I/O pins required The peripherals needed (i.e. CCP module, USART, etc.) The memory size (program memory, RAM, EEPROM) Microcontroller speed Physical size (form factor) 16 PIC16F87x : PIC16F87x 17 Slide 18: 18 8-bit Microcontroller Motorola – M68HC05, HC08, HC11 Intel – 8051 Atmel Philips Dallas Cygnal Zilog etc Microchip – PIC Atmel - AVR PIC Product Overview : PIC Product Overview 19 Current Main Architecture : Current Main Architecture 20 Harvard Architecture Von Neuman Architecture CPU CPU Program and Data Memory Data Memory Program Memory 8-bit PIC Microcontroller : 8-bit PIC Microcontroller 21 PIC microcontroller architecture is based on a modified Harvard RISC instruction set that provides an easy migration path from 6 to 80 pins and from 384 bytes to 128K bytes of program memory. By combining the RISC features with a modified Harvard dual-bus architecture, Microchip's fast and flexible 10 MIPS PIC16F core is the most popular architecture for new microcontroller designs. Central Processing Unit (CPU) : 22 Central Processing Unit (CPU) CPU is the brain of a microprocessor where all of the arithmetic and logical operations are performed. CPU has a role of connective element between other blocks in the microcontroller. It coordinates the work of other blocks and executes the user program. The control unit controls the internal operations of the microprocessor and sends out control signals to other parts of the microprocessor to carry out the required instructions. A generic CPU has a set of registers (memory of CPU), an arithmetic logic unit (ALU), memory interface and timing circuits Central Processing Unit (CPU) : 23 Central Processing Unit (CPU) Central Processing Unit (CPU) : 24 Central Processing Unit (CPU) This is a unit which monitors and controls all processes inside the microcontroller. It consists of several smaller subunits, of which the most important are: Instruction Decoder is a part of the electronics which recognizes program instructions and runs other circuits on the basis of that. The “instruction set” which is different for each microcontroller family expresses the abilities of this circuit. It decodes the binary code in an instruction and passes the necessary control signals to the CU to complete the operations specified by the instruction. Central Processing Unit (CPU) : Central Processing Unit (CPU) Arithmetical Logical Unit (ALU) performs all mathematical and logical operations upon data. Example of arithmetic operations are add, subtract, multiply and divide. In low-end microprocessors, multiply and divide may not be implemented. Example of logical operations are AND, OR, and XOR. The ALU also performs shift and rotate operations that may either be arithmetic or logical in nature. 25 Central Processing Unit (CPU) : Central Processing Unit (CPU) Accumulator is a SFR closely related to the operation of the ALU. It is a kind of working desk used for storing all data upon which some operation should be performed (addition, shift/move etc.). It also stores the results ready for use in further processing. One of the SFRs, called a Status Register (PSW), is closely related to the accumulator. It shows at any given moment the “status” of a number stored in the accumulator (number is greater or less than zero etc.). 26 Central Processing Unit (CPU) : 27 Central Processing Unit (CPU) Register Registers refer to a set of internal storage locations within the CPU. These include: 1. Control and Status Registers that are used by the control unit to control the operation of CPU, such as: - Program Counter (PC) - Instruction Register (IR) Central Processing Unit (CPU) : 28 Central Processing Unit (CPU) 2. User-Visible Registers that can be accessed by programmer using machine language, such as: - General-purpose Register - Special Function Register - Address Register - Data Register - Flag Register Special Function Register (SFRs) & GPR. : 29 Special Function Register (SFRs) & GPR. Memory System : Memory System 30 Each memory address corresponds to one memory location. The content of any location becomes known by its addressing. Memory can either be written to or read from. There are several types of memory within the microcontroller. Memory is part of the microcontroller used for data storage. The easiest way to explain it is to compare it with a filing cabinet with many drawers. Suppose, the drawers are clearly marked so that it is easy to access any of them. It is easy enough to find out the contents of the drawer by reading the label on the front of the drawer. Memory System : 31 Memory System There are two groups of memory Program memory – stores all the program code and this memory is usually non-volatile (data is not lost after the removal of power) Data memory – stores the temporary user data during the arithmetic and logical operations. PIC Program Memory – Flash Program Memory : 32 PIC Program Memory – Flash Program Memory 0000h -> 1FFFh = 8Kbyte of memory size 8K = 8192 lines of programming codes. Each line of code only take 1 word (14bits) of memory size. Memory System : 33 Memory System RAM (Random Access Memory) – a general purpose memory which usually stores user data. RAM is volatile. ROM (Read Only Memory) – usually holds program of fixed user data. ROM are programmed at the factory and their contents cannot be changed by the user. ROM are only useful if we have developed program and wish to order several thousand copies of it. Memory System : 34 Memory System EPROM (Erasable Programmable ROM) – similar to ROM but it can be programmed using a suitable programming device. Has a small clear window on the chip where the data can be erased under a UV light. Many development versions of microcontrollers are manufactured with EPROM memories where the user program are usually stored. Memory System : 35 Memory System Some versions of EPROM, known as OTP (One Time Programmable), can be programmed using a suitable programmer device but these memories cannot be erased. OTP memories cost less than the EPROM and it is useful after a project has been developed completely and it is required to make hundred of copy of the program memory. Memory System : 36 Memory System EEPROM (Electrical EPROM) – These memory can be erased and also can be programmed under program control. EEPROMs are used to save configuration information, maximum and minimum values, identification data etc. Some microcontrollers have built-in EEPROM memories (e.g. PIC16F84 contains a 64-byte EEPROM memory where each byte can be program and erase directly by software). EEPROM memories are usually very slow. Memory System : 37 Memory System Flash EEPROM – very popular and is used in many microcontrollers (e.g. PIC16F77A contain 8K bytes of flash memory) to store the data program. The data on a flash EEPROM is erased and programmed using a programming device. The entire contents of the memory should be erased and then reprogrammed. Flash EEPROMs are usually very fast. Bus : 38 Bus System bus is a collection of wires carrying information within a computer system. There are three types of system busses: address, data and control busses. Address Busses are wires that carry the CPU-generated address signals out to memory and to I/O devices. It is an uni-directional. The size of the memory space that a microprocessor can access depends on the number of address lines. Bus : 39 Bus No of address lines Size of memory space 8 16 20 24 32 Bus : 40 Bus Data buses refer to data signals that travel out of and into the microprocessor. Thus, data bus is bi-directional. The number of wires in the data bus depends on the word size that the microprocessor operates with. An 8-bit microprocessor will have a data bus consisting of 8 wires while a 32-bit microprocessor will have a data bus with 32 wires. Bus : 41 Bus Control Bus consists of wires, some of which carry signals from the CPU to external devices, while other carry signals from external devices to the CPU. The number of wire present in the control bus varies from microprocessor to microprocessor. Example of control buses signals are READ/WRITE, WAIT, READY and HOLD. Bus : 42 Bus I/O Modules : 43 I/O Modules I/O modules provide interface between the computer system and the ‘real world’. An external device connected to an I/O modules is often referred to as a peripheral device. Three broad classes of I/O devices are: Human-readable I/Os: suitable for communication with the user. E.g. Monitor, keyboard, mouse, joystick, video display terminals, printer, scanner, microphone and speaker I/O Modules : 44 I/O Modules Machine-readable I/Os: Suitable for communicating with equipment E.g. magnetic disk, optical disk, sensors and actuators. Communication I/Os: Suitable for communication with remote devices. E.g. infra-red (IR) interface, radio frequency (RF) interface, Bluetooth device and wireless LAN. I/O Modules : 45 I/O Modules Serial Communications : 46 Serial Communications Some microcontrollers contain hardware to implement a serial asynchronous communications interface. The baud rate and the data format can usually be selected in software. If serial input/output hardware is not provided, it is easy to develop software to implement serial data transfer using any I/O pin of a microcontroller. Some microcontrollers incorporate SPI(Serial Peripheral Interface) or IC bus interfaces. These enable a microcontroller to interface to other comptible devices easily. 2 Serial Communications : 47 Serial Communications Serial Communication : 48 Serial Communication The Clock : 49 The Clock All microcontrollers require an oscillator (clock) to operate. Most microcontrollers will operate with a crystal and two capacitors. Some will operate with resonators or with external resistor-capacitor pair. Some microcontrollers have built-in resistor-capacitor type oscillators and they do not require any external timing components PIC Clock Source. : PIC Clock Source. 50 The value of capacitors ranges from 15pf to 33 pf The Clock : 51 The Clock Watchdog Timer : 52 Watchdog Timer Watchdog is a mechanism which microcontroller uses to defend itself against programs getting stuck. As with any other electrical circuit, so with a microcontroller too can occur failure, or some work impairment. Unfortunately, microcontroller also has program where problems can occur as well. When this happens, microcontroller will stop working and will remain in that state until someone resets it. Because of this, watchdog mechanism has been introduced. After a certain period of time, watchdog resets the microcontroller (microcontroller in fact resets itself). Watchdog works on a simple principle: if timer overflow occurs, microcontroller is reset, and it starts executing a program all over again. In this way, reset will occur in case of both correct and incorrect functioning. Watchdog Timer : Watchdog Timer 53 Analogue-to-digital Converter : 54 Analogue-to-digital Converter Some microcontrollers are equipped with analogue-to-digital converter circuits. Usually these converters are 8 bits, but some microcontrollers have 10- or even 12-bit converters. A/D converters usually generate interrupts when a conversion is complete so that the user program can read the converted data very quickly. A/D converters are very useful in control and monitoring applications since most sensors produce analogue output voltages. Analogue-to-digital Converter : 55 Analogue-to-digital Converter Analogue-to-digital Converter : Analogue-to-digital Converter External signals are usually fundamentally different from those the microcontroller understands (Ones and Zeros), so that they have to be converted in order for the microcontroller to understand them. An analogue to digital converter is an electronic circuit which converts continuous signals to discrete digital numbers. This module is therefore used to convert some analogue value into binary number and forwards it to the CPU for further processing. In other words, this module is used for input pin voltage measurement (analogue value). The result of measurement is a number (digital value) used and processed later in the program. 56 Program : 57 Program Microcontroller needs a program that would be executed. A program is a logical sequence of instructions stored in the memory of the system. In its operations, the CPU fetches an instruction from memory, decodes the instruction and carries out the operation or operations specified by the instruction. A Microcontroller 16F877A : 58 A Microcontroller 16F877A World of Numbers : World of Numbers 59 World of Numbers : World of Numbers 60 Binary Number System Hexadecimal Number System World of Numbers : World of Numbers 61 Hexadecimal to Decimal Number Conversion Decimal to Binary Number Conversion World of Numbers : World of Numbers 62 Marking Numbers The hexadecimal numbering system is along with binary and decimal number systems considered to be the most important for us. It is easy to make conversion of any hexadecimal number to binary and it is also easy to remember it. However, these conversions may cause confusion. For example, what does the statement “It is necessary to count up 110 products on assembly line” actually mean? Depending on whether it is about binary, decimal or hexadecimal, the result could be 6, 110 or 272 products, respectively! Accordingly, in order to avoid misunderstanding, different prefixes and suffixes are directly added to the numbers. The prefix $ or 0x as well as the suffix h marks the numbers in hexadecimal system. For example, hexadecimal number 10AF may look as follows $10AF, 0x10AF or 10AFh. Similarly, binary numbers usually get the suffix % or 0b, whereas decimal numbers get the suffix D. Comparative table below contains the values of numbers 0-255 in three different numbering systems. World of Numbers : World of Numbers 63 Byte A byte or a program word consists of eight bits grouped together. All mathematical operations can be performed upon them, like upon common decimal numbers. The largest value has the leftmost bit called the most significant bit (MSB). The rightmost bit has the least value and is therefore called the least significant bit (LSB). Since eight zeros and units of one byte can be combined in 256 different ways, the largest decimal number which can be represented by one byte is 255 (one combination represents zero). A nibble is referred to as half a byte. Depending on which half of the byte we are talking about (left or right), there are “high” and “low” nibbles. Summary : 64 Summary The CPU communicates with the main system chip via a shared set of address and data bus lines. The address lines select the device and location for the data to be transferred on the data bus. The microcontroller provides, in simplified form, most of the features of a conventional microprocessor system on one chip. Summary : 65 Summary The PC consists of data input, storage, processing and output devices. The main unit is a modular system, consisting of the motherboard, power supply, disk drives and expansion cards containing interfacing circuits plugged into the motherboard. The motherboard carries the microprocessor (CPU) chip, RAM module, a BIOS ROM, ISD and keyboard interface. Summary : 66 Summary The microcontroller consist of: CPU Memory Unit Buses Clock (Timer, Watchdog) I/O Modules Serial Communication PWM (Pulse Width Modulation) A/D Converter Summary : Summary PIC Applications: Automotive industries Controlling home appliances Controlling industrial instruments Remote sensors Electric door locks Safety devices Smart cards Many more…………. 67