Arduino: library for controlling digital out and 74HC595 LCD display together – en

 

 

In a previous article I presented a new library to control in a simple manner daisychains of chip 74HC595, as regards both the classic digital outputs and the use of the LCD display. I opened this page to keep track of updates that will be made gradually, so I’m not forced to modify the original article. I remind you that the main feature of the library is the ability to manage AT THE SAME TIME on the same line, up to 256 74HC595 chip with the ability to MIX displays and digital outputs.

Wiring diagram

Before start to post newest revisions, I give you the wiring diagrams, so you always have them at a glance. As you can see there are two shift registers, the first connected to a display and the second one to a ULN2803A, useful for example if you want to connect some relays. The display must be connected exactly as in the diagram. Note the free output number zero and two of the corresponding 74HC595 to maintain the compatibility with original LiquidCrystal library.

LCD e Out 74hc595_schem

Usage

I prepared a summary table with all the functions of the library. In the first column you can see the function with its parameters, in the second the version, in the third is specified when the function is applied to the display or to the digital outputs (or both ), then there is a short description and a final column with a simple example. The functions that begin with Set, changes the data of the internal buffer but NOT send data to the shift register, whereas the functions that begin with Send send the data to the shift register.

Function Vers. Target Description Example  
hc595(latch,clock,data,sr); 1.00 LCD / DIGOUT It prepares the hc595 instance object. The parameters are the latch,clock and data pins. The last one is the number of shift registers connected. hc595 My595(12,11,13,4);
Set595Pin(D7,D6,D5,D4,D3,D2,D1,D0,sr) 1.00 DIGOUT It sets the internal buffer with the singular bit (D7-D0) for the specified shift register on last parameter (remember that first shift register is the number zero). This function modifies only the internal buffer without send real data to shift-registers: to do this use the Send595() function.  
Set595Pin(val,sr) 1.00 DIGOUT It sets the internal buffer using a char (8bit) for the specified shift register on last parameter (remember that first shift register is the number zero). This function modifies only the internal buffer without send real data to shift-registers: to do this use the Send595() function.  
Send595(); 1.00 LCD / DIGOUT It sends the internal buffer to the shift register chain. This produce a update of all outputs of all shift registers. My595.Send595();
Send595Pin(val,sr); 1.00 DIGOUT It works as the sum of Set595Pin and the Send595, in the sense that sets the 8-bit and sends them directly to the shift register. If you have only one shift register to edit you should use this function. If you need to change more than one at the same time you should use two or more Set595 and eventually Send595. My595.Send595Pin(170,3);
ResetDisplay(options,sr);la funzione è stata sostituita con la DisplayReset nella v1.01 1.00 LCD Initialize the display connected to sr register. The options are: LCD595_BASIC_DISPLAY_INIT: it does the standard reset LCD595_USEFONT_5X10: use the 5×10 font instead the 5×8 LCD595_MORELINES: use displays with more than one line. My595.ResetDisplay(LCD595_BASIC_DISPLAY_INIT | LCD595_MORELINES ,3);
SetCursor(X,Y,Type,sr) 1.00 LCD It sets the cursor position at X,Y (start from 0,0). sr as the other functions is the number of the shift register (zero for the first, one for the second….). Type is basically sets to 1 that indicate a display in with the memory location of first char of each rows is 0×00,0×40,0×14,0×54. If your display has 0×00,0×40,0×10,0×50 location as some 16×4 displays, you must use 2. If you found other configurations, please alert me. My595.SetCursor(5,2,2,3);
SetDDRAM_Address(address,sr); 1.00 LCD Instead using SetCursor you can use this function to set directly the SDRAM address for cursor positioning. In this way you can use atypical displays where SetCursor fails. My595.SetDDRAM_Address(0x40,3);Posiziona il cursore su 0x40 ossia il primo carattere della seconda riga della stragrande maggioranza dei display. Nell’esempio viene settato sul quarto shift-register (3).
DisplayChar(char,sr); 1.00 LCD Write a char at the cursor position. char is the character and sr is the shift register number My595.DisplayChar(‘A’,3);
DisplayWrite(string,sr); 1.00 LCD Write the string “string” at the cursor position in the sr shift register number. My595.DisplayWrite(“Hello!”,3);
SendLcdCommanf(option,sr) 1.00 LCD This function is useful to send directly some commands to the display. The option parameter is a char in wich every bit will be sent to the display. There are some pre-set: LCD595_DISPLAY_ON_CB: Switch on the display with blinking cursor on. LCD595_DISPLAY_ON_C: Switch on the display with NOT blinking cursor. LCD595_DISPLAY_ON_B: Switch on the display with last char blinking. LCD595_DISPLAY_ON: Switch on display without cursor. LCD595_DISPLAY_OFF: Switch off the display LCD595_DISPLAY_CLEAR: Cleans the display. My595.SendLcdCommand(LCD595_DISPLAY_ON_C,3);
CreateChar(char,array,sr) 1.00 LCD Used to redefine some custom characters. The char is the number of the character to redefine (0-7). Array is a 8bytes array with the bitmap of new character. sr is the number of the shift register. byte MyChar[8] = {0,10,21,10,0,17,14,3}; My595.CreateChar(0,MyChar,3); My595.DisplayChar(0,3);
Lcd_SetFreePin(pin,value,sr) 1.01 LCD It sets the free pinsi (2 and 0) of 74HC595 connected to a display. pin is the pin (0 or 2), value is the state (HIGH o LOW) and sr is the shift register number. My595.Lcd_SetFreePin(2,HIGHT,3);
SetBackLight(pin,value,sr) 1.01 LCD If you connect the display’s back light to a free pin of the 74HC595 (through  resistor and transistor!!), you can use this function to set the corresponding pin. This function is identical to Lcd_SetFreePin. My595.SetBackLight(2,HIGHT,3);
DisplayClean(sr) 1.01 LCD Clean the display connected to shift register number sr. My595.Lcd_Clean(3);
DisplayReset(sr) 1.01 LCD It substitutes the older ResetDisplay My595.DisplayReset(3);

