Right-click here to get the skeleton program for this project.
- This program uses version 3 of the S215 standard functions file.
- Version 3 contains the Delay( ) function and also the Initp( ) function.
- Delay( ) is exactly like the variable delay function we have already been using.
- Initp(mode, inverted )
provides for choosing which PIC pins are used for input and which are
used for output. It also provides for using inverted or non-inverted
logic. If the mode parameter is 0, the 5 lines of port A will be used as input and the 8 lines of port B will be used for output. If the mode parameter is 1, the reverse is true. The inverted parameter specifies non-inverted logic if it is a 0 and inverted logic if it is a 1.
- The skeleton program file contains the Gib( ) function. It works as shown on the flowchart. Gib stands for "get input bit." This function will streamline the writing of future programs. It contains a call to GetInBts( ) to read from the input switches. It also contains a call to SelBit( ) to choose the bit we are interested in. Now, instead of calling GetInBts( ) and SelBit( ) in the main program, we can simply call Gib(bitno), where bitno is the desired input bit. For example, Gib(5) will return the status of input switch 5.
- The skeleton program file also contains the Ckedge( )
function, which returns a 1 if there is a leading edge; a 2 if we are
between the leading edge and the trailing edge; a 3 if there is a
trailing edge; and a 0 if we are between the trailing edge and the
leading edge.
- This project's program works as follows:
- Call Ckedge to determine if there has been a leading edge or a trailing edge for in0.
- If there is a leading edge, wait a delay and check the status of in0 to see if it is still high. If it is, put a high into out0.
- If there is a trailing edge, wait a delay and check the status of in0 to see if it is still low. If it is, put a low into out0.
- Output out0 to LED 0.
- Notice that we have to call Gib( ) before checking to see if in0 is high or low after each delay has timed out. If we didn't do this, in0 would still have the same value it did when we checked it at the very beginning of the program.
- To let us see what's happening with the two delays, we're
turning on LED 7 during the leading edge delay and LED 6 during the
trailing edge delay.
|