# ch08 - Chapter 8 Exercises Solutions E8.1 It takes the...

This preview shows pages 1–3. Sign up to view the full content.

Chapter 8 Exercises Solutions E8.1 It takes the 68HC11 3 E clock cycles to fetch the instruction "LDD \$100E". The main counter value is \$1000 when it is being fetched. Therefore, the D accumulator will contain the value \$1003. E8.2 The pin PA5 is controlled by OC3. The bits 5 and 4 of the TCTL1 control the action of this pin. Bits 5 and 4 must be set to 01 in order to toggle the pin PA5. Other bits in the TCTL1 should be set to 0s so that no other port A pins should be affected. Therefore, the value %00010000 should be written into TCTL1. E8.3 Using the interrupt-driven method, we need to provide an interrupt service routine. The interrupt service routine will either pull the signal to high or low. An easy way to tell the interrupt service routine what to do is to use a flag. When the flag is 1, pull the signal to high. Otherwise, pull it to low. The flag will be initialized to 0. The interrupt service routine will toggle the flag every time it is entered. REGBAS equ \$1000 ; base address of I/O register block PORTA equ \$00 ; offset of PORTA from REGBAS TOC2 equ \$18 ; offset of TOC2 from REGBAS TCNT equ \$0E ; offset of TCNT from REGBAS TCTL1 equ \$20 ; offset of TCTL1 from REGBAS TFLG1 equ \$23 ; offset of TFLG1 from REGBAS TMSK1 equ \$22 ; offset of TMSK1 from REGBAS hitime equ 800 ; value to set high time to 400 μ s lotime equ 1200 ; value to set low time to 600 μ s toggle equ \$40 ; value to select the toggle action OC2 equ \$40 ; value to select OC2 pin and OC2F flag clear equ \$40 ; value to clear OC2F flag sethigh equ \$40 ; value to set OC2 pin to high ORG \$00 hlflag rmb 1 ; a flag to indicate OC2 action to be setting high or low ORG \$FFE6 ; set up the OC2 interrupt vector FDB oc2_ISR ; " ***************************************************************************** * Use the following assembler directives to replace the previous two directives if the program * is to be run on the EVB * * ORG \$00DC * JMP oc2_ISR ***************************************************************************** ORG \$C000 ; starting address of the program LDX #REGBAS 7- 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
LDS #\$DFFF ; initialize the stack pointer BSET PORTA,X OC2 ; set OC2 pin to high LDAA #1 STAA hlflag ; initialize the flag to 1 LDAA #clear STAA TFLG1,X ; clear the OC2F flag LDAA #toggle ; select the OC2 action to be toggle STAA TCTL1,X ; " * the following 3 instructions start the OC2 output compare with a delay of 400 μ s LDD TCNT,X ; start an OC2 compare with a delay equal to 400 μ s ADDD#hitime ; " STD TOC2,X ; " * the following instructions enable the OC2 interrupt BSET TMSK1,X OC2 CLI ; enable interrupt to the 68HC11 wait BRA * ; stay in an infinite loop oc2_ISR LDAA #clear ; clear the OC2F flag STAA TFLG1,X ; " TST hlflag ; test the flag BEQ zero ; branch if the flag is zero CLR hlflag ; toggle the the flag LDD TOC2,X ; pull OC2 pin to high after 1200 E clock cycles ADDD#lotime ; " STD TOC2,X ; " BRA exit ; prepare to return zero LDAA #1 ; set the flag to 1 STAA hlflag ; " LDD TOC2,X ; pull OC2 pin to low after 800 E clock cycles
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 18

ch08 - Chapter 8 Exercises Solutions E8.1 It takes the...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online