Assignment 1 Key
Assignment 1 Key
• The operand can be a register, a direct address, an       Work on the accumulator or a bit.
indirect address, the data pointer.                           • CLR P1.2
 DEC                                                         •   CPL Rn
• Decrement the operand by one.
• The operand can be a register, a direct address, an       RL / RLC / RR / RRC
indirect address.                                           Rotate the accumulator.
 MUL AB / DIV AB                                             • RL and RR without the carry
• Multiply A by B and place result in A and B registers.      • RLC and RRC rotate through the carry
                                                           SWAP A: Swap the upper and lower nibbles of the
                                                           accumulator
Data transfer instructions                             Push and Pop a data byte onto the stack.
 8-bit data transfer for internal RAM and the SFR.
• MOV A, Rn                                            The data byte is identified by a direct address from
                                                      the internal RAM locations.
• MOV A, direct                                       • PUSH DPL
• MOV A, @Ri                                          • POP 40H
                                                       XCH
• MOV A, #data
                                                       Exchange accumulator and a byte operand
• MOV Rn, A                                           • XCH A, Rn
• The 11-bit address is substituted for the lower 11-bits   • CJNE A, direct, rel
of the PC to calculate the 16-bit address of the target.    • CJNE Rn, #data, rel
• The location referenced must be within the 2K Byte
memory.                                                     • CJNE @Ri, #data, rel
 Indirect Jump – JMP                                        Decrement and Jump if Not Zero – DJNZ
• JMP @A + DPTR                                              Decrement the first operand by 1 and jump to the
 The 8051 provides 2 forms for the CALL                    location identified by the second operand if the
instruction:                                                resulting value is not zero.
 Absolute Call – ACALL                                     • DJNZ Rn, rel
• Uses an 11-bit address similar to AJMP                    • DJNZ direct, rel
• The subroutine must be within the same 2K page.            NOP – No operation
 Long Call – LCALL
• Uses a 16-bit address similar to LJMP
• The subroutine can be anywhere.
 Both forms push the 16-bit address of the next
instruction on the stack and update the stack pointer.
     2) Write a program to generate a delay of 10ms.
                 Name: This is simple but helpful. Giving a name to the project not only simplifies
                 talking about it to other people but can also crystallize the purpose of the
                 machine.
                 Purpose: This should be a brief one- or two- line description of what the system is
                 supposed to do. If you can’t describe the essence of your system in one or two lines,
                 chances are that you don’t understand it well enough.
                 Inputs and outputs: These two entries are more complex than they seem. The
                 inputs and outputs to the system encompass a wealth of detail:
                 Types of data: Analog electronic signals? Digital data? Mechanical inputs?
                 Data characteristics: Periodically arriving data, such as digital audio samples?
                 Occasional user inputs? How many bits per data element?
                 Types of I/O devices: Buttons? Analog/digital converters? Video displays?
                 Functions: This is a more detailed description of what the system does. A good way
                 to approach this is to work from the inputs to the outputs
When the system receives an input, what does it do? How do user interface inputs affect these
functions? How do different functions interact?
             □ Performance: Many embedded computing systems spend at least some time
               controlling physical devices or processing data coming from the physical
               world.
             □    In most of these cases, the computations must be performed within a certain time frame. It
                 is essential that the performance requirements be identified early since they must be
                 carefully measured during implementation to ensure that the system works properly.
             □   Manufacturing cost: This includes primarily the cost of the hardware components. Even
                 if you don’t know exactly how much you can afford to spend on system components, you
                 should have some idea of the eventual cost range. Cost has a substantial influence on
                 architecture.
             □    A machine that is meant to sell at $10 most likely has a very different internal
                 structure than a $100 system.
             □   Power: Similarly, you may have only a rough idea of how much power the system can
                 consume, but a little information can go a long way. Typically, the most important
                 decision is whether the machine will be battery powered or plugged into the wall. Battery-
                 powered machines must be much more careful about how they spend energy.
             □   Physical size and weight: You should give some indication of the physical size of the
                 system to help guide certain architectural decisions. A desktop machine has much
                 more flexibility in the components used than, for example, a lapel mounted voice
                 recorder.
      DCC
       □ The Digital Command Control (DCC) was created by the National Model Railroad
           Association to support interoperable digitally-controlled model trains.
       □ Hobbyists started building homebrew digital control systems in the 1970s
           and Marklin developed its own digital control system in the 1980s.
       □ DCC was created to provide a standard that could be built by any manufacturer
           so that hobbyists could mix and match components from multiple vendors.
