0% found this document useful (0 votes)
35 views82 pages

EIOT Upto 3unit

Uploaded by

Kaviya S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
35 views82 pages

EIOT Upto 3unit

Uploaded by

Kaviya S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 82
SYLLABUS ve €S3691 EMBEDDED SYSTEMS AND IOT "UNIT I 8-BIT EMBEDDED PROCESSOR 8-Bit Microcontroller — Architecture - Instruction Set and Programming — Programming Parallel Ports - Timers and Serial Port - Interrupt Handling, UNIT II EMBEDDED C PROGRAMMING Memory And 1/O Devices Interfacing ~ Programming Embedded Systems i C- Need For RTOS - Multiple Tasks and Processes - Context Switching - Priority Based Scheduling Policies. UNIT III IOT AND ARDUINO PROGRAMMING Introduction to the Concept of IoT Devices - IoT Devices Versus Computers = IoT Configurations — Basic Components ~ Introduction to Arduino ~ Types “of Arduino - Arduino Toolchain ~ Arduino Programming Structure - Sketches = Pins — Input/Output From Pins Using Sketches ~ Introduction to Arduino Shields - Integration of Sensors and Actuators with Arduino. Communication Models and APIs - loT Communication Protocols - tooth = WiFi ~ ZigBee ~ GPS - GSM modules — Open Platform (like ing ~ Accessing GPIO ~ Connecting to the of Embedded Systems — Develo, pment of ion — Smart Agriculture ~ Smart IoT Applications Cities ~ smart Healthcare. UNIT-I: 8 BIT EMBEDDED PROCESSOR .. Introduction to Embedded Systems Ll 12 13 “14 2 3 12.1 1.22 Instruction Set and Programming 1.4.1 Data Transfer Instructions. 1.4.2 Arithmetic Instructions 1.4.3 Logical Instructions. 1.4.4 Logical Instructions 1.4.5. Boolean or Bit Manipulation Instructio 1.4.6. Program Branching Instructions 1.4.7, Instructions and Progranis 1.4.8 BCD Number System CONTENT Key Characteristies of Embedded System Applications of Embedded System Oscillator and Clock ‘Address, Data & Control Bus a Embedded Systems and lor C2 1,5 Programming Parallel Ports... Port 0 Port Port 2 Port . es 1.5.5 Programming the Ports of 8051 1.6 Timers and Serial Port . 1.6.1. Timers... 1 Timer Mode 1.6.1.2 Counter Mode 1,3 TMOD Register 1.6.2. Serial Port 1.6.2.1 Seri 1.6.2.2 RS 232 Standards 1.6.2.3 MAX232. 1.6.2.4 8051 Ser Interrupt Handling... ‘Communication Port Programming. LT 1.7.3. Interrupt Priority Register (IP). UNIT-II : EMBEDDED C PROGRAMMING .... 2.1 Memory and 1/0 Devices Interficing . 2.1.1 Memory Interfacing. 2.1.2 UO Devices Interfacing 2.1.2.1 LED - Light Emitting Diode... 2.1.2.2 7—Segment Display. .2 Programming Embedded Systems in C .3\. Need for RTOS. Content C3 (eh a ee 2.4 Multiple Tasks and Mi 2.4.1 Task: 2.4.2 Processes le Processes... 2.5. Context Swi ; 2.6 Priority Based Scheduling Policies.... 2.6.1. Preemptive Priori 2.6.2 Non Preemptive Priority Schedul UNIT- III: IOTAND ARDUINO PROGRAMMING. 3.1 Introduction to loT Devices. 3.1 3.1.2 3.13 3.1.4 Challenges and Considerations .. 3.1.5 ToT Devices Vs. Computers: Introduction to Computers Understanding IoT Devices Funk jonality and Purpose .. Computing Power and Resources .. 32 Distributed 1oT Configuration Edge Computing Configuration. Hybrid loT Configuration.. Considerations for loT Configurations.. & Embedded Systems and lor 3,3. Components of loT 33.1 Introduction to loT Components 33.2. Sensofs and Actuators 33.3. Connectivity Technologies 33.4 DataProcessing and Analyti 3.3.5. Communication Protocols 3.3.6 Security and Privacy Measure 3.4 Introduction to Arduino.. 3.4.1 Examining the Arduino Ar 3411 tecture ‘The ATmega AVR Microcontt 35 3.5.2 Arduino Mega 3.33. Arduino Micro 3.5.4 Arduino Leonard. 3.55. Arduino Nano..... 3.5.6 » Arduino Due 3.5.7 Arduino Pro Mini 3.5.8 Arduino Esplora.. 3.5.9 Arduino Yon 3.5.10 Arduino Ethemet. 3.6 37 3.8 Introduction to Arduino SI 3.8.1 Exploring Arduino Shields 3.8.2 Connecting with the Ethemet Shield... content 3,9 Arduino program structure and execution-sketche: 3.10 VO pin setuy 3.10.1 Comy 3.10.2 Commonly used in-b ling, Loading and Running a Sketch . C Sketch Functions 3.11 Input/Output from pins using sketches... UsingaS 3.11.2 Usinga Switch 43.12. Integration of sensors and Actuators with Arduino Interfacing of a humidity and temperature sensor with your Arduino boar 3.12.2 Integration of a Motor Based Actuator. UNIT- IV : IOT COMMUNICATION AND OPEN PLATFORMS ..4.1 ~ 4.63 4.1 10T Communication Models and API IOT Communication Models 2. WebSocket-based commu 4.2. 10T Communications protocols: 4,3 Bluetooth 4.3.1 Bluetooth Architecture 4.3.2 Bluctooth Protocol 44 WiFi 44.1 IEEE 802.11 Architecture 4.4.2. Frame Format of IEEE 80: 4.4.3 IEEE 802 Protocol Architecture 4.4.4 IEEE 802.11 Serviees.. Embedded Systems and toy coe ES ‘Types of ZigBee Devices General Characteristics of Zigbee Standard .. Operating Frequency Band Zigbee Topologies. Zigbee protocol architecture 4.5.6 Zigbee Addressing Mode... 4.6 Comparison of Zigbee, Bluetooth, and Wi 4.7 Raspberry’ 4.8 Raspberry Pi Architecture. 4.9 Accessing Raspberry Pi’s GPIO 4.40 441 483 443 oo 448 oe 48 4.49 4.53 4.10. Raspberry Pi interfaces. 4,11 Sending and Receive signals using GPIO pis. 4.12. Programming Raspberry Pi with Python .. 4.12.1 Controlling LED with Raspberry] 4.12.2 Interfacing an LED and switch with Raspberry Pi 4.12.3 Interfacing a Light Sensor (LDR) 4.13 Connecting to the cloud 4.14 The GSM module 4.14.1 Extended Coverage GSM for Internet of Things 458 4.15 Global Positioning System 4.60 UNIT-V: APPLICATIONS DEVELOPMEN 1-524 5.1 Complete Design of Embedded Systems ‘What Is an Embedded System? An Introduction to Embedded Systems Ai 3. The Embedded Systems Model... lopment of loT App! Content pect 5.3 HomeAutomationusingloT 5.3.1 Appl 5.3.2. Home Automation Component ions ofhome automat 5.3.3 Home Automation Protocol 5.3.4 Home Automation: Which Protocol is the Best? 5.3.5 Home Auto: 5.3.6 Home Auto: 5.3.7 Home Auto: 5.4 Smart Agriculture 5.4.1 What is Smart Agriculture? 5.4.2 Howto Utilize Al for Yield Predi ‘Two Marks Question and Answer ‘Model Question Paper A) 8 BIT EMBEDDED PROCESSOR 7 INTRODUCTION TO EMBEDDED SYSTEMS 4.4.1 Definition ‘An embedded system is a specialized computer system designed to perform specific integration into a larger designed to perform dedicated tasks and often operates in e, meaning it must respond to inputs and produce outputs within strict time constraints. ‘The hardware components of an embedded system typically include a microcontroller ‘or microprocessor, memory, input/output interfaces, and various sensors and actuators. ‘The software running on the embedded system is responsible for controlling the hardware, executing specific tasks, and interacting with the larger system. Figs1.1 Embedded Systems Embedded Systems and IoT 12 ted resources (e.t. ime responsiveness, ints during the design and nemory, ‘has. [Embedded systems often have constraints suc processing power), power efficiency requirements, and re Therefore, developers need to careful phases to meet the system's speci y consider these const ns. 4.4.2 Key Characteristics of Embedded System “The key characteristics of embedded systems include: ed resources: Embedded systems often have ‘memory, storage, and energy resources compared to general-purpose computers, in these constraints ‘They are designed to operate efficiently wit 4, Hardware-softwar of hardware and software components. The software is specifically lowing for optimal integr developed to run on the embedded hardware platform, performance and efficiency. 5. Reliability; Embedded systems often need to operate reliably over extended periods without failures. They are built with robustness and fa stable operation. 1.1.3 Applications of Embedded System Embedded systems can be found ina wide range of appl electronics, automotive systems, medical devices, industrial automation, aerospace and defense systems,and more. They are used to control and monitor vari - embedded Processor 13 Examples of embedded systems include microcontrollers in household ap e pacemakers, industrial \s ‘automotive engine control units (ECUs), medical devices ess control systems, and smart home automa n syst proc ‘of systems and devices. They br ions, contributing to enhanced ef a 72 6-BIT MICROCONTROLLER 1.2 B-BIT MICROCONTROUER ler is a type of microcontroller that has an 8- fed circuit that combines a microprocessor core, memory, and various peripherals. he width ofthe data bus, which determines >. The 8-bit designation refers the size of data that can be processed by the microcontroller ina single operation. 4.2.1 8051 Microcontroller versati sophisticated real provides extra features like interrupts, bit addressability, ‘and computer peripherals. very powerful and cost effective. ‘and anenhanced set of instructions which make the 1.2.2 Features of 8051 Microcontroller + sbi CPU +) On-chip oscillator + 4KBof ROM (Program memory) + 128 bytes of RAM (Data memory) + 21 Special function registers 32 1/0 lines (Ports PO to P3) Embedded Systems and IOT 15 g Bit Embedded Processor is.embedded Processor G4 KB address space for external data memory « 4.3.4 CPU Core «G4 KBaddress space for program memory : Y Accumulator: The 8051 has a single 8. itaccumulator (ACC) used for arithmetic ter A, is used for all arithmetic and ofeach calculation main memory. Accesso ke the accumulator because the main memory is slower than access toa registe : technology used forthe large main memoryis slower (but cheaper) than the technology 7.3 ARCHITECTURE sture of the 8051 microcontt thas separate program memory and data memory. - banl used fora register. ide Register Banks/ The “R” Registers: . A total of 32 bytes of RAM are set for the register banks and the stack. These 32 bytes are divided into fourregister which each bank has 8 registers, RO-R7. RAM locations from 0 to 7 are ide for bank 0 of RO-R7 where RO is RAM location 0, R1 is RAM location set extemal 1, R2is location 2, and so on, until the memory location 7, which belongs toR7 of * oncnP ee bank 0:The 8051 has four register banks (RO-R7), each containing eight 8-bit general- ose ORAM purpose registers. These registers function as auxiliary or temporary storage registers (akoytes) (126 oon) in many operations. : Tntemal bus. 127 7FH t Direct 8a 20 ee peal addressing. 7 (Bi TT TT mr hres PFT urpieres 9 PT FP PS 2480 oH - dataladdress nl aun Higher orde J L, Register 16 B9 0 Ke ormay 1.0562 Mz biger ede al etona eae 104 7 Bank 4 ig: 1.2 Architecture of 8051 Microcontrol ler 7 Bank 0 9 Ro____toont The architecture of the 8051 microcontroller is based on the Harvard architecture. Which means it has separate program memory and Fig:1.3 Register Bank of 8051 Microcontroller Embedded Systems and IoT yp ere v B~Register: The “B” it may hold an 8- bi -pisteris very si byte) value. The instructions: MULAB and DIV AB, To quickly and e another number, you may store the other number in’ instructions. Apart from using MUL and DIV instr used as yet another temporary storage register, much to the Accumulator in the sense that is used only by two 8051 Data Pointer (DPTR): The Data Pointer (DPTR) is the 8051's only user-accessible 16-bit (2-byte) register. The Accumulator, RO-R7 rej 1 -byte registers. DPTR is meant for poi access external memory using the addre: rs and B register are used by the 8051 to indicated by DPTR. DPTR is the only 16-bit register available and is often used to store 2-byte values. ng to data. It Arithmetic Logic Unit (ALU): It performs arithmetic and logical operations on data stored in the accumulator or other registers. Program Status Word (PSW): Bit no. 7 6 5 4 3 2 1 oO Psw ey | ac | Fo [ rst | rso [| ov | x P P= Odd Panty Flag FO = User Flag 0 St Rso 0 0 bank 0 0 1 bank 4 1 ° bank 2 1 1 bank 3 information about the current ‘State of the ALU operation of microcontroller and influences Here are the components of the PSW in the 805 1 architecture: £ g Bit Embedded Processor 7 1), (Carry Flag (CY): The Carry flag is used to indicate carry or borrow conditions during arithmetic and logical operations. I ccan be used form set when a carry or borrow occurs and te arithmetic operations. 2. Auxiliary Carry Flag (AC): The Auxiliary Carry flag is used in BCD (Binary Coded Decimal) arithmetic operations. It indicates acary from bit 3 to bit 4 during addition ‘ora borrow from bit 4to bit3 during subtraction. 3, Overflow Flag (OV): The Overflow flagis used to indicate signed arithmetic overflow conditions. Itis set when the result ofa signed arithmetic operation exceeds the range of asigned value. 4. Parity Flag (P): of the last operat i Parity flag indicates the party of the accumulator or the result set ifthe number of set bits in the accumulator or the result is odd, is even and cleared if 5, Register Bank Select (RSI and RS0): The Register Bank Select bits are used to select one of the four register banks in the 8051 microcontroller. The register bank determines which set of eight registers (RO-R7) is currently accessible. 6. User flag 0 Bit (F0): The User-defined bit can be used by the programmer for any purpose. They can be set or cleared as needed. ‘The PSW register can be accessed like any other register in the 8051 microcontroller. Instructions are available to manipulate the individual bts or the entire PSW register. For example, the INC (Jump if No Carry) instruction can be used to conditionally jump based on the state of the Carry flag. “The PSW is essential for managing control flow, arithmetic operations, and decision- ‘making in the 8051 microcontroller. Itallows programmers to react to various conditions and take appropriate actions based on the status flags and control bits it provides. ¥ Program Counter (PC): The Program Counter (PC) isa register to store a2-byte address which tells the 8051 where from the next instruction to be executed can be found (in the memory). PC starts at 0000h when the 8051 initializes and is incremented every time after an instruction is executed. P by 1. Some instructions may require 2 or 3 byte: isnotalways incremented such eases, the PC will be incremented by 2 or 3. 7 embedded Systems aid joy 18 , i peas oad the Program Counter Wihan adres gg Not power-onsest will ause al values ng Cis 0 upon eset, foreing the CPU to fetch y, means we mst place the fist byte of opcode, CPU expectsto find the first instruction Activating a than the next sequential locati register tobe lost. Itmeans the value of the first opcode from the ROM location 0000. I ROM location 0000 because that is where the ‘except DPTR and PC, may hold an 8-bi ‘rand can address memory addresses of range OOH to FFH. When the conten led a PUSH operation. When thy called a POP operation, content ofa stack is stored in a CPU register, “The Stack Pointer tells the location from where the next value is to be removed fiom the stack. When a value is pushed onto the stack, the -value of SP is incremented and then, the value is stored at the resulting memory location. When a value is popped off the stack, the value is returned from the memory location indicated by SP, and then the value of SPis decremented. This order of operation is important. SP will be initialized. Ifa value is pushed onto the stack at the the internal RAM address 08H because the 8051 (Grom 07H to 08H) and then will store the pushed value at that memory address (08H) ‘SPis modified directly by the 8051 by six instructions: PUSH, POP, ACALL, LCALL, RET, and RETI. It points to the top of the stack, used for storing return addresses and local variables during subroutine calls. . 1.3.2 Memory Internal RAM: The 8051 has 128 bytes of on-chip RAM (Internal RAM) fo: storing data and variables, Internal Program Memory: The 8051 has 4 KB of on-chip ROM or flash memon} an aha ares the program instructions. This memory Scat Program even when power is tamed off. _ ny: The 8051 can access up to 64 KB of external data memory nal storage requirements, lized to 07H when the 80: the value will be sto first increment the value of SP ¥ g Bit Embedded Processor 19 ea SSSS——SSSS _ 9 1.3.3 VO Ports The 8051 microcontroller has four 8-1 ional I/O ports (Port 0, Port 1, Port 2, Port 3) that can be used to interface with external devices. Each port pin can be ‘configured as an input or output, 1.3.4 Timers/Counters ‘The 8051 has two 16-bit timers/counters (Timer O and Timer 1) that can be used for various timing and counting applications. The timers can operate indifferent modes, including timer mode, counter mode, or asa baud rate generator for serial communication. 1.3.5 Serial Communication ted UART (Universal ‘The 8051 supports serial commur tocommunicate with Asynchronous Receiver/ Transmitter other devices using asynchronous serial protocols. 1.3.6 Interrupts ‘The 8051 supports both external and internal interrupts. It has five interrupt sources that can be individually enabled or disabled. When an interrupt occurs, the microcontroller the corresponding interrupt service routine, transfers cont 1.3.7 Oscillator and Clock XTALI GND Fig:1.4 Clocking circuit of 8051 Microcontroller Embedded Systems and 1oy 111 it - Bit Embedded Processor requires an external ental or ck source foritsoperatig, SLE A CCC generate the system clock, The 7 Data Transfer Instructions or pins XTALI and XTAL2 which are provided for connecting hhavinga frequency range from I MHZ to Logical Instructions ¥ Boolean or Bit Manipulation Instructions ¥ Program Branching Instructions 8051 has on chip osci resonant network to from an oscillator crystal 24 MHZ. 1.3.8 Address, Data & Control Bus DATA | ARITHMETIC | LOGICAL | BOOLEAN] PROGRAM ‘The address bus in 8051 microcontrollers is consisting of 16-bit address lines which IrRANSFER| BRANCHING carrie the 16-bitaddresses of memory locations. is generally be used for transfering © | ADD ANE GR MP the data from Central Processing Unit to Memory. The 16-bit address bus ae 2 Move ape aan an an 64K (2°16) memory space and a separate 64K byte of data memory space. Whilethe | 0.) cane a Row SIMP data bus in 8051 microcontrollers is consisting of lines which carries data PUSH INC cunt Ic Z between processor and other components. Data bus is bidirectional. The control bus BOP Bee con INC JNZ manages the information flow between various components (ALU, registers, memory, | yy mae mC a ONE VO etc.) indicating whether the operation is a read or a write and ensuring that the — | yyy) Di RLC INB DINZ operation happens at the right time. x DAA RR JBC NOP 7.4 INSTRUCTION SET AND PROGRAMMING RRC ANL LCALL ‘ . SWAP ORL ACALL ‘To perform any task by a microprocessor or a microcontroller it is to be programmed con Har: using specific instructions from its set. Writing a program for any microcontroller is nothing RETI but giving a set of commands to the microcontroller in particular order in which they se must be executed in order to perform a specific task. These commands to the 4.4.1 Data Transfer Instructions ‘The Data Transfer Instructions are associated with transfer of data between registers orexternal program memory or external data memory. The Mnemonics associated wi computer or microcontroller. 8051 microcontrollers instruction setis also known as M ‘of 8051microcontrollers use 8. Data Transfer are given below. v MOV instruction set can be up to 28 = 256 instruct ions. However, depending upon the types of vy MOVC instructions (groups) and addressing modes there 49 instruction Mnemonics in the 8051 y¥ MOVX Microcontroller. These 49 Mnemonics are divided into five groups, aoa Based on theo they perform, all the instructions inthe 8051 Microcontrollet feel : Instruction Set are divided into five groups. They are: Bes 0H ¥ XCHD £& Embedded Systems and Ioy 112 ‘it Embedded Processor aa Mnemonic Description F Memonic] Instruction Description ‘Adaressing] Not | No. of] ‘MOV Move Data Mode _| Bytes | Cycles Movc Move Code be DPTR Immediate | 3 2 Mocx Move External Data #Datal6 #Datal6 PUSH. Move Data to Stack jOVC | A@A+ A€ Code pointed Indexed | 1 2 POP Copy Data from Stack DPTR by A+DPTR XCH Exchange Data between two Registers A@A+PC | A'-Code pointed | Indexed | 1 2 XCHD Exchange Lower Order Data between two Registers by AHPC “The following table lists outall the possible data transfer instructions along with A@Ri ‘A OL A, #Data A©AORData__| Immediate | 2 | 1 A.Rn ‘A CAORRn Register | 1 | 1 + RL A,Direct_| A AOR (Direct) | Direct Zt + RLC . A.@Ri ACAt@Ri indirect | 1] 1 fa Direct, A | Direct) < (Direct) OR] — Direct Zag] 2 A + RRC Direct,#Data | (Direct)<—(Direct) OR | Direct a] a + SWAP #Data XRL, ata 5 cae Dacription A, #Dat AAXRLData_| Immediate | 2 | 1 A.Rn AC AXRLRa Register | 1 [7 ANL Logical AND ‘A.Direct_| A (SP);ADDR16 - PC LCALL, TCALL | ADDRIG Tong Subroutine call 3 2 ACALL PC+3-9(SP); ADDRI6->PC ET jun tine ae f Ri Return from subrout T 2 > (SP) > PC : RET ;RETI = Return from Interrupt 1 2 + IMP ~AmMP_[ADDRI_ + Absolute JumpADDRI6 —> PC 2 2 fiuaaiar UMP [ADDRI6_|~_Long JumpADDRIG > PC 3 z SUMP Short Jump PC+2+rel—>PC 2 2 LIMP IMP ‘A+DPTR->PC T z ‘AJMP > ‘Absolute Jump (Uncons | [gaz TFA=0, Jump to PC +rel z Z IMP Short Jump (Unconditional) INZ TFA #0, Jump to PC+el 2 Sang fA oqaal 06 | CINE |A, Direct, rel, | Compare (Direct) withA, 3 2 INZ Jump ifAisnot equal to0 | A, Data, rel Compare # Data with A, 3 z CINE Compare and Jump if Not Equal | Jump to PC +rel if not equal DINZ Decrement and Jump ifNot Zero | A, Data, rel Compare #Daa ya Ro s Z Jump to PC +rel if not equal ‘NOP No Operat oe K, Data, | rel Compare #Data with @Ri, > | 2 Lea Jump to PC +rel if not equal ACALL Absolute Cal to Subroutine (Unconditional) DINZ |~ Rayrel Department Rn, 2] 2 RET Retum from Subroutine Jump to PC +relif not Zero RETI ‘Retum from Interrupt Direct, rel Department (Direct) , 3 2 fae ; Jump to PC+ rel ifnot Zero lump oan Address (Unconditional) NOP No Operation 7 T dded Systems and Ioy am ee 4.4.7 Instructions and Programs Arithmetic Instructions Addition of Unsigned Numbers =A+ source ADDA, source ; ‘The instruction ADD is used to add two operands nn operand isalways in register fate data, or in memory + Desting + Source operand can be a register, immedi operations are never allowed in 805) + Memory-to-memory arithmet Assembly language ceris affected by the following instruction show how the flag rey MOVA,#0FSH ;A=FS hex ADDA,#0BH sA=F5+0B=0 Solution: FSH. 1111 0101 00001011 0000 0000 & 2. Assume that RAM locations 40— 44H have the following values. Write a program to find the sum of the values. At the end ofthe program, register A shiould contain the | low byte and R7 the high byte. Solution: 40 =(7D) 41 =(EB) 42=(C5) 43 = (5B) 44=(30) f it Embedded Pr. Mov RO,#40HR2, #5 load pointer Mov A sload counter CLR caso ee Mov RIA selear R7 's AGAIN: ADD A,@RO add the byte ptrto by RO ie INC NEXT CY=0don'tadd carry ¢ INC R7 skeep track of carry NEXT: INC RO increment 0 pointer DINZ.R2, AGAIN; repeat until R2 is \ zero cea ADDC and Addition of 16- Bit Numbers a + When adding two 16-bit data operands, the propagation ofa carry from lowe? byte to higher byte is concerned When the first byte is added (E7+8D =74, CY =1). 3c £7 + 3B_8D ‘The carry is propagated to the 7874 higher byte, which result in 3C+3B+1=78 (all in hex) 1.4.8 BCD Number System ¥ — The binary representation of the digits 0 to 9 is called BCD (Binary Coded Decimal) + Unpacked BCD + In unpacked BCD, the lower 4 bits of the number represent the BCD number, and the rest of the bits are 0 + Ex, 00001001 and 00000101 are unpacked BCD for 9 and $ + Packed BCD + Inpacked BCD, a single byte has two BCD number in it, one in the lower the upper 4 bits packed BCD for 59H 4 bits, and one + Ex.0101 1001 nisin 9487 Embedded Systems andig, | 126 Digit gy2) 8H2) | 0 pool errs | I go10 1000 2 coll il | ool 3 2 F a vs 5 91d | 6 pool | 7 | 8 1000 9 1001 ¥? Adding two BCD numbers must give a BCD result v Mov AK, #17 ADD A,#28H ‘Adding these two number ¥ Theresult about should have been 17+28=45 (01000101). To correct this problem, | the programmer must add 6 (0110) to the low di DA Instruction DAA; decimal adjust for addition + TheDA instructi with BCD addition + TheDA instruction will add 6 to the lower nibble or higher nibble ifneed Example: MOVA, 47H 6CH MOV B,/#25H 72H not after INC DA works only after an ADD, but :3F +06=45 H. provided to correctthe aforementioned problem associated | 3A=47 H first BCD operand + B=2SH second BCD operand shex (binary) addition (A =6 CH adjust for BCD addition (a=rH) git Embedded Processor 127 ae ‘The “DA” instruction works only on A. In other word, whi jon must be in register A in order for DA to operand of any addressing mode, the dest work. © Summary of DA instruction + Afteran ADD or ADDC instruction 1. lower 4 bits. 2. Ifthe upper nibble is greater than the source can be an f the lower nibble (4 bits) is greater than 9, orifAC=1, add 0110to the 9, or if CY=1, add 0110 to the upper bits. HEX BeD (0010 1001, + + 9001 1000 0100 0001 AC=1 + + ono 47 ‘1000111 AC=l after the n, “DAA” will add 6 to the lower nibble, The final result is in BCD format. GS 3. Assume that 5 BCD data items are stored in RAM locations starting at 40H, as shown below. Write a programto find the sum ofall the numbers. ‘The result must be in BCD. 40= (71) 41s (11) 42= (65) 43= (59) 44= (37) | embedded Systems and toy we Solution: MOV —RO,#40H —_; Load pointer MOV R2,#5 jLoadcounter | CLRA MOV RIA ear R7 AGAIN: ADD A,@RO add the byte pointer; to by ROJNCNEXT -C¥=0 don’t; add carry INC RT ceep track of carries NEXT: INC’ RO increment pointer DINZR2, AGAIN repeat until R2 is 0 Subtraction of Unsigned Numbers ¥ _Inmany microprocessors there are two different instructions for subtraction; SUB and SUBB (subtract with borrow) * Inthe 8051 we have only SUBB | + ‘The 8051 uses adder circuitry to perform the subtraction SUBB A, source; A= A-source-CY ¥ Tomake SUB out of SUBB, we have to make CY = 0 prior to the execution of the instruction + Notice that we use the CY flag for the borrow SUB when CY = 1, Take the 2’s complement of the subtrahend (source operand) 2. Additto the minuend (A) 3. Invert the carry CLR Cc MOV A, #4C jload A with value 4CH SUBB A, #6EH subtract 6E from A JNC ‘NEXT ifCY=0 jump to NEXT cPLA 3ifCY=1, take 1’s complement INC A i and inerementto get's comp NEXT:MOV — RLA jsaveAin RI a Bit Embedded Processor 1.29 Solution: 4c = OE. 22 CY=0, the result is posi CY=1, the res and the dest 2’s complement ofthe result + SUBB when CY=1 borrow of the lower operand CLR C MOV 4/462H ;A=62H SUBB A, #96H 62H - 96H = CCH with CY=1 MOV R7,A_ ; save the result MOV A#271 . #12H; 27H-12H-12H-1 = 14H Solution: We have 2762H - 1296H = 14CCH This instruction is used for multi-byte numbers and will take care of the Ors complement 0100 ah oa] Te QOinvert carry A= @2H-96H-0= CCH A=27H-12H-1= 4HCY= bedded Systems and io, er 139 Unsigned Mi et “The 8051 supports byte by bytem ie ick . Te tyearcasunedio be unset aa UAB By 16-bit A Mov A#25H Joad 25Hto ree-A Mov —-B.#6SH Joad 65H t0re8. B MUL. AB :25H * 65H= £99 where ;B=OEHand A= 99H Unsigned Mi jon Summary | (MULAB) Mulipicaion Operand! Operand2 Result Byte x byte A B ° B=highbyte A=lowbyte Unsigned Division + The 8051 supports byte over byte + The byte are assumed to be unsigned data 131 g Bit Embedded Processor Beit Embedded Processor (a) Weite a program to get hex data in the range of 00 — FFH fromport I and convertit R7,R6 and RS. (b)_ Assuming that PI has. value of FDH for data, analyse program. Solution: (@) Mov A#OFFH Mov PLA smake P1 an input port Mov APL ead data from PA Mov ByI0 B=OA hex DIV AB videby 10, Mov RIB ssave lower digit, Mov BAO DIV AB vide by 10 once more Mov R6B ve the next di Mov RSA jsave the last i by 10 repeatedly until the MOY A,#95.—_jload 95toreg.A MOV B#10 load l0toreg. B (b) Toconverta binary (he) valu to dee DIVAB;Aby BAB = tis less than 10. After each division the remainder is saves R DIVAB; divide A by B,A/B ya ma FD/OA=19 3 (lowdigit) MOV A,##95. jload95to eg. A 19/0A=2 — S(middledigit) MOV B#10 ;load10t0 = eg, B 2(ighdigi) MUL AB; A=09 (quotient) and ‘Therefore, we have FDH = 253. ;B=05 (remainder) a | Signed Arithmetic Instructions wm Summary (DIV AB), | Signed 8-bit Operands ‘Numerator | Denominator | Quotient | Remainder D7 (MSB) is the sign and DO to D6 are the magnitude of the number Byte/byte A B in 5 IfD7=0,the operandis pastive, andifD7=1,itisnegatine > D7] pe ps | p+] ps | p2 | pi _| Do CYisalways 0 | IfB # 0,0V=0 Sign [Magnitude IfB=0, 0V=1 indicates er | : & Embedded *¥StEMs and ig, pS oe embedle Processor 133 SSS Positive numbers are 0 to +127 aa 3 : fon (2’s complement) e | Solution: be ° oll Negative mumberrepresetation @SCOMPIMET a sgn) ae qu ee! ow, 1. Write the magnitude of the number in, ao 9210 + +70 0100 o110 ° 2. Inverteachbit | 06 3. Add Ltoit | E 166° 1010 0110 and OV=1 ye 34H Solution: e | 4 2. © ‘Show how the 8051 would represent | 0000 0010 According to the CPU, the result is -90, which is wrong. The CPUsets OV=1 to 1. 00110100 —_34H/givenin inary L111 11.0} | indicatethe overflow 2 1100 1011 inate cointey 1! iyo OV Flag 3; 11001100 add 1 (whichis Ao In 8-bit signed number operations, OV is set to 1 if either occurs: ion of 34 in2's complement is CCH | jigned number representation of -34 in aatl 1. There isa carry from D6 to D7, but no carry out of D7 (CY= 0) Decimal aS a 2, There is acarry from D7 out (CY=1), but no carry from D6 to D7 128 1000.00 7m MOV A,i-128—;A=1000_000(A=80H) "127 1000 0001 eee | MOV R42 1110(R4=FEH) 7126 1000 0010 82 — ADD ARS 1110(A=7EH=+126,INVALID) = - -128 1000 0000 2 T1110, FE 3 1 u FF * a Hn 1110 -130 oul Vet ! E 0 (0000 0000) 00 | 1110 and OF + (0000 0001 ol OV=1 42 (0000 0010 2 The result + 126 is wrong} MOV A, #2 ;A=II11 1110(A=FEH) 127 ont it TF. | MOVRI,#-5 — ;R1=1111 1011(RI-FBH) Overflow Problem ADDA,RI— A=III1 1001(A=F9H=-7, 7 (irseresut ‘of an operation on signed numbers is too large for the register. sCorrect, OV = 0) An overflow has occurred and the programmer must be is) | 2 Ut 1110 sO Examine the following code and analyze the result. + 5 + Mi, 1011 i SREY ya ee T- gh. NEXT sjumpit > INZEXIT- jump if Ais noto Rs < 80 [CY flag always checked for NEXT <1” ; eases of greater or less than 7 Fi but only after it is determined both registers have the same value, 00 that they are not equal placed in A. INZ and JZ test the contents | | of the accumulator Embedded Systems and I0t | ee 138 g pit Embedded Processor 3 entation mae —_—__—___ Instruction and Data Seriatizaq, ation Compare Carry Flag | Rotate ase cy=0 | rotating Right and Left Jestnation source cy=1 | RRA} oe ae = #. + Inrotate right + Notice in the CINE instruction that any Rn register ean be compared with an + The Sbits oft Pee {The Sito theacumultrarroutedsighton bit nd Bit DO exits from the LSB and enters into MSB, D7 + There is no need for register A to be involved ‘except that the operands remain + Thecompare instruction is really a subtraction, unchanged aT MSB > LsB + Flags are changed according to the execution of the SUBB instruction 29). Writea program to read the temperature and est it for the value 75.According to Mov AM6H =A = oo on the test results, place the temperature value into the registers indicated by the following. a in ‘A © pdt ton IfT=75 thenA= RR A Ey ee cn 751ET <75 then RI | Ag a A= 1100 0110 RR A A= =TIfT>75 then a reno RLA rotate left A © Inrotate left Solution: + The 8 bits of the accumulator are rotated left one + Bit D7 exits from the MSB and enters into LSB, DO MOV P1,#0FFH smake P1 an input port: MOVA,P1 sread PI port jump ifA isnot 75 MSB <— LSB CINEA#H75,OVER R2=T and ‘SJMP EXIT jA=75, exit OVER: JNCNEXT sifCY=0 then A>75 | Rotating through Carry MOVRLA sCY=1, A<75, save in RI | RRCA;rotate right through carry SJMP EXIT sandexit | MOV A#f72H A = OMIT 0010 RL A A = 1110 0100 = 1100 1001 NEXT: MOV R2,4, 3A>75, save it in R2 } RL A A Embedded Systems and Ioy Mo ee + InRRCA + Bitsare rotated from left to right + They exit the LSB to the carry flag, and the carry lag enters the MS, MSB > LSB oY, CLRC ;makeCY=0 MOV A#26H A = 00100110 RRC A A = 0001 Cane RRC A A = 0000 1001 CY = 1 RRC A A = 1000 0100 CY = 1 RLCA jrotate left through carry + InRLCA + Bitsare shifted from right to left + They exit the MSB and enter the carry flag, and the carry flag enters the LSB. oH MSB< LSB 5 ‘Write a program that finds the number of Is ina given byte Mov R140 Mov R7#8;count=08 MOV A,#97H AGAIN:RLCA INCNEXT check for CY INCRI CY=1 add to ‘count NEXT: DINZ R7,AGAIN a pit Embedded Processor Serializing Data Serializing data isa way of send single pin of microcontroller + Using the serial por ing a byte of data one bit ata time through a iscussed in Chapter 10 ‘To transfer data one bit at atime and control the sequence of data and ‘spaces in between them. ‘Transfer a byte of data serially by 18 CY toany pin of ports PO—P3 Using rotate instruction @ Write a program to transfer value 41H serially (one bit ata time) via pin P2.1,Put ‘wo highs atthe start and end of the data. Send the byte LSB first. Solution: MOV A, #411 SETBP2.1 igh SETBP2.1 high MOVRS, #8 AGAIN: RRCA MOV P2.1, C ; send CY to P2.1 DINZRS, HERE SETBP2.1; Pin Reiser A | cy { ma | D7 DO 1.8 PROGRAMMING PARALLEL PORTS ARAL EL PORTS 1.5.1 Port 0 Port 0 is one of the four I/O ports available on the 8051 microcontroller. Itis a1 8-bit bidirectional port, which means that each bit of Port O can be individually configure as either an input or an output. 142 Embedded Systems and [97 Address and SFR Name: + Portis associated with Special Function Register (SFR) PO + Theaddress of PO in the memory space is 0x80 (128 in decimal). Open-Drain Output: Y Port 0 isan open-drain output port. It means that it can only pull the output pins Loy (sink current) and relies on external pull-up resistors to drive the pins high. | YTouse Port 0.as an output and to drive the pins high, youneed to connect external pull-up resistors to the corresponding pins. Default Input Mode: Y Atpower-up or reset, Port 0 is configured as an input port by default. Y When used as an input, the port can be used to read the state of external devices o- signals connected to the pins, Nee 10k eHow OO pull-up resistors = 10k Fig:1.5 Port 0 with internal pull up resistors Input Mode with Internal Pull-u ¥ Port 0 also provides an internal pull-up resistor feature, which can be enabled by setting the POPU (Port 0 Pull-Up) bits of the POM] and POMO SFRs. Y When the internal pull-up resistors are enabled, the input pins of Port 0 are internally pulled up to VCC, providing a default logic high state when no external device is connected, a Bit Embedded Processor eee tts External Interrupts: ¥ Port 0 (PO.2, PO.3) also servesas the inter ipt input for external interrupts INTO and INTI, respectively 7 ¥ Theextemal interrupts can be triggered ona filling edge, ising edge, or level change, depending on the configuration, bit Manipal: ¥ Individual bts of Port Ocan be manipulated using bitwise operations. ¥ Forexampl set PO.5 high, you can use the instruction SETB PO.5. ¥ Toclear PO.3 (set it low), you can use the instruction CLR P0.3. ¥ Totoggle PO.7, youcan use the instruction XRLPO.7, #1 4.5.2 Port1 configured as either an inputoran output. ‘Address and SFR Name: ¥ Port | is associated with Sp Function Register (SFR) P1. ¥ The address of P1 in the memory space is 0x90 (144 in decimal). Output Mode: Y Port 1 can be used as a general-purpose output port. When configured as an output, the port can be used to drive external devices or signals connected to the pins. Default Input Mode: ¥ Atpower-up or reset, Port | is configured as an input port by default, When used as an input, the port can be used to read the state of external devices or signals connected to the pins. External Interrupts: Port | (P1.2, P1.3) can serve as the interrupt input for extemal interrupts INT2 and INT3, respectively. ¥ Theexternal interrupts can be triggered ona falling edge, rising edge, orlevel change, depending on the configuration. Embedded Systems and lor For example, to set P1. Y Toclear P1.3 (set it low), you can use the instruct Y Totoggle P1.7, you can use the instruction XRL- 1.5.3 Port2 san 8-bit bidirectional port, which means that each bit of Port 2 can be individually ‘configured as either an input oran output Address and SFR Name: Y Port 2isassociated with Special Function Register (SFR) P2. Y Theaddress of P2 in the memory space is 0 A0 (160 in decimal) Output Mode: Y Port 2 can be used as a general-purpose output port, Y When configured as an output, the port can be used to drive external devices or signals connected to the pins. Default Input Mode: Y Atpower-up or reset, Port 2 is configured as an input port by defa ¥ When used as an input, the port can be used to read the state of external devices or signals connected tothe pins, External Interrupts: ¥ Port 2(P2.0, P2.1) can serve as the interrupt input for external interrupts INTO and INTI, respectively. Y Theextemal interrupts can be triggered ona falling edge, rising edge, or level change, ise operations, n‘SETB P25’, Tow), you can use the instruction “CLR P2.3, ‘To toggle P2.7, you can use the instruction “XRLP2.7, #1° to set P2.5 high, you can use the To clear P2.3 (set g pit Embedded Processor as 4.5.4 Port3 Itisan bt bidirectional port, which me configured as either an input oran output, ‘Address and SFR Name: ans that each bit of Port 3 can be individually Port is associ ¢ Theaddress ofP3 ‘Output Mode: 'd with Special Function Register (SFR) P3, ‘the memory space is 0xBO (176 in decimal). Y Port 3 can be used asa general-purpose output port, When configured as an output, the port can be used to drive external devices or signals connected to the pins Input Mode: ‘orl 3 is configured as an input port by default. the port can be used to read the state of extemal devices or als connected to the pi External Interrupts: jerTupts can be triggered ona f he configuration, wise operations. instruction *SETB P3.5° Alternate Functions: ¥ — Insome variants of the 8051 microc :mbedded »ystems ae T 146 E Port3Pin ‘Alternate Function P3.0 RXD (Serial Receive Data) P3.1 "TXD (Serial Transmit Data) P32 INTO (External Interrupt 0) P33. INTI (External Interrupt 1) P34 TO (Timer O extemal input) P35 TI (Timer | external input P3.6 WR’ (Extemal data memory write strobe) P37 RD* (External data memory read strobe) ‘Dual-Function Pins: “Some pins of Port 3 may have dual functionality, meaning they can serve as both general-purpose UO and address‘data bus pins when interfacing with extemal memory or peripherals. ‘The dual-functionali and the specific configuration. determined by the mode of operation of the microcont 4.5.5 Programming the Ports of 8051 ‘To program the pons of the 8051 microcontroller, you need to manipulate thespeci function registers (SFRs) associated with each port. The 8051 microcontrol VO ports, labeled as PO, P1, P2.and P3. Each port is 8 bits wide and can be configured as cither input or ouiput. Here isan overview of how you can program the ports of the 8051 microcontro| 1. Set the Port ¢ Toconfigure a port as an inpul cer (PO, PI. P2, oF P3)t0 1. et the corresponding bits in the port's direction | ¥ To configure port asan output, set the corresponding bts in the port's direction | a pit Embedded Processor Se Read from an Input Port: ‘To read the current state ofan input por, si ut port, simply read the i port register (PO, Pl, P2, or P3), ply read the value ofthe corresponding Write to an Output Port: To write data to an output port assign the desired value to the corresponding port register (PO, P1, P2, or P3). Manipulate Individual Pins: ‘To manipulate individual pins of a port, you can use bitwise operations. Each bitin the port register corresponds to a pin on the port. Y Toset.a pin high (logic 1), use the bitwise OR operation (\) with the desired bit mask. ¥ Tocleara pin (set it low; logic 0), use the bitwise AND operation (&) with the ‘complement of the desired bit mask. To toggle the state of apin, use the bitwise XOR operation (*) with the desired bit mask. Here’s an example code to illustrate seting Port I (P1)as.an output and manipulating ividual pins: 3 Set Port 1 as output (P1.0-P1.7) MOV P1.1, #0; Set XRLPI.2, #1 ; Toggle P1.2 In the example above, *MOY* instructions are used to set the port direction, and ‘MOV* and *XRL¢ instructions are used to manipulate individual pins of Port 1 Embedded Systems and 1oy as git Embedded Processor - 7.5 TIMERS AND SERIAL PORT imer Timer 1 Mode Timer 0 Mode Dj|paDenails |Gate(@] CF — Dg aR imers | Bit Details GOT | wr ‘° at timer registers. These registers are known a, MO |Gate(@)| CAT] Mi [Mo 3] two 16-bil ae es canbe used in two modes, These modes ary ean Timermose and the Counter mode. The ely difference between these two modesis thy source for incrementing the timer regis = 1.6.1.1 Timer Mode In the timer mode, the intemal machine cycles are counted. So this regi incremented in each machine eyele. So when the clock frequency is 12MHz, then timer registers incremented in each millisecond. In this mode it ignores the extemal ti inpurpin 4.6.1.2 Counter Mode Inthe counter mode, the extemal events are counted. In this mode, the timer is incremented foreach 1 10 0 transition of the external input pin. This type of transitions istreated as events. The extemal input pins are sampled once in each machine cycle, and to determine the Lor 0 transitions, another machine cycle will be needed. So in this mode, at least two machine cycles are needed. When the frequency is12MHz, then the smacimum count frequency will be 12MHz/24 = 500KHz. So for event counting the time durations? ps. There are four different modes of the Timer or Counter. The Mode 0 to Mode 2 are forboth of the Timer/Counter. Mode 3 has a different meaning for each timer register. There isa register called TMOD. This register can be programmed to configure these timers or counters. ‘The Serial poris used for serial communication in mode 1 and 3. Timer! is used for senerating the baud rate. So only Timer0 is available for timer or counter operations. Cys TMOD Register ‘TMOD(Timer Mode) is an SFR. The address of this register is 89H. This is not bit- addressable. ‘Now, letus see the circuit that controls the running of the mer. Bit Details High value (1) oF Configure for the Counter operations Timer0 of Timer! Run Mode Gate (G), Bit 00 1 10 i Details Mi Mo This is Mode 3 ‘(The function depends on Timer0 or “Timoet ‘e+ To timer increment input Run control 1=>Run 0 => Stop. Git INTs Toputpin it will be high when the timer or counter is in mode 0 to 2, Embedded Systems and loy | so Examples inter and Timer! as 8-| 1 To configure the Timer 0 as 16-bit event cou tern 0.010010 pattern, we can use t reload counter, we can use the bit p want to program the TMOD register wi MOV TMOD, #25H ‘The above instruction is executed, then the tim« re the system as hardware controlled mode, then the gate bits wil 1=ADH we can use this instru ier/counter will be cont software. To confi be 1. So the bit patterns will be 1010110 MOV TMOD, soap } Opearting Modes of Timer/Counter pre-scaler. So of THO@rTI SetTFL conditions are met Inthis example the Timerlis selected, ase, every 32 (25)event for counter operations or 32 machine cycles for timer operation, the THI register will be incremented | by 1. When the TH overflows from FFH to 00H, then the TF of TCON register will be , and it stops the timer/counter. So for an example, we can say that if the TH. I be high after 10H * 32= 512 machi MOV TMOD, #00H MOVTHI, #OFOH MOVIE, #88H SETB TRI In the above program, the Timer! is configured as timer mode 0. In this case Gate =0, Then the THI will be loaded with FOH, then enable the Timer] interrupt. At | - last set the TR1 of TCON register, and start the timer. | | it Embedded Processor a Bi are using Mode 1 for'Timer 0, ) 60 cycles. When the clock frequency is 12MHIz, then the following instructions generate an interrupt 16 1s after Timer0 starts rus MOVTMOD, #01H MOVTLO, #0FOH MOVTHO, #0FFH MOVIE, #82H SETB TRO In this case In the above program, the Timer0 is configured as timer mode Gate = 0. Then the TLO will be loaded with FOH and THC ‘enable the Timer0 interrupt. At last set the TRO of TCON register, and start the timer. Mode2 of Timer/Counter ‘The Mode 2 operation diagram, we are using Mode 2for Timer! ‘case every event for counter operations or machine cycles for timer operation, incremented by 1. When the register pair overflows from FFH to be reloaded with the Content of TH and starts the operation ag2"7._ embedded Systems and 1Or wa Lee t MOVTMOD, #20H MOVTLI, #0FOH MOVTHI, #0FOH MOVIE, #88H SETBTRI In the above progr Gate = 0, Then the TL1 and THI are loaded with FOH. then enable the Timer! interrupt. At last set the TRI of TCON register, and start the timer. Timer! in mode2 generates the desired baud rate when the serial port is working on Mode 1 or 3 ram, the Timerl is configured as timer mode 2, In this ease Mode3 of Timer/Counter Mode 3is different for Timer 0 and Timer!. When the Timer 0 is working in mode 3, led by the standard Bit, embedded Processor es Timer irement input To Run contol 1S Run 0= Sup TRI When the Timer! is working in Mode 3, i imply holds the count but does not run, ‘configured in one of the mode 0, 1 and 2. In this ramming of THOis controlled by TR! bitonly. Sth gat bitin this mode for Timer Ohas nospecific role. ‘The mode 3 is present for app! Mode 3 of Timer 0, the 8051 hi timer/counter by TLO, and one 16-1 imer by THO, another8-bit ner/eounterby Timer. deacti vated when the gate is ial Ports Serial Communication LZ ‘When a microcontroller communicates with the outside world, it provides the data ‘in byte-sized chunks. In some cases, suchas printers, the informati “fom the 8- bit data bus and presented to the 8-bit data bus of the printer. This can work only if the cable is not too long, since long cables diminish and even distort signals. Embedded Systems and 107 git Embedded Processor ) shows serial versus parallel data transfer. The fay data line instead ofthe 8-bit data line of paras Fon towark, the Byte of data must be conver, When the distance is short, the digital signal can be transferred as iti wire and requires no modulation. However, for long-distance data transfers, serial day communication requires a modem to modulate (convert to Osand 1s to audio tones) an ‘demodulate (converting from audio tones to 0s and 1s). jon uses two methods, asyitchronous and synchronous. The synchronous method transfers a block of data(characters) at atime, while the asynchronow method transfers a single byte at a time. There are special IC’s made by many . These chips are commonly referred to as ‘manufacturers for serial data comm UART (universal asynchronous receiver transmitter) and USART (universal synchronous asynchronous receiver transmitter). Parallel Transfer Serial Transfer Do Receiver Reeeiver ] | sender ‘D7 ‘ i computer only sends data. Duplex transmissions can be half full duplex, depending on whether or not the data transfer canbe simultaneous. I datas transmitted one way aa time, itis referred toas half duplex. Ifthe data can go both ways atthe same t duplex. Full duplex requires two wire conductors for the data lines, one for transmission and one for reception, in order to transfer and receive data simultaneo ‘Simplex . [4 Receiver a YW o_9fet . Transmitter ake nly Half Duplex —————_~_] — Receiver a Receiver — L__“eewer 5 ‘Transmitter T i | Full Duplex ransmitter Receiver Receiver, im] > Fig:1.7 Serial communication forms ‘Asynchronous Serial Comm 7 nat the receiving end ofthe data line in a serial data transfer is all jcult to make sense of the data unless the sender and: ‘The data cor aset of rules, a protoc ‘and when the data begins and ends. Fig:1.8 Asynchronous Serial Communication data framing widely-used for character-o Asynchronous serial data communi transmissions, In this method, each characteris placed between start and stop in data framing for asynchronous communications, the data such as ASCII butthe called frami characters, are packed between astart bit an stop bit can be one or two bits. The start bi Look at below figure in wt 1 ASCII character “A between the start bit and astop bi { the LSB is sent out first. x stop bit. The start bits always one i Embedded Systems and Io, ase Data Transfer Rate he rate of data transfer in s second), Another widely used terminology jology and s defined as the mur for bpsis baud rate. eof signal changes per second, Fnput and output voltage levels are not TTL compat ible. For this reason, to connect any RS232 toa microcontroller system we must use voltage ‘converters such as MAX232 tg convert the TTL logic levels to RS232 vollage levels, and viee versa. MAX232 IC's are commonly referred toas line drivers. S232 pins S232 cable commonly referred to as the DB-25 connector has 25 pins. Since not all the pins are used in PC cables, IBM introduced the DB-9 version of the seri ‘standard, which uses 9 pins only. ‘Current terminology classifies data communication equipment as DTE (data terminal equipment) or DCE (data communication equipment). DTE refers to terminals and computers that send and receive data, while DCE refers t communication equipment, le for transferring the data, The simplest connec DIE DTE TxD xD: rx0->-axo ground Fig:1.9 RS232 Pinout git embedded Processor ot? 18232 pins description Description Data carrier detect (-DCD) Received data (=D) “Transmitted data (T*D) ‘To ensure fast and reliable data transmission between two devices, the data transfer must be coordinated. Many of the pins of the RS232 connecter are used for handshaking CTS (Clear'To Send): In response to RTS, when the modem has room forstoring the data sends out signal CTS tothe DTEto indicat thatit can receive the data now. DCD (Data Carrier Detect): The modem asserts signal DCD to inform the DTE that a valid carrier has been detected and that contact between it and the other modem is, established, Therefore , DCD is an output from the modem and an input to the PC. lephone is ringing, However if the PC is in RI (Ring Indicator): charge of answering the phone, this signal can be used. Embedded Systems and Ig 158 _ | 1.6.2.3 MAX232 Since the RS232 is not compa microcontrollers, we need a voltage converter (line tible with today’s microprocessors any driver) to convert the RS232's signay, 1d RxD pins, to TTL voltage levels that will be acceptable 10 the ee sn einen ey example of such converter is MAX232. Itconverts from eer i voltage levels and vice versa, One advantage of the MAX: v ‘ource voltage for the 8051. power source which is the same asthe s ‘The MAX232 has two sets of line drivers for transferring and rece shown in fig(S). The lin drivers used for TXD are called TI and 72, while th tedasR1 and R2. MAX232 requires four capacitors ranging data, drivers for RXD are d reso from 1 to 22 uF. The most widely used value for these capacitors is 22 HF. od) mwas2* at} . 8051: 2 oy ee * pal rin riot] feet pn sale a ® S > 9 deta na ~

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy