Surprise Me!

PIC16 Microcontrollers, Unit 10, Ch. 3; Parallel Output Port Write Timing Wavefo_HD

2015-11-09 1 Dailymotion

Building a parallel interface:: <br />Itshouldbesimpletocreateasetofoutputpinstocreatean‘output’port(Figure3.1).Letus <br />assign an address in the memory map to the port. Whenever that address is selected by an <br />instructionintheprogram,itactivatesalinecalled‘PortSelect’.Afurtherline,‘Read/Write’, <br />indicates whether the CPU is undertaking a Read (line is high) or Write (line is low) oper- <br />ation. This is gated with the Port Select line. Each line of the data bus is connected to <br />abistable,andalloftheseareclockedbythePortSelectline.Thenthevalueofthedatabusis <br />latchedintothebistablewhenevertheportmemorylocationisaddressed,inWritemode.The <br />outputs of the bistables are made available for connection to the outside world. <br />It is equally simple to create a set of input pins (Figure 3.2). All that is needed is a tristate <br />buffer gate connected between an external pin and a line of the data bus. When the buffer is <br />enabled, again by a logical combination of Port Select line and Read/Write control, the <br />logic value of the external pin is briefly connected to the data bus line, and can be read <br />by the CPU. Note that in this design the external data is not latched by the port; it must be <br />held at a stable value by the external source. <br />These ideas are quite attractive, but the reality is that it is inflexible to limit an external pin of <br />an IC to just one function, whether input or output. It would be much neater to combine <br />somehowthetwocircuitsusedforinputandoutput,andlettheuserdecideinwhichdirection <br />he/she wants the data to move. The diagram of Figure 3.3 does just that. It shows <br />apossible‘pindriver’circuitforonebitofaparallelport.Itiseasytopickoutinitthecircuits <br />of Figures 3.1 and 3.2. What must be added, however, is a further flip-flop (‘Direction’), <br />which is set to determinewhether this microcontroller pin is to act as an input or output. The <br />state of this flip-flop is set by the program. It controls the ‘Output buffer’, which is enabled <br />when the port bit is in output mode. <br />This circuit forms the basis for a very useful bi-directional input/output pin driver, and it is <br />easy to find versions of it in many popular microcontrollers. Sets of I/O pins are grouped <br />together to form a parallel I/O port. Each ‘Data’ flip-flop then forms one bit of a ‘Data’ SFR <br />(Special Function register), and each ‘Direction’ flip-flop forms one bit of a ‘Direction’ SFR, <br />asseeninFigure3.3.EachSFRismemorymapped,withitsownuniqueaddress.Derivedfrom <br />that address is its select line, which goes high when that location is addressed. ‘Port Select’ <br />selects the Data SFR and ‘Direction Select’selects the Direction SFR. <br />By writing to the Direction SFR the user can determine which bits are to be input and which <br />are to be output. By writing to the Data SFR he/she can set the value of all Data flip-flops, <br />whether that pin is actually set as an output or not. This value is transferred to the I/O pin <br />throughthebufferforthosepinswhichareenabledasoutputs.ByreadingfromtheDataSFR <br />theprogramcanacquirethelogicalvalueoftheI/Opin.Ifthepinissetasoutput,thisvalueis <br />simply the value held by the Data flip-flop and asserted on the I/O pin through the Output <br />buffer. If the pin is set as an input, then an external signal should be connected to the pin, and <br />the controller will read its value.

Buy Now on CodeCanyon