The DCC standard is given in two documents:
                 □ Standard S-9.1, the DCC Electrical Standard, defines how bits are
                     encoded on the rails for transmission.
                 □ Standard S-9.2, the DCC Communication Standard, defines the packets
                     that carry information.
       □ Any DCC-conforming device must meet these specifications. DCC also provides
           several recommended practices. These are not strictly required but they provide
           some hints to manufacturers and users as to how to best use DCC.
       □ The DCC standard does not specify many aspects of a DCC train system. It doesn’t
           define the control panel, the type of microprocessor used, the programming
           language to be used, or many other aspects of a real model train system.
       □ The standard concentrates on those aspects of system design that are necessary for
           interoperability.
        □ Over standardization, or specifying elements that do not really need to be
          standardized, only makes the standard less attractive and harder to
          implement.
        □ The Electrical Standard deals with voltages and currents on the track
        □ The standard must be carefully designed because the main function of the track is to
          carry power to the locomotives. The signal encoding system should not interfere with
          power transmission either to DCC or non-DCC locomotives. A key requirement is
          that the data signal should not change the DC value of the rails.
        □ The data signal swings between two voltages around the power supply voltage. bits
          are encoded in the time between transitions, not by voltage levels. A 0 is at least
          100 ms while a 1 is nominally 58ms.
        □ The durations of the high (above nominal voltage) and low (below nominal voltage)
          parts of a bit are equal to keep the DC value constant. The specification also gives
          the allowable variations in bit times that a conforming DCC receiver must be able to
          tolerate.
        □ The standard also describes other electrical properties of the system, such as
          allowable transition times for signals.
        □ The DCC Communication Standard describes how bits are combined into packets and
          the meaning of some important packets.
        □ Some packet types are left undefined in the standard but typical uses are given in
                                                                                               15
Recommended Practices documents.
                                   16
         □ We can write the basic packet format as a regular expression:
           PSA (sD) + E ( 1.1)
                                                                                                   17
Conceptual Specification:
              □ Digital Command Control specifies some important aspects of the system,
                  particularly those that allow equipment to interoperate. But DCC deliberately
                  does not specify everything about a model train control system.
              □ A conceptual specification allows us to understand the system a little better. This
                  specification does not correspond to what any commercial DCC controllers do,
                  but is simple enough to allow us to cover some basic concepts in system design
              □ A train control system turns commands into packets. A command comes from the
                  command unit while a packet is transmitted over the rails.
              □ Commands and packets may not be generated in a 1-to-1 ratio. In fact, the DCC
                  standard says that command units should resend packets in case a packet is
                  dropped during transmission.
              □ We now need to model the train control system itself. There are clearly two major
                  subsystems: the command unit and the train-board component. Each of these
                  subsystems has its own internal structure.
               □ The command unit and receiver are each represented by objects; the command
                 unit sends a sequence of packets to the train’s receiver, as illustrated by the arrow.
               □ The notation on the arrow provides both the type of message sent and its sequence
                 in a flow of messages; since the console sends all the messages, we have numbered
                 the arrow’s messages as 1..n. Those messages are of course carried over the track.
               □ Since the track is not a computer component and is purely passive, it does not
                 appear in the diagram. However, it would be perfectly legitimate to model the
                 track in the collaboration diagram, and in some situations it may be wise to model
                 such nontraditional components in the specification diagrams. For example, if we
                 are worried about what happens when the track breaks, modeling the tracks would
                 help us identify failure modes and possible recovery mechanisms.
Class diagram for the train controller messages.
UML collaboration diagram for major subsystems of the train controller system.
                                               1
