Embedded System Embedded means something that is attached to another thing. An embedded system can be thought of as a computer hardware system having software embedded in it. An embedded system can be an independent system or it can be a part of a large system. An embedded system is a microcontroller or microprocessor based system which is designed to perform a specific task. For example, a fire alarm is an embedded system; it will sense only smoke.
An embedded system has three components − It has hardware. It has application software. It has Real Time Operating system (RTOS) So we can define an embedded system as a Microcontroller based, software driven, reliable, real-time control system. A real - time operating system (RTOS) is any operating system (OS) intended to serve real - time applications that process data as it comes in, typically without buffer delays.
Current Trends in Embedded Systems Applications An embedded system is an application-specific system designed with a combination of hardware and software to meet real-time constraints. The key characteristics of embedded industrial systems include speed, security, size, and power. The major trends in the embedded systems market revolve around the improvement of these characteristics. To give context into how large the embedded systems industry is, here are a few statistics: The global market for the embedded systems industry was valued at $68.9 billion in 2017 and is expected to rise to $105.7 billion by the end of 2025. In 2015, embedded hardware contributed to 93% of the market share and it is expected to dominate the market over embedded software in the upcoming years as well.
Trends of Embedded Systems Industry Improved Security for Embedded Devices: With the rise of the Internet of Things (IoT), the primary focus of developers and manufacturers is on security. In 2019, advanced technologies for embedded security will emerge as key generators for identifying devices in an IoT network, and as microcontroller security solutions that isolate security operations from normal operations. Cloud Connectivity and Mesh Networking: cloud connectivity tools will be an important future market for embedded systems. These tools are designed to simplify the process of connecting embedded systems with cloud-based services by reducing the underlying hardware complexities.
Trends of Embedded Systems Industry Reduced Energy Consumption: Several solutions are under development for monitoring and reducing the energy consumption of embedded devices that we can expect to see in 2019. These include energy monitors and visualizations that can help developers fine-tune their embedded systems, and advanced Bluetooth and Wi-Fi modules that consume less power at the hardware layer. Visualization Tools with Real Time Data: Developers currently lack tools for monitoring and visualizing their embedded industrial systems in real time. These tools will enable developers to keep a check on key metrics such as raw or processed sensor data and event-based context switches for tracking the performance of embedded systems.
Trends of Embedded Systems Industry Deep Learning Applications: Deep learning represents a rich, yet unexplored embedded systems market that has a range of applications from image processing to audio analysis. Even though developers are primarily focused on security and cloud connectivity right now, deep learning and artificial intelligence concepts will soon emerge as a trend in embedded systems. Embedded System Innovations: The industrial sector for embedded systems is undergoing numerous transformations that will enable developers to build systems that are high-performing, secure, and robust. For 2019, the embedded systems market is shaping up for simplified cloud connectivity, improved security tools, real-time visualizations, lower power consumption, and deep learning solutions.
Introduction of 8051 Microcontroller In 1981, Intel introduced an 8-bit microcontroller called the 8051 . It was referred as system on a chip because it had 128 bytes of RAM, 4K byte of on-chip ROM, two timers, one serial port, and 4 ports (8-bit wide), all on a single chip.
Features of 8051 Microcontroller An 8051 microcontroller comes bundled with the following features − 64K bytes on-chip program memory (ROM) 128 bytes on-chip data memory (RAM) Four register banks 128 user defined software flags 8-bit bidirectional data bus 16-bit unidirectional address bus 32 general purpose registers each of 8-bit 16 bit Timers (usually 2, but may have more or less) Three internal and two external Interrupts Four 8-bit ports,(short model have two 8-bit ports) 16-bit program counter and data pointer 8051 may also have a number of special features such as UARTs, ADC, Op-amp, etc.
Architecture of 8051 Microcontroller
Central Processor Unit (CPU) CPU is the brain of any processing device of the microcontroller. It monitors and controls all operations that are performed on the Microcontroller units. The User has no control over the work of the CPU directly It reads program written in ROM memory and executes them and do the expected task of that application.
Interrupts Interrupt is a subroutine call that interrupts of the microcontrollers main operations or work and causes it to execute any other program, which is more important at the time of operation. An Interrupts gives us a mechanism to put on hold the ongoing operations, execute a subroutine and then again resumes to another type of operations. Generally five interrupt sources are there in 8051 Microcontroller. There are 5 vectored interrupts are INTO, TFO, INT1, TF1, R1/T1 Out of these, (INT0) ̅ and (INT1) ̅ are external interrupts that could be negative edge triggered or low level triggered.
Memory Microcontroller requires a program which is a collection of instructions. This program tells microcontroller to do specific tasks. These programs require a memory on which these can be saved and read by Microcontroller to perform specific operations of a particular task. The memory which is used to store the program of the microcontroller is known as code memory or Program memory of applications. It is known as ROM memory of microcontroller also requires a memory to store data or operands temporarily of the micro controller. The data memory of the 8051 is used to store data temporarily for operation is known RAM memory. 8051 microcontroller 4KB ROM and also 128 bytes of data memory RAM.
BUS Basically Bus is a collection of wires which work as a communication channel or medium for transfer of Data. Address Bus : Microcontroller 8051 has a 16 bit address bus. It is used to address memory locations and to transfer the address from CPU to Memory of the microcontroller. Data Bus : Microcontroller 8051 has 8 bits of the data bus, which is used to carry data of particular applications. Control Bus : Control bus manages the information flow between components indicating whether the operation is a read or a write and ensuring that the operation happens at the right time.
Oscillator microcontroller requires clock pulses for its operation microcontroller 8051 has an on-chip oscillator which works as a clock source for Central Processing Unit of the microcontroller. The output pulses of oscillator are stable. Therefore, it enables synchronized work of all parts of the 8051 Microcontroller.
Input/Output Port Normally microcontroller is used in embedded systems to control the operation of machines in the microcontroller. Therefore, to connect it to other machines, devices or peripherals we require I/O interfacing ports in the microcontroller interface. For this purpose microcontroller 8051 has 4 input, output ports to connect it to the other peripherals
Timers/Counters 8051 microcontroller has two 16 bit timers and counters. These counters are again divided into a 8 bit register. The timers are used for measurement of intervals to determine the pulse width of pulses.
Pin Diagram of 8051 Microcontroller The pin diagram of 8051 microcontroller consists of 40 pins as shown below. A total of 32 pins are set away into four Ports such as P0, P1, P2 and P3. Where, each port contains 8 pins.
Pin description Port 0(p0.0 to p0.7): It is 8-bit bi-directional I/O port. It is bit/ byte addressable. During external memory access, it functions as multiplexed data and low-order address bus AD0-AD7. Port 1 (p1.0 to p1.7): It is 8-bit bi-directional I/O port. It is bit/ byte addressable. When logic '1' is written into port latch then it works as input mode. It functions as simply I/O port and it does not have any alternative function. Port 2 (p2.0 to p2.7): It is 8-bit bi-directional I/O port. It is bit/ byte addressable. During external memory access it functions as higher order address bus (A8-A15).
Port 3(p3.0 to port 3.7): It is 8-bit I/O port. In an alternating function each pins can be used as a special function I/O pin. P3.0-RxD: It is an Input signal. Through this I/P signal microcontroller receives serial data of serial communication circuit. P3.1-TxD: It is O/P signal of serial port. Through this signal data is transmitted. P3.2- (INT0): It is external hardware interrupt I/P signal. Through this user, programmer or peripheral interrupts to microcontroller. P3.3-(INT1): It is external hardware interrupt I/P signal. Through this user, programmer or peripheral interrupts to microcontroller. P3.4- T0: It is I/P signal to internal timer-0 circuit. External clock pulses can connects to timer-0 through this I/P signal. P3.5-T1: It is I/P signal to internal timer-1 circuit. External clock pulses can connects to timer-1 through this I/P signal. P3.6-[WR(bar)]: It is active low write O/P control signal. During External RAM (Data memory) access it is generated by microcontroller. when [WR(bar)]=0, then performs write operation. P3.7-[RD(bar)]: It is active low read O/P control signal. During External RAM (Data memory) access it is generated by microcontroller. when [RD(bar)]=0, then performs read operation from external RAM
XTAL1 and XTAL2:These are two I/P line for on-chip oscillator and clock generator circuit. A resonant network as quartz crystal is connected between these two pin. 8051 microcontroller also drives from external clock, then XTAL2 is used to drive 8051 from external clock and XTAL1 should be grounded. [EA(bar)]/VPP:It is and active low I/P to 8051 microcontroller. when (EA)= 0, then 8051 microcontroller access from external program memory (ROM) only. When (EA) = 1, then it access internal and external program memories (ROMS). [PSEN(bar)]: It is active low O/P signal. It is used to enable external program memory (ROM). When [PSEN(bar)]= 0, then external program memory becomes enabled and microcontroller read content of external memory location. Therefore it is connected to (OE) of external ROM. It is activated twice every external ROM memory cycle.
Example of hardware connection
ALE: Address latch enable: It is active high O/P signal. When it goes high, external address latch becomes enabling and lower address of external memory (RAM or ROM) latched into it. Thus it separates A0-A7 address from AD0-AD7. It provides properly timed signal to latch lower byte address. The ALE is activated twice in every machine cycle. If external RAM & ROM is not accessed, then ALE is activated at constant rate of 1/6 oscillator frequency, which can be used as a clock pulses for driving external devices. RESET: It is active high I/P signal. It should be maintained high for at least two machine cycle while oscillator is running then 8051 microcontroller resets.
Types of Computer Architecture Basically, Microprocessors or Microcontrollers are classified based on the two types of Computer Architecture: Von Neumann Architecture and Harvard Architecture. Von Neumann Architecture or Princeton Architecture is a Computer Architecture, where the Program i.e. the Instructions and the Data are stored in a single memory. Since the Instruction Memory and the Data Memory are the same, the Processor or CPU cannot access both Instructions and Data at the same time as they use a single bus. Harvard Architecture, in contrast to Von Neumann Architecture, uses separate memory for Instruction (Program) and Data. Since the Instruction Memory and Data Memory are separate in a Harvard Architecture, their signal paths i.e. buses are also different and hence, the CPU can access both Instructions and Data at the same time. Almost all Microcontrollers, including 8051 Microcontroller implement Harvard Architecture. Harvard Architecture Von Neumann Architecture
Memory Organization The 8051 Microcontroller Memory is separated in Program Memory (ROM) and Data Memory (RAM). The Program Memory of the 8051 Microcontroller is used for storing the program to be executed i.e. instructions. The Data Memory on the other hand, is used for storing temporary variable data and intermediate results. 8051 Microcontroller has both Internal ROM and Internal RAM. If the internal memory is inadequate, you can add external memory using suitable circuits.
Program Memory (ROM) of 8051 Microcontroller In 8051 Microcontroller, the code or instructions to be executed are stored in the Program Memory, which is also called as the ROM of the Microcontroller. The original 8051 Microcontroller by Intel has 4KB of internal ROM.
In case of 4KB of Internal ROM, the address space is 0000H to 0FFFH. If the address space i.e. the program addresses exceed this value, then the CPU will automatically fetch the code from the external Program Memory. For this, the External Access Pin (EA Pin) must be pulled HIGH i.e. when the EA Pin is high, the CPU first fetches instructions from the Internal Program Memory in the address range of 0000H to 0FFFFH and if the memory addresses exceed the limit, then the instructions are fetched from the external ROM in the address range of 1000H to FFFFH.
There is another way to fetch the instructions: ignore the Internal ROM and fetch all the instructions only from the External Program Memory (External ROM). For this scenario, the EA Pin must be connected to GND. In this case, the memory addresses of the external ROM will be from 0000H to FFFFH.
Data Memory (RAM) of 8051 Microcontroller The Data Memory or RAM of the 8051 Microcontroller stores temporary data and intermediate results that are generated and used during the normal operation of the microcontroller. Original Intel’s 8051 Microcontroller had 128B of internal RAM. But almost all modern variants of 8051 Microcontroller have 256B of RAM. In this 256B, the first 128B i.e. memory addresses from 00H to 7FH is divided in to Working Registers (organized as Register Banks), Bit – Addressable Area and General Purpose RAM (also known as Scratchpad area). In the first 128B of RAM (from 00H to 7FH), the first 32B i.e. memory from addresses 00H to 1FH consists of 32 Working Registers that are organized as four banks with 8 Registers in each Bank.
The 4 banks are named as Bank0, Bank1, Bank2 and Bank3. Each Bank consists of 8 registers named as R0 – R7. Each Register can be addressed in two ways: either by name or by address. To address the register by name, first the corresponding Bank must be selected. In order to select the bank, we have to use the RS0 and RS1 bits of the Program Status Word (PSW) Register (RS0 and RS1 are 3rd and 4th bits in the PSW Register). When addressing the Register using its address i.e. 12H for example, the corresponding Bank may or may not be selected. (12H corresponds to R2 in Bank2). The next 16B of the RAM i.e. from 20H to 2FH are Bit – Addressable memory locations. There are totally 128 bits that can be addressed individually using 00H to 7FH or the entire byte can be addressed as 20H to 2FH.
The final 80B of the internal RAM i.e. addresses from 30H to 7FH, is the general purpose RAM area which are byte addressable. These lower 128B of RAM can be addressed directly or indirectly. The upper 128B of the RAM i.e. memory addresses from 80H to FFH is allocated for Special Function Registers (SFRs). SFRs control specific functions of the 8051 Microcontroller. Some of the SFRs are I/O Port Registers (P0, P1, P2 and P3), PSW (Program Status Word), A (Accumulator), IE (Interrupt Enable), PCON (Power Control), etc.
SRFs Memory addresses are only direct addressable. Even though some of the addresses between 80H and FFH are not assigned to any SFR, they cannot be used as additional RAM area. In some microcontrollers, there is an additional 128B of RAM, which share the memory address with SFRs i.e. 80H to FFH. But, this additional RAM block is only accessed by indirect addressing.
8051 Registers
Types of Registers The 8051 microcontroller contains mainly two types of registers: General purpose registers (Byte addressable registers) Special function registers (Bit addressable registers) The memory which is used for general purpose is called as RAM memory, and the memory used for SFR contains all the peripheral related registers like Accumulator, ‘B’ register, Timers or Counters, and interrupt related registers.
General Purpose Registers The general purpose memory is called as the RAM memory of the 8051 microcontroller, which is divided into 3 areas such as banks, bit-addressable area, and scratch-pad area. The banks contain different general purpose registers such as R0-R7, and all such registers are byte-addressable registers that store or remove only 1-byte of data.
Banks and Registers The B0, B1, B2, and B3 stand for banks and each bank contains eight general purpose registers ranging from ‘R0’ to ‘R7’. All these registers are byte-addressable registers. Data transfer between general purpose registers to general purpose registers is not possible. These banks are selected by the Program Status Word (PSW) register.
PSW (Program Status Word) Register The PSW register is a bit and byte-addressable register. This register reflects the status of the operation that is carried out in the controller. The PSW register determines bank selection by a RS1 and RS0, as shown below. The physical address of the PSW starts from D0h and the individual bits are accessed with D0h to D7h. PSW Registers
Carry Flag (C) : The Address of the Carry flag is D7. This carry flag is affected when the bit is generated from the 7th position. When C=0 carry resets C=1 carry sets Carry Flag Auxillary Flag(AC) : The address of the auxiliary carry is D5. This auxiliary carry is affected when a bit is generated from the 3rd position to the 4th position. AC=0 auxiliary is reset AC=1 auxiliary is set Auxiliary Carry (AC)
Overflow Flag (OV) : The address of the overflow flag is D2. When a bit is generated from the 6th position to the 7th position, then the overflow flag is affected. OV=0 overflow flag resets OV=1 overflow flag sets Overflow Flag Parity Flag (P): The address of the parity flag is D0. While performing arithmetic operations, if the result is 1, then the parity flag is set – otherwise reset. RS1 and RS0 The RS1 and RS0, the bits in PSW register, are used to select different memory location (bank0 to bank4) in the RAM memory.
The following is an example for using this register. The following example demonstrates addition of two numbers and then the storage of final value in the Bank1 register using assembly level program. Org 0000h MOV PSW,#08h MOV A, 15 ADD A, 20 MOV 00h, A END Assembly program to move 6 natural numbers in bank1 register R0-R7 Org 0000h (starting addresses declaration) MOV PSW, #08h (open the bank1 memory) MOV r0, 00h (value send to the bank1 memory) MOV r1, 02h MOV r2, 02h MOV r2, 03h MOV r3, 04h MOV r4, 05h MOV r5, 06h MOV r6, 07h MOV r7, 08h END
Special Function Registers (SFR) Special function registers are upper RAM memory in the 8051 microcontroller. These registers contain all peripheral related registers like P0, P1, P2, P3, timers or counters, serial port and interrupts-related registers. The SFR memory address starts from 80h to FFh . The SFR register is implemented by bit-address registers and byte-address registers. The accumulator, B register, Po, P1, P2, P3, IE registers are bit-addressable register remaining all are byte-addressable registers.
Accumulator The accumulator which is also known as ACC or A is a bit as well as a byte-addressable register by an address of the accumulator. If you want to use a bit-addressable register, you can use a single bit (E0) of the register and you can use an 8-bit of the accumulator as a byte-addressable register. The accumulator holds the results of most Arithmetic and logical operations. The Assembly program for subtraction used with an Accumulator Org 0000h MOV A, #03h (1byte data) SUBB A, 01h (1byte data) END
B-Register The B-register is a bit and byte-addressable register. You can access 1-bit or all 8-bits by a physical address F0h. Suppose to access a bit 1, we have to use f1. The B register is only used for multiplication and division operations. B-Register The Assembly program for multiplication used with a B-Register Org 0000h MOV A, #09h MOV B, #03h MUL A, B (Final value stored in A) END The Assembly program for Division used with a B-Register Org 0000h MOV A, #09h MOV B, #03h DIC A, B (Final value stored in A) END
Microcontrollers 8051 Input Output Ports All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which can be configured as inputs or outputs. Accordingly, in total of 32 input/output pins enabling the microcontroller to be connected to peripheral devices are available for use. Pin configuration, i.e. whether it is to be configured as an input (1) or an output (0), depends on its logic state. In order to configure a microcontroller pin as an output, it is necessary to apply a logic zero (0) to appropriate I/O port bit. In this case, voltage level on appropriate pin will be 0. Similarly, in order to configure a microcontroller pin as an input, it is necessary to apply a logic one (1) to appropriate port.
Port 0 Port 0 occupies a total of 8 pins (pins 32-39) .It can be used for input or output. Port-0 can be used as a normal bidirectional I/O port or it can be used for address/data interfacing for accessing external memory. When control is ‘1’, the port is used for address/data interfacing. When the control is ‘0’, the port can be used as a bidirectional I/O port.
Port 1,2 &3 Port 1: P1 is a true I/O port and can be configured as general I/O only. It has a pull-up resistor built-in and is completely compatible with TTL circuits. Port 2: P2 acts similarly to P0 when external memory is used. When no memory is added, this port can be used as a general input/output port showing features similar to P1. Port 3: All port pins can be used as general I/O, but they also have an alternative function. In order to use these alternative functions, a logic one (1) must be applied to appropriate bit of the P3 register.
8051 timer/counter
What is a Timer? Why to use them? Timer is a clock that controls the sequence of an event while counting in fixed intervals of time. A Timer is used for producing precise time delay. Secondly, it can be used to repeat or initiate an action after/at a known period of time. This feature is very commonly used in several applications. An example could be setting up an alarm which triggers at a point of time or after a period of time.
Counter and Timers The 8051 has two timers: timer0 and timer1. They can be used either as timers or as counters. Both timers are 16 bits wide. Since the 8051 has an 8-bit architecture, each 16-bit is accessed as two separate registers of low byte and high byte.
Timer0 Timer0 registers is a 16 bits register and accessed as low byte and high byte. The low byte is referred as a TL0 and the high byte is referred as TH0. These registers can be accessed like any other registers.
Timer1 Timer1 registers is also a 16 bits register and is split into two bytes, referred to as TL1 and TH1.
Starting or stopping a Timer For every Timer, there is a corresponding Timer control bit which can be set or cleared by the program to start or stop the Timer. TR0 and TR1 are the control bits for Timers 0 and 1 respectively. Setting the control bit would start the Timer. TR0 = 1; starts Timer 0 TR1 = 1; starts Timer 1 Clearing the control bit would stop the Timer. TR0 = 0; stops Timer 0 TR1 = 0; stops Timer1
TMOD (timer mode) Register This is an 8-bit register which is used by both timers 0 and 1 to set the various timer modes. In this TMOD register, lower 4 bits are set aside for timer0 and the upper 4 bits are set aside for timer1. In each case, the lower 2 bits are used to set the timer mode and upper 2 bits to specify the operation.
TMOD (timer mode) Register
GATE Timers of 8051 do starting and stopping by either software or hardware control For using software to start and stop the timer where GATE=0 The start and stop of the timer are controlled by way of software by the TR (timer start) bits TR0 and TR1 The SETB instruction starts it, and it is stopped by the CLR instruction These instructions start and stop the timers as long as GATE=0 in the TMOD register The hardware way of starting and stopping the timer by an external source is achieved by making GATE=1 in the TMOD register
Mode 1 Programming The following are the characteristics and operations of mode1: It is a 16-bit timer It allows value of 0000 to FFFFH to be loaded into the timer’s register TL and TH After TH and TL are loaded with a 16-bit initial value, the timer must be started This is done by SETB TR0 for timer 0 and SETB TR1 for timer 1 After being started, it starts to count up It counts up until it reaches its limit of FFFFH
Mode 1 Programming (cont.) When it rolls over from FFFFH to 0000, it sets high a flag bit called TF (timer flag) Each timer has its own timer flag: TF0 for timer 0, and TF1 for timer 1 This timer flag can be monitored When this timer flag is raised, one option would be to stop the timer with the instructions CLR TR0 or CLR TR1, for timer 0 and timer 1, respectively In order to repeat the process TH and TL must be reloaded with the original value TF must be reloaded to 0
Steps to Mode 1 Program Load the TMOD value register Indicating which timer (timer 0 or timer 1) is to be used and which timer mode (1 or 2) is selected Load registers TL and TH with initial count value Start the timer Keep monitoring the timer flag (TF) With the JNB TFx,target instruction to see if it is raised
Steps to Mode 1 Program (cont.) Get out of the loop when TF becomes high Stop the timer Clear the TF flag for the next round Go back to Step 2 to load TH and TL again
If TH and TL are not reloaded. the program generates a single pulse.
Finding the Loaded Timer Values To calculate the values to be loaded into the TL and TH registers: Assume XTAL = 11.0592 MHz Divide the desired time delay by 1.085 us Perform 65536 – n, where n is the decimal value we got in Step1 Convert the result of Step2 to hex, where yyxx is the initial hex value to be loaded into the timer’s register Set TL = xx and TH = yy
CPL P1.5 ; Comp. P1.5 to get Hi, Lo
CPL P2.3 ; Comp. P2.3 to get Hi, Lo CLR TF1 ; Clear timer 1 flag SJMP AGAIN ;Reload timer
Mode 2 Programming The following are the characteristics and operations of mode 2: It is an 8-bit timer It allows only values of 00 to FFH to be loaded into the timer’s register TH After TH is loaded with the 8-bit value, the 8051 gives a copy of it to TL Then the timer must be started This is done by the instruction SETB TR0 for timer 0 and SETB TR1 for timer 1
Mode 2 Programming (cont.) After the timer is started, it starts to count up by incrementing the TL register It counts up until it reaches its limit of FFH When it rolls over from FFH to 00, it sets high the TF (timer flag) When TF is set to 1, TL is reloaded automatically with the original value kept by the TH register To repeat the process, we must simply clear TF and let it go without any need by the programmer to reload the original value
Mode 2 Programming (cont.) Mode 2 can auto-reload, in contrast with mode 1 in which the programmer has to reload TH and TL
Steps to Mode 2 Program Load the TMOD value register Indicating which timer (timer 0 or timer 1) is to be used, and the timer mode (mode 2) is selected Load the TH registers with the initial count value Start timer Keep monitoring the timer flag (TF) With the JNB TFx,target instruction to see whether it is raised
Steps to Mode 2 Program (cont.) Get out of the loop when TF goes high Clear the TF flag Go back to Step 4 Since mode 2 is auto-reload
The number 200 is the timer count till the TF is set to 1 (253)
Counter Programming Timers can also be used as counters Counting events happening outside the 8051 A pulse outside of the 8051 increments the TH, TL registers TMOD and TH, TL registers are the same as for the timer Programming the timer also applies to programming it as a counter Except the source of the frequency The C/T bit in the TMOD registers decides the source of the clock for the timer
Counter Programming (cont.) When C/T = 1, the timer is used as a counter and gets its pulses from outside the 8051 The counter counts up as pulses are fed from pins 14 and 15 These pins are called T0 (timer 0 input) and T1 (timer 1 input)
TCON Register TCON (timer control) register is an 8-bit register
TCON Register (cont.) TCON register is a bit-addressable register
Case of GATE = 1 The start and stop of the timer are done externally through pins P3.2 and P3.3 for timers 0 and 1, respectively Allows to start or stop the timer externally at any time via a simple switch
Serial communication Microcontrollers need to communicate with external devices such as sensors, computers and so on to collect data for further processing. Data communication generally done by means of two methods : Parallel and Serial mode. In the parallel mode data bits are transferred in a fast manner using more number of lines. But when comes to a Microcontroller system, we cannot afford to dedicate many lines for data transfer. So UART or Serial communication in 8051 microcontroller will allow the controller to send and receive data’s just by using two pins Serial Communication uses only two data lines to establish communication between Microcontroller and external devices. In this communication data bits are transferred one bit at a time, so the process will be slow.
RS232 AND MAX232: To establish communication between a controller and PC, we must use a serial I/O standard RS-232 which was widely used in PC and several devices. PC works on the RS-232 standards which operates at a logic level of -25V to +25V. But Microcontrollers use TTL logic which works on 0-5V which is not compatible with the RS-232 standards. MAX232 is a specialized IC which offers intermediate link between the Microcontroller and PC. The transmitters of this IC will convert the TTL input level to the RS-232 Voltage standards. Meanwhile the receivers of this IC will convert RS-232 input to 5V TTL logic levels.
SCON REGISTER: SCON is a bit addressable register is used to set the mode in which the serial communication takes in the controller. The above figure shows the configuration of the SCON register. The functions of each bit are listed below.
SM0, SM1: Serial Mode control Bits SM2: Multiprocessor mode control bit, logic 1 enables Multi processor mode and 0 for normal mode. REN: Enables Serial reception. If set it enables the reception, otherwise the reception is disabled. TB8: It is the 9th bit of the data that is to be transmitted. RB8: It is used in modes 2 and 3, it is the 9th bit received by the microcontroller. TI: It is known as Transmit Interrupt flag which is set by the hardware to indicate the end of a transmission. It has to be cleared by the software. RI: It is known as Receive Interrupt flag which is set by the hardware to indicate the end of a reception. It has to be cleared by the software. SCON REGISTER:
BAUD RATE: It is defined as number of bits transmitted or received per second and usually expressed in Bits per second bps. For mode 0 and mode 2 the baud rate is determined by means of 1/12, 1/32 or 1/64 of the crystal frequency whereas for mode 1 and 3 it is determined by means of timer 1 Baud Rate by Timer1
SBUF REGISTER: It is a 8 bit register that holds the data needed to be transmitted or the data that is received. The serial port of the 8051 is full duplex so the microcontroller manages to transmit and receive data into the register simultaneously.
Power Mode control Register (PCON) Register PCON controls processor power down, sleep modes and serial data baudrate . Only one bit of PCON is used with respect to serial communication. The seventh bit (b7)(SMOD) is used to generate the baud rate of serial communication. Address: 87H SMOD: Serial baud rate modify bit GF1: General purpose user flag bit 1 GF0: General purpose user flag bit 0 PD: Power down bit IDL: Idle mode bit
Data Transmission: Transmission of serial data begins at any time when data is written to SBUF. Pin P3.1 (Alternate function bit TXD) is used to transmit data to the serial data network. TI is set to 1 when data has been transmitted. This signifies that SBUF is empty so that another byte can be sent. Data Reception: Reception of serial data begins if the receive enable bit is set to 1 for all modes. Pin P3.0 (Alternate function bit RXD) is used to receive data from the serial data network. Receive interrupt flag, RI, is set after the data has been received in all modes. The data gets stored in SBUF register from where it can be read.
Serial Data Transmission Modes:
Bit time= 1/ f baud In receiving mode, data bits are shifted into the receiver at the programmed baud rate. The data word (8-bits) will be loaded to SBUF if the following conditions are true. RI must be zero. (i.e., the previously received byte has been cleared from SBUF) Mode bit SM2 = 0 or stop bit = 1. After the data is received and the data byte has been loaded into SBUF, RI becomes one. Serial Data Transmission Modes