![]() |
McMajan Library Pack
v 2.00
Improve your Arduino !
|
Before start to post detail, 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. This is only an example, but you can mix digital output and displays as you want. For example you can use 3 shift register to control 24 digital outputs and in the same chain use the 4th e 5th shift registers to connect 2 displays. You have only the limit of 256 shift registers (and the speed of all chain).
Press Here to see full size version
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 5x10 font instead the 5x8 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 0x00,0x40,0x14,0x54. If your display has 0x00,0x40,0x10,0x50 location as some 16x4 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); |
Version 1.00
This is the firs release. In the image below, you can see 2 lcd displays and one 7segment display, on the same chain.
Version 1.01
After the first release I presented my work to Italian Arduino Forum where I knew some people as "Peletta" (thanks for the previous image) and collected some useful suggestion, added in this new release:
Version 1.02
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 but using my library you can use every pin you want in every Arduino's clone. Only to understand what I'm talking, in a test a direct port manipulating require about 0.3 microseconds and the original digitalWrite 6 microseconds (15-20 times slower). 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 (on AVR Arduinos).
Version 1.03
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 needs 3676 microseconds.
Versione 1.04
The previous 1120ms for the debug sketch become 844ms.
Version 1.05
Integrated to McMajan Library Pack. Now the library can manipulate directly the Arduino's ports. If you set HC595_DP in the Ss_McMajan_Config.h file, the library'll uses direct port access. In this case you MUST use latch clock data on 2, 4, 7 pins.