A UML class diagram for the train controller showing the composition of the subsystems.
         □ Let’s break down the command unit and receiver into their major components. The
           console needs to perform three functions: read the state of the front panel on the
           command unit, format messages, and transmit messages. The train receiver must
           also perform three major functions: receive the message, interpret the message.
         □ It shows the console class using three classes, one for each of its major
           components. These classes must define some behaviors, but for the moment we
           will concentrate on the basic characteristics of these classes:
         □ The Console class describes the command unit’s front panel, which contains
           the analog knobs and hardware to interface to the digital parts of the system.
         □ The Formatter class includes behaviors that know how to read the panel knobs
           and creates a bit stream for the required message.
         □ The Transmitter class interfaces to analog electronics to send the message along
           the track.
    □ There will be one instance of the Console class and one instance of each of the component
      classes, as shown by the numeric values at each end of the relationship links. We have also
      shown some special classes that represent analog components, ending the name of each with
      an asterisk:
    □ Knobs describes the actual analog knobs, buttons, and levers on the control panel.
    □   Sender describes the analog electronics that send bits along the track.
    □   Likewise, the Train makes use of three other classes that define its components:
    □   The Receiver class knows how to turn the analog signals on the track into digital form.
    □   The Controller class includes behaviors that interpret the commands and figures out how
        to control the motor.
    □ The Motor interface class defines how to generate the analog signals required to control the
      motor.
      We generally proceed in two phases: First, we gather an informal description from the customers
       known as requirements, and we refine the requirements into a specification that contains enough
       information to begin designing the system architecture.
      Separating out requirements analysis and specification is often necessary because of the large gap
       between what the customers can describe about the system they want and what the architects need
       to design the system.
      Consumers of embedded systems are usually not themselves embedded system designers or even
       product designers. Their understanding of the system is based on how they envision users’
       interactions with the system. They may have unrealistic expectations as to what can be done within
       their budgets; and they may also express their desires in a language very different from system
       architects’ jargon.
      Capturing a consistent set of requirements from the customer and then massaging those requirements
       into a more formal specification is a structured way to manage the process of translating from the
       consumer’s language to the designer’s.
      Requirements may be functional or nonfunctional. We must of course capture the basic functions
       of the embedded system, but functional description is often not sufficient.
                    Typical nonfunctional requirements include:
                    Performance: The speed of the system is often a major consideration both for the
                       usability of the system and for its ultimate cost. As we have noted, performance may
                       be a combination of soft performance metrics such as approximate time to perform a
                       user- level function and hard deadlines by which a particular operation must be
                       completed.
      Cost: The target cost or purchase price for the system is almost always a consideration. Cost
       typically has two major components: manufacturing cost includes the cost of components and
       assembly; nonrecurring engineering (NRE) costs include the personnel and other costs of
       designing the system.
      Physical size and weight: The physical aspects of the final system can vary greatly depending upon
       the application. An industrial control system for an assembly line may be designed to fit into a
       standard-size rack with no strict limitations on weight. A handheld device typically has tight
       requirements on both size and weight that can ripple through the entire system design.
      Power consumption: Power, of course, is important in battery-powered systems and is often
       important in other applications as well. Power can be specified in the requirements stage in terms of
       battery life—the customer is unlikely to be able to describe the allowable wattage.
      Validating a set of requirements is ultimately a psychological task since it requires understanding
       both what people want and how they communicate those needs.
                                                               1
One good way to refine at least the user interface portion of a system’s requirements is to build a
              mock-up.
             The mock- up may use canned data to simulate functionality in a restricted
              demonstration, and it may be executed on a PC or a workstation. But it should give the
              customer a good idea of how the system will be used and how the user can react to it.
             Physical, nonfunctional models of devices can also give customers a better idea of
              characteristics such as size and weight.
              Sample requirements form.
                    Name
                    Purpose
                    Inputs
                    Outputs
                    Functions
                    Performance
                    Manufacturing cost
                    Power
                    Physical size and weight
           Requirements analysis for big systems can be complex and time consuming. However,
               capturing a relatively small amount of information in a clear, simple format is a good
               start toward understanding system requirements.
           To introduce the discipline of requirements analysis as part of system design, we will
               use a simple requirements methodology.
     We can use the requirement form as a checklist in considering the basic characteristics of the
     system.
       Name: This is simple but helpful. Giving a name to the project not only simplifies talking
       about it to other people but can also crystallize the purpose of the machine.
        Purpose: This should be a brief one- or two- line description of what the system is supposed to
        do. If you can’t describe the essence of your system in one or two lines, chances are that you
        don’t understand it well enough.
        Inputs and outputs: These two entries are more complex than they seem. The inputs and
        outputs to the system encompass a wealth of detail:
        Types of data: Analog electronic signals? Digital data? Mechanical inputs?
        Data characteristics: Periodically arriving data, such as digital audio samples? Occasional user
        inputs? How many bits per data element?
        Types of I/O devices: Buttons? Analog/digital converters? Video displays?
        Functions: This is a more detailed description of what the system does. A good way to
        approach this is to work from the inputs to the outputs: When the system receives an input, what
        does it do? How do user interface inputs affect these functions? How do different functions
        interact?
          Performance: Many embedded computing systems spend at least some time controlling
          physical devices or processing data coming from the physical world. In most of these cases,
          the computations must be performed within a certain time frame. It is essential that the
                                                1
performance requirements be identified early since they must be carefully measured during
implementation to ensure that the system works properly.
Manufacturing cost: This includes primarily the cost of the hardware components. Even if
you don’t know exactly how much you can afford to spend on system components, you should
have some idea of the eventual cost range. Cost has a substantial influence on architecture: A
machine that is meant to sell at $10 most likely has a very different internal structure than a
$100 system.
Power: Similarly, you may have only a rough idea of how much power the system can
consume, but a little information can go a long way. Typically, the most important decision is
whether the machine will be battery powered or plugged into the wall. Battery-powered
machines must be much more careful about how they spend energy.
Physical size and weight:You should give some indication of the physical size of the
system to help guide certain architectural decisions. A desktop machine has much more
flexibility in the components used than, for example, a lapel mounted voice recorder.