Page 366 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 366

PROBLEMS                                                            343


        10. Write a shortest assembly-language program to output data from a buffer using
        autoincrernent addressing to Port B each time Port A bit 7 rises from low to high.
        Instead of using LDAA B,X STAA l,use  LDAA 1,X+ STAA 1 to transfer a byte
        from input to buffer. The program outputs ten bytes from vector BUFFER and exits.

        11. Write a shortest assembly-language program to input data, from Port B each time
        Port A bit 7 rises from low to high, to a buffer using autoincrernent addressing. Instead
        of using LDAA 1 STAA B,X, use      LDAA 1 STAA      1,X+ to transfer a byte
        from the input to the buffer. The program should store ten such bytes in vector
        BUFFER and then exit.

        12. In Figure 11.7, if the two least significant bits of port TCTLE, which is the 16-bit
        port at $8a, are 10 instead of 01, the flag, which is the least significant bit of TFLG1
        and is the 8-bit port at $8e, is set on the rising edge. Write a shortest program segment
        to initialize the device and a shortest program segment to gadfly until a rising edge
        occurs on PORTT bit 0.

        13. In Figure 11.7, if the two least significant bits of port TCTLE, which is the 16-bit
        port at $8a, are 11 instead of 01, the flag, which is the least significant bit of TFLG1
        and is the 8-bit port at $8e, is set on both the rising and falling edge. Write a shortest
        program segment to initialize the device and a shortest program segment to gadfly until
        an edge of either type occurs on PORTT bit 0.

        14. Write a shortest program to initialize the devices and input a byte from PORTA to
        the 10-element BUFFER in an interrupt handler each time a rising edge occurs on PORTT
        bit 0.

        1 5. Write a shortest program to initialize the devices and input a byte from PGRTA to
        the 10-element BUFFER in an interrupt handler each time a rising or a falling edge
        occurs on PORTT bit 0.

        16. Explain why interrupts are useful when unexpected requests are made from a device
        but are actually slower than gadfly routines when expected requests are made from a
        device,

        17. Give two concrete examples of devices that will require each of the following
        synchronization mechanisms, so that they should only use that mechanism and no other,
        and give reasons for your choice: real-time, gadfly, and interrupt. For example, a
        microcontroller in an electric stapler, that generates a pulse to engage a solenoid, should
        use real-time synchronization, because the microcontroller is doing nothing else, and this
        is the least costly approach, requiring minimal hardware.

        18. An A-to-D converter consists of (1) a D-to-A converter that outputs data through
        PORTA in Figure 11.10, which is converted to an analog voltage Vref, and (2) an analog
        comparator that compares Vref to an input voltage Vin, inputting a high (1) in PORTS
        bit 7 if Vref < Vin, otherwise inputting a low (0). Write a shortest subroutine RAMP
   361   362   363   364   365   366   367   368   369   370   371