Versions

Version 1.00 Libreria hc595 (809 download )

This is the firs release. hc595Pelletta

Version 1.01 Libreria hc595 v1.01 (902 download )

After the first release I presented my work to Italian Arduino Forum where I knew some people as “Peletta” (thank for the image in right side) and collected some useful suggestion, collected in this new release:

  • Added compatibility with old IDE
  • Added Lcd_SetFreePin function to set directly the free pins (0 or 2) of the 74HC595.
  • Added the SetBackLight function to switch on / off the back light using pins zero or two: Obviously you must connect the back light through a resistor and transistor to a free pin. This function is identical to Lcd_SetFreePin, only the name is different.
  • Added the function DisplayClean to clear the display.
  • Added an example to the library directory.
  • Changed the name of ResetDisplay to DisplayReset (for omogeneity with others functions)
  • Now the DisplayReset don’t interfere to free 0 and 2 pins.

Version 1.02 Libreria hc595 v1.02 (912 download )

  • Some code optimisations.
  • Better lcd timings
  • Changed library name to lower case for Linux compatibility.
  • Added and supported the new small library  “FastArduino”.

In this version I done a great performance tuning. Anyone with a discrete knowledge about Arduino knows that the direct port programming is faster than the original digitalWrite function. However the direct port is not usable if you previously don’t know the pin needed and with my library can use every pin you want in every Arduino’s clone. Only to understand what I’m talking, a direct port manipulating require about 0.3 microseconds and the original digitalWrite 6 microseconds (15-20 times). Using original Arduino’s API the example sketch of my library is done in 7268 microsecond and with my library in 4872. From this version my library uses a new little library named FastArduino. In this library you have two new functions, FastdigitalWrite and FastShiftOut that are identical to originals but faster. You can use these functions on your sketches or other libraries. Note that hc595 library can work without FastArduino, just remove it or comment the inclusion. This feature is to avoid compatibility issues if you have problems.

Version 1.03  Libreria hc595 v1.03 (1775 download )

  • Great performance boost of display speed.

I found a incredible bug (confused nanoseconds with microseconds in the PulseE function). I corrected it and now the basic sketch speeds up from 4872 to 1120 microseconds, yes, 4 times faster!. Just for compare, the LiquiCrystal need 3676 microseconds.

Versione 1.04 – Non yet released

  • Further performance boost of display speed.

The previous 1120ms for the debug sketch become 844ms.

 

The library is now included on the McMajan library pack that is here.

 

  No Responses to “Arduino: library for controlling digital out and 74HC595 LCD display together – en”