Download m68332evkem/ad1
Transcript
EXAMPLE PROGRAMS 3.2.2.2 Example 3: Event Detection Example 3 illustrates another important use of the DIO mode: detecting an event, such as a box on a conveyer belt passing in front of a photo detector, then generating an interrupt (if enabled) and interrupt flag. This requires detection of a timer pin state transition. Program 3 (or the user) must perform these actions to use the state-transition capability of the DIO mode: 1. Connect a jumper between the TP0 and TP1 pins of PFB connector P2. (This is a physical connection the user must make; the program does not make this connection.) 2. Load the value $8 in the channel function select field of channel function select register 3. 3. Load a priority value in the channel priority field of channel priority register 1. Note that there is no default priority; if the program does not load a priority value, the channel cannot generate host service requests. 4. Write the value $000F to the channel control register. As table 3-2 indicates, this value determines that the channel is an input and that either edge is detected. 5. Load the value $00 in the host sequence field of host sequence register 1. This determines that updates occur on transition. 6. If interrupts are to be used, write the value 1 to the appropriate channel interrupt enable register. (Example 3 does not use interrupts, and the power-up restart presumed to precede all programs of this manual clears the channel interrupt register. Accordingly, Program 3 need not include any interrupt instruction.) 7. Load the value %11 in the host service request 1 register. This determines that an interrupt will be generated when a rising edge is detected on the timer pin. Program 3 sets up channel 0 to generate a square wave pulse, and channel 1 to sample the values of channel 0. Before running this program, make sure to install a jumper between the TP0 and TP1 pins of PFB connector P2. M68332EVKEM/AD1 3-15