Yet another 1-wire LCD
Using a microcontroller instead of a shift register this circuits uses a standard asynchr. serial interface.
Introduction.
I needed an LCD-display for a project, but only 1 pin was available for driving it. No problem; there are examples from Elektor and others for such an interface. Most of these use a shift register, which was not available in my private store. Therefore the same function will be realised in software using a small microcontroller.
But wait: why implement a new interface on both sides when standard interfaces exist?
So I decided to use the build-in USART for the connection. The lower layers of the interface are already realised in the microcontroller hardware, so the rest of the project became simple.
Hardware.
I used a 14-pin PIC microcontroller 16F1825, but the cheaper 16F1823 will also work. Most pins are needed for the display, but still 1 pin is available for a new function (or 2 if low voltage programming is disabled). Two serial inputs are available for the interface: an rs232 compatible one, which for instance can be connected to a PC (I used this one to test the firmware) and a direct connection to the PIC, which can be used to connect the circuit to another microcontroller. In the latter case Q2 and surrounding components can be omitted.
I designed a PCB for the circuit, but the final circuit is realised on veroboard because I needed only 1 piece.
The PCB therefore has never been produced and tested. Nevertheless the Eagle-files are added to use at your own risk.
Baudrate is 9600; therefore the simple cicuit with Q2 can be used to convert from RS232 to a microcontroller compatible signal. The baudrate is also chosen low because this way the sending system doesn't have to include waits after certain commands.
Q1 is included to be able to switch off the backlight of the LCD.
Software.
The first idea was to realise the display as a small VT52 or VT100 terminal, but this was too much effort for such a simple device. The final version therefore does not contain much intelligence.
Initially the program simply sends the 4 LSB's of any received character to the LCD, using bit 4 to control the RS-input. Using ASCII-characters 0x20 to 0x3f (' ' to '?', see examples) the display can be fully controlled.
Later I added the possibility to switch on and off the backlight and to send 8 bit control and data. Sending a string for instance now can simply be done by putting the LCD in 8 bit data mode by sending a code followed by the string as ASCII-characters. Sending an Escape-character returns to 4 bit mode. Using 8 bit control is less usefull, because in many cases not more efficient than 4 bit control.
A second addition was a time-out on the reception of the second nibble in 4 bit mode. If it is not received within 1 second, the controller forgets the first nibble. The time-out can be made smaller by changing parameter MAXTIM and by another prescaler factor for timer 0. The time of 1 second was needed
as I did my first tests by typing the commands on my PC keyboard.
Because the lack of intelligence, all kind of displays based on HD44780 and compatibles can be used. Information about number of lines and characters are kept on the sending side.
Following control codes are available (so don't use these codes for characters in 8 bit mode!):
CTRL-A (0x01) - backlight off
CTRL-B (0x02) - backlight on
CTRL-C (0x03) - send 8 bit control
CTRL-D (0x04) - send 8 bit data (ASCII)
CTRL-E (0x05) - erase display
Escape (0x1b) - 4 bit control and data
The prgram is compiled by the B.Knudsen CC5X compiler.
Examples
.- clear display, backlight on and print 'test 1' on line 1 using 8 bit interface:
0x05,0x02,0x04,'test 1' (ctrl-e,ctrl-b,ctrl-d,'test 1')
- same using 4 bit interface:
0x1b,0x20,0x21,0x02,0x37,0x34,0x36,0x35,0x37,0x33,0x37,0x34,0x32,0x30,0x33,0x31 (Esc,' !',ctrl-b','746573742031')
- print 'line 2' on second line of display using 8 bit interface:
0x03,0xc0,0x04,'line 2'
- same using 4 bit interface:
0x1b,0x2c,0x20,0x36,0x3c,0x36,0x39,0x36,0x3e,0x36,0x35,0x32,0x30,0x33,0x32 (Esc,', 6<696.652032')
- print 'Hello' on third line of 4x20 display using 8 bit interface:
0x03,0x94,0x04,'Hello'
- same using 4 bit interface:
0x1b,0x29,0x24,0x34,0x38,0x36,0x35,0x36,0x3c,0x36,0x3c,0x36,0x3f (ESC,')$48656<6<6?')
I needed an LCD-display for a project, but only 1 pin was available for driving it. No problem; there are examples from Elektor and others for such an interface. Most of these use a shift register, which was not available in my private store. Therefore the same function will be realised in software using a small microcontroller.
But wait: why implement a new interface on both sides when standard interfaces exist?
So I decided to use the build-in USART for the connection. The lower layers of the interface are already realised in the microcontroller hardware, so the rest of the project became simple.
Hardware.
I used a 14-pin PIC microcontroller 16F1825, but the cheaper 16F1823 will also work. Most pins are needed for the display, but still 1 pin is available for a new function (or 2 if low voltage programming is disabled). Two serial inputs are available for the interface: an rs232 compatible one, which for instance can be connected to a PC (I used this one to test the firmware) and a direct connection to the PIC, which can be used to connect the circuit to another microcontroller. In the latter case Q2 and surrounding components can be omitted.
I designed a PCB for the circuit, but the final circuit is realised on veroboard because I needed only 1 piece.
The PCB therefore has never been produced and tested. Nevertheless the Eagle-files are added to use at your own risk.
Baudrate is 9600; therefore the simple cicuit with Q2 can be used to convert from RS232 to a microcontroller compatible signal. The baudrate is also chosen low because this way the sending system doesn't have to include waits after certain commands.
Q1 is included to be able to switch off the backlight of the LCD.
Software.
The first idea was to realise the display as a small VT52 or VT100 terminal, but this was too much effort for such a simple device. The final version therefore does not contain much intelligence.
Initially the program simply sends the 4 LSB's of any received character to the LCD, using bit 4 to control the RS-input. Using ASCII-characters 0x20 to 0x3f (' ' to '?', see examples) the display can be fully controlled.
Later I added the possibility to switch on and off the backlight and to send 8 bit control and data. Sending a string for instance now can simply be done by putting the LCD in 8 bit data mode by sending a code followed by the string as ASCII-characters. Sending an Escape-character returns to 4 bit mode. Using 8 bit control is less usefull, because in many cases not more efficient than 4 bit control.
A second addition was a time-out on the reception of the second nibble in 4 bit mode. If it is not received within 1 second, the controller forgets the first nibble. The time-out can be made smaller by changing parameter MAXTIM and by another prescaler factor for timer 0. The time of 1 second was needed
as I did my first tests by typing the commands on my PC keyboard.
Because the lack of intelligence, all kind of displays based on HD44780 and compatibles can be used. Information about number of lines and characters are kept on the sending side.
Following control codes are available (so don't use these codes for characters in 8 bit mode!):
CTRL-A (0x01) - backlight off
CTRL-B (0x02) - backlight on
CTRL-C (0x03) - send 8 bit control
CTRL-D (0x04) - send 8 bit data (ASCII)
CTRL-E (0x05) - erase display
Escape (0x1b) - 4 bit control and data
The prgram is compiled by the B.Knudsen CC5X compiler.
Examples
.- clear display, backlight on and print 'test 1' on line 1 using 8 bit interface:
0x05,0x02,0x04,'test 1' (ctrl-e,ctrl-b,ctrl-d,'test 1')
- same using 4 bit interface:
0x1b,0x20,0x21,0x02,0x37,0x34,0x36,0x35,0x37,0x33,0x37,0x34,0x32,0x30,0x33,0x31 (Esc,' !',ctrl-b','746573742031')
- print 'line 2' on second line of display using 8 bit interface:
0x03,0xc0,0x04,'line 2'
- same using 4 bit interface:
0x1b,0x2c,0x20,0x36,0x3c,0x36,0x39,0x36,0x3e,0x36,0x35,0x32,0x30,0x33,0x32 (Esc,', 6<696.652032')
- print 'Hello' on third line of 4x20 display using 8 bit interface:
0x03,0x94,0x04,'Hello'
- same using 4 bit interface:
0x1b,0x29,0x24,0x34,0x38,0x36,0x35,0x36,0x3c,0x36,0x3c,0x36,0x3f (ESC,')$48656<6<6?')
Updates van de auteur