When this idea arose, a serial bus LCD indicator was required. A modern display was not at hand and an ancient LCD with a driver µPD7225 was used for verification. When the task was solved, it became clear that the indicators available today are just a special case.
When using microcontrollers with a small number of legs, you often face the problem of lack of I / O ports. The resources of the microcontroller are enough "by the eye" to solve the problem, but the ports are not. There is a temptation to "load" already occupied. As an example, let us consider a simple two-channel voltmeter on the MK tiny13, in which two ports are analog inputs and two are a serial LCD interface. Expand the functionality of the device can only be using the serial data bus (SD). Moreover, she almost always rests. Data transfer to the indicator takes a maximum of two to three hundred microseconds, the update is no more than once every 300 ms. The clocking line (CLK) cannot be used for obvious reasons. A simple device lacks a pair of buttons to switch modes and display these modes, especially when the display is small. That's the problem ...
First, connect the indicator to a two-wire serial interface. To control the LCD with the µPD7225, 6 signal lines are required: RESET, CS, C / D, BUSY, SI, SCK. The last two have nothing to discuss, we have already mentioned them. The rest, in order: reset, chip select, command / data and readiness, which is generated by the LCD driver. A two-wire display connection diagram is shown in Figure 1 on the right. The reset of the crystal occurs once at power on and is carried out by the R2C2 circuit, provided for by the documentation on the driver.
Active low CS is formed by a low level on the sync line. While data is being written to the LCD, capacitor C1 is discharged through the diode VD1. After the last entry, the CLK is set to "1" and C1, charging through R1, removes the resolution of the crystal.
Before writing the command sequence to the indicator, you must set a high level on the SD bus and wait for C3 to charge through R3. The recording time of a few bytes is not enough for the voltage on C3 to change significantly. To record data, the C3 is discharged low on SD. Instead of polling the BUSY signal, which is expensive to do, the program generates a time delay after the edge of the pulse, before writing the next byte. The readiness signal is removed by the driver after each byte has been recorded and when CS is removed, as shown in the waveform.
To be sure of the reliability of the circuit, we tested another LCD with a similar interface - KTM-S1201. The driver is the same, the clocking parameters differ by 20%.
I had to adjust the delay constants and add the missing contrast adjustment circuit. For the 8-bit NEC indicator, the pt13.asm program is intended, for the 12-bit KTM-S1201 - pt23.asm. Connecting to the microcontroller through the standard for these indicators 8-pin rectangular connector.
It is clear that more modern LCDs with sequential control are much easier to connect to two buses.
The control and indication circuit is shown in Fig.1 in the center. A chain of three LEDs and a pair of resistors with two ordinary buttons without latching allows you to get a set of voltages in the nodes necessary and sufficient for reliable identification of pressing, and also allows you to independently control two LEDs of different colors using the capabilities of the standard output port. Consistently connected red diodes will be counted as one with a doubled direct voltage drop. Since the LEDs are used here not only for their intended purpose, but also as zener diodes, to begin with, let us warn that any substitution for LEDs with a different color than those indicated will hardly lead to good results. The same applies to the supply voltage of the circuit.
In the initial state (the buttons are not pressed), the voltage at the junction point of the diodes is 2.1V. There is no glow, there is little voltage on each of the diodes. Pressed upper / lower - 1.4 / 4.8V. To distinguish between levels, the microcontroller must be able to analog-to-digital conversion on the selected port for connecting the circuit. Then everything is standard.
The port is configured as an input, conversion of input voltage, comparison of the code with the set thresholds, suppression of "bounce" and generation of pressure flags. The logic of the scanning program is arranged so that the first pressing of the selected button sets its flag, the second - resets. Another program controls the LEDs. The third port state is used to enable and disable them independently. Low port lights red LEDs, high green. So that all the LEDs can be lit at the same time, the usual principle of dynamic indication is used. Maintenance costs are scanty.
The control circuit of its only input / output is connected to the SD bus of the serial LCD interface. In the pause between calls to the indicator, the bus is translated to high-impedance, and the clocking bus is in a passive state. Now the level on the SD bus is determined by the LED-resistive-button circuit, which can vary in one direction or another from the middle, depending on the button pressed, by the amount of the forward voltage drop across the LEDs. After the ADC cycle, the microcontroller, in the time-sharing mode, controls the LEDs. The circuit can be connected optionally to any convenient port of any microcontroller, for setting operations, checking or searching for program buggy. In this case, it is necessary to provide for a simple check of its presence during initial initialization, a sign of which is the voltage level “none zero or one”. The circuit does not affect the operation of the interface of the indicator and does not require any significant expenditure of the program memory of the microcontroller. This is clearly seen in the size of the demo HEX file.
The operation of the control circuit is illustrated with an oscillogram of signals on the SD bus of the serial interface. The pict on the left is the moment of polling the state of the buttons. "Paling" to the right of the center - update the indicator.
Choosing element base consider the following. Green SMD LEDs are rejected due to low brightness at the selected current. I had to use a 3 mm LED. To test, turn it on to the 5V circuit through a 10K resistor. Brightness should suit you. Red LEDs are suitable for any. It is not necessary to pay attention to the LED glow at the moment of pressing the button (such is the diagram), since change of information in the register of the microcontroller occurs when the button is released. Some time is still required to activate the new output cycle (the old one may not be finished yet), so take it as a wink at the controller to you personally, no more. No inconvenience during the work is noted. The only feature, a short flash of LEDs when the indicator is updated, can be considered an indication of the operating state of the device.
The demonstration program is written in assembler, compiled for ATtiny13 under two indicators and contains only what is necessary to understand the principle of the interface and control scheme operation in a real device. The LED of the corresponding button lights up when first pressed and goes out when the second. This limits the processing of click flags in the program. The developer has a free port to control, depending on the functional purpose of the device and the "reset" input is in stock. The remaining free program memory, which is almost half of all, should be enough to provide the device with specific additional functions. Using tiny25 / 45/85 removes the memory problem altogether.
To select the conversion factors for the voltmeter channels, use the Coef constants in the source. Their selection when compiling the program makes it unnecessary to use trimming resistors in the dividers of the input circuits and allows the use of a voltmeter in the input voltage range up to 99.9V. Although two digits are displayed after the comma, it should be understood that the accuracy is limited by the microcontroller's ADC digit capacity. Averaging over 64 counts allows us to observe changes within tens of millivolts of input voltage above 10V with high stability of readings. The nominal values of the resistors of the input divisors are selected from the condition that the supply voltage at the microcontroller leads is not exceeded, followed by the correction of constants in the program to match the readings. Values fuses MK in the source text. It is necessary to turn off the divider by 8, the rest by default.
The author points out that the choice of a voltmeter to demonstrate additional features of a serial interface is purely pragmatic. In the test program it was easy to add a couple of functions. Application of this idea in designs on microcontrollers in housings with a small number of ports allows expanding the functionality already in finished devices by simply connecting the described control circuit and modifying the software component.
I2C bus also applies to two-wire interfaces. It would be tempting to transfer the idea of double use of a serial bus to it, especially since there are many LCD indicators of this standard. Even the domestic manufacturer produces a dozen titles.
The obvious solution is to mirror a series of LED-resistive circuits so that there is no voltage above half the supply voltage at the midpoint in the initial state. Bus operation is based on the principle of "mounting or" and the low level current should be within the required limits. To ensure this parameter, while maintaining the ability to identify button presses by different voltage levels at the connection point of indicator LEDs, the scheme shown in Fig. 2
To offset the initial level, a parametric stabilizer is applied on the LED VD3, the current through which sets the resistor R3. This LED can be used as an indicator of device operation. The demonstration program of the voltmeter described above, but intended to work with the indicator MT-10T11 (MELT LLC) and the control-display circuit, is present.
ATTENTION: SDA bus pull-up resistor is not installed, it performs its functions
control circuit-indication. An SCL bus pull-up resistor is mounted on the indicator.
Source: https://habr.com/ru/post/358338/
All Articles