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

344                                               Chapter 11 Input/ Output

         that begins outputting Vref = 0, increments Vref until it just exceeds Vin, and returns
        the byte it last output in PORTA. This is called a ramp converter.

         19. An A-to-D converter is connected as in Problem 18. Write the shortest subroutine
         SUCCESS that begins outputting Vref = 2.5 and recursively determines whether Vin is
         in the upper or lower half of the range, reducing the range by one half each time it
        determines which half of the range Vin is in. SUCCESS returns the final value output
        on PORTA. This divide-and-conquer algorithm is like binary number division; it is called
         successive approximation conversion.

        20. For the compiled C procedure in Figure 11.18, encircle and label the following C
        statements and assembly-language program segments: (1) declaration of global
        variables; (2) declaration of I/O ports; (3) declaration, allocation, and deallocation of
        local variables; (4) the initialization ritual; (5) for loop control statements to output
        str; (6) while loop control statements to input until a carriage return; (7) gadfly loops;
        (8) input operation; and (9) output operation. Next to each circle, write the label shown
        above in italics or a number enclosed in parentheses () to identify which part the code
        corresponds to. If one of the above appears in two parts, circle each part.

         21. For the compiled C procedure in Figure 11.19, encircle and label the following C
         and assembler program segments: (1) declaration of global variables; (2) declaration of
        I/O ports; (3) declaration of local variables; (4) the initialization ritual; (5) the loop
        control statements to try each value from 1 to 128; (6) the gadfly loop; (7) the input
        operation; (8) the output operation; (9) calculation and collection of results; and (10)
         an infinite loop to stop the program. Next to each circle, write the label shown above
         in italics or a number enclosed in parentheses () to identify which part the code
        corresponds to.

         * volatile int SClBD@OxC8;volatile char SClCR@OxCB,SClSR@OxCC,SClDR@QxCF;
         SClBDi      EQU    $C8
         SC1CR:      EQU    $CB
         SC1SR:      EQU    $CC
         SC1DR:      EQU     $CF
                     ORG    $800

         * char j; const char str[10] = "Hi ThereXr";
         j:          DS.B 1
         str:        DC.B "Hi ThereXr"

         * void put(char d) { while( ( SC1SR & 0x80 ) == 0) ; SC1DR = d; }

        put:         BRCLR SC1SR,$80,put
                     STAA     SC1DR
                     RTS

         * char get{) { while( ( SC1SR & 0x20 ) == 0) ; return SC1DR; }
   362   363   364   365   366   367   368   369   370   371   372