|
| 1 | +## Use Of The Library |
| 2 | + |
| 3 | +### Create Instance |
| 4 | + |
| 5 | +The interface of the BC759x chip is a serial port, so the use of this driver library must also rely on the Arduino's serial port. The serial port can be either Arduino's hardware serial port (e.g. Serial, Serial1, Serial2, etc.) or software serial port (Software Serial). |
| 6 | +For models like the Arduino UNO, there is only one hardware serial port, and that serial port is already used for communication with the computer, so it is appropriate to use the software serial port, otherwise there will be conflicts with the IDE (unless the program is downloaded to the hardware using an external programmer that does not occupy the Arduino's serial port). |
| 7 | +Before use, the first step should be to include the library. After loading, the following statement appears in the Sketch editing window. |
| 8 | + |
| 9 | +```c |
| 10 | +#include <UART_7Seg_Display.h> |
| 11 | +``` |
| 12 | + |
| 13 | +then, for easy understanding and using, define an instant named LED_SERIAL: |
| 14 | + |
| 15 | +```c |
| 16 | +#define LED_SERIAL Serial1 |
| 17 | +``` |
| 18 | + |
| 19 | +Below the statements above, and before setup(), create the instance of the UART_7Seg_Display library, e.g. |
| 20 | + |
| 21 | +```c |
| 22 | +UART_7Seg_Display Disp(LED_SERIAL); |
| 23 | +``` |
| 24 | +
|
| 25 | +Where UART_7Seg_Display is the name of this driver class, Disp is the name given to the instance by the user, it can be anything, as long as it conforms to the Arduino variable naming rules. |
| 26 | +If you are using SoftwareSerial, you'll need 2 extra steps. The first step is to include the SoftwareSerial library, which is one of the standard libraries for Arduino. |
| 27 | +
|
| 28 | +```c |
| 29 | +#include <SoftwareSerial.h> |
| 30 | +``` |
| 31 | + |
| 32 | +The second step requires the creation of an instance of the software serial prior to the creation of an instance of UART_7Seg_Display. |
| 33 | + |
| 34 | +```c |
| 35 | +SoftwareSerial swSerial(11, 12); |
| 36 | +``` |
| 37 | +
|
| 38 | +Where swSerial is the name given to the instance by the user, which can be anything that matches the Arduino variable naming rules. In parentheses the 11, 12 are the RX and TX pins used by the software serial port. See the Arduino software serial port library for more information. |
| 39 | +The definition of the LED_SERIAL should also be changed to: |
| 40 | +
|
| 41 | +```c |
| 42 | +#define LED_SERIAL swSerial |
| 43 | +``` |
| 44 | + |
| 45 | +### setup() |
| 46 | + |
| 47 | +This library itself does not require any initialization to be used, but the serial port must be properly initialized to connect to the BC759x chip. The serial port must be initialized to baud rate 9600. |
| 48 | + |
| 49 | +```c |
| 50 | +LED_SERIAL.begin(9600); |
| 51 | +``` |
| 52 | + |
| 53 | +Although it can be used without initialization, because different PCB hardware designs may have different PCB layouts, it may be necessary to set the direction of the display in the initialization. If the library is set to display the opposite direction of the actual board, when the value is displayed, the position of the high and low digits will be reversed, for example, when displaying decimal numbers, the ones may be displayed on the leftmost side. |
| 54 | +The library has two functions to set the display direction, which are |
| 55 | +setDispLowDigOnLeft() and setDispLowDigOnRight() , respectively, represent the smaller digit number on the board is the 7-segment on the left side or right side. Users can call the corresponding function according to the design of the PCB, for example. |
| 56 | + |
| 57 | +```c |
| 58 | +Disp.setDispLowDigOnLeft(); // Notify the library of the smaller digit number is on the left |
| 59 | +``` |
| 60 | + |
| 61 | +If not set, the default setting is smaller digit number on the right. |
| 62 | +In addition, the clear function clear() is often used in the initialization section to clear all display content and blink attributes after a reset. |
| 63 | + |
| 64 | +```c |
| 65 | +Disp.clear(); |
| 66 | +``` |
| 67 | + |
| 68 | +### Display Content |
| 69 | + |
| 70 | +The BC759x chip has internal registers where the display content is written and will remain displayed until it is replaced by new content. Therefore the program only needs to call the library when the display content is to be updated. |
| 71 | +The library provides 3 functions related to display. |
| 72 | + |
| 73 | +- Display in decimal -- displayDec() |
| 74 | + |
| 75 | +- Display in hexadecimal -- displayHex() |
| 76 | + |
| 77 | +- Display float point value -- displayFloat() |
| 78 | + |
| 79 | +- Blink by digit -- digitBlink() |
| 80 | + |
| 81 | +For more information on the use of these three functions, see the function references section later. |
| 82 | +Only the three display-related functions above are provided, as other common operations can generally be completed by a BC727x instructions, encapsulated into a function does not simplify the user program. The following are some common scenarios: |
| 83 | + |
| 84 | +#### Display Special Characters |
| 85 | + |
| 86 | +Some special characters, such as "L", "H", "P", "-", etc., can be implemented by writing directly to the display register, using the BC759x direct register write instruction DIRECT_WT. For example, to display "L": |
| 87 | +sendCmd(DIRECT_WT|Pos, 0x38); // Where Pos is the display position and 0x38 is the character map of "L". For detailed instructions of BC759x, you can refer to the datasheet of BC759x. |
| 88 | + |
| 89 | +#### Display A Decimal Point |
| 90 | + |
| 91 | +The numeric display function, whether it is a decimal display or a hexadecimal display, will not affect the status of the decimal point. To control the status of the decimal point, you can use the segment addressing instruction SEG_OFF/SEG_ON of the BC759x. For example, to light up the decimal point in the 3rd position: |
| 92 | + |
| 93 | +```c |
| 94 | +sendCmd(SEG_ON, 0x1f); // Where 0x1f is the segment address of the decimal point of the 3rd digit. |
| 95 | +``` |
| 96 | +
|
| 97 | +#### Other Special Controls |
| 98 | +
|
| 99 | +Any control of the BC759x chip can be done by using the sendCmd() function, such as controlling the blinking speed, adjusting the display brightness, etc. For more information about the commands of the BC759x chip, please refer to the datasheet of the BC759x. |
| 100 | +
|
| 101 | +### Function Reference |
| 102 | +
|
| 103 | +#### sendCmd() : Send Command |
| 104 | +
|
| 105 | +Format: |
| 106 | +
|
| 107 | +```c |
| 108 | +sendCmd(Cmd, Data); |
| 109 | +``` |
| 110 | + |
| 111 | +This function can be used to send any command to the BC759x. The library only provides a few upper-level common display functions. If the user needs to have full control of the BC759x, this function needs to be called. There are two parameters, Cmd is the command to be sent and Data is the data to be sent. In "bc_led_disp.h" header file all the commands for the BC759x are listed. For detailed descriptions of the instructions for specific BC759x chips, please refer to the datasheets of the selected BC759x chip. All other functions provided by the library are implemented by calling this function. |
| 112 | + |
| 113 | +##### Predefined Commands: |
| 114 | + |
| 115 | +The following commands have already been defined in library and are ready to be used: |
| 116 | + |
| 117 | +- DIRECT_WT Direct write to display register |
| 118 | + |
| 119 | +- COL_WRITE Column write (BC7591 only) |
| 120 | + |
| 121 | +- BLINK_WT_CLR Segment blink clear |
| 122 | + |
| 123 | +- BLINK_WT_SET Segment blink set |
| 124 | + |
| 125 | +- SHIFT_H_WT Column insert and shift high(right) (BC7591 only) |
| 126 | + |
| 127 | +- ROTATE_R Rotate right(high) (BC7591 only) |
| 128 | + |
| 129 | +- ROTATE_L Rotate left(low) (BC7591 only) |
| 130 | + |
| 131 | +- SHIFT_L_WT Column insert and shift low(left) (BC7591 only) |
| 132 | + |
| 133 | +- DECODE_WT Decoded write |
| 134 | + |
| 135 | +- QTR_WT_BOT Quarter line write at bottom (BC7591 only) |
| 136 | + |
| 137 | +- QTR_INS_BOT Quarter line insert at bottom (BC7591 only) |
| 138 | + |
| 139 | +- QTR_WT_TOP Quarter line write at top (BC7591 only) |
| 140 | + |
| 141 | +- WRITE_EXT Direct write at extended position |
| 142 | + |
| 143 | +- QTR_INS_TOP Quarter line insert at top (BC7591 only) |
| 144 | + |
| 145 | +- DECODE_EXT Decoded write at extended position |
| 146 | + |
| 147 | +- SEG_OFF Segment OFF |
| 148 | + |
| 149 | +- COORD_OFF Coordinate OFF (BC7591 only) |
| 150 | + |
| 151 | +- SEG_ON Segment ON |
| 152 | + |
| 153 | +- COORD_ON Coordinate ON (BC7591 only) |
| 154 | + |
| 155 | +- BLINK_DIG_CTL Digit blink control |
| 156 | + |
| 157 | +- GLOBAL_CTL Global control |
| 158 | + |
| 159 | +- WRITE_ALL Write to all |
| 160 | + |
| 161 | +- BLINK_SPEED Blink speed |
| 162 | + |
| 163 | +- DIM_CTL Dim control |
| 164 | + |
| 165 | +- RESET_H Reset (as Cmd) |
| 166 | + |
| 167 | +- RESET_L Reset (as Data) |
| 168 | + |
| 169 | +- UART_SEND_0_H UART send 0 (as Cmd) |
| 170 | + |
| 171 | +- UART_SEND_0_L UART send 0 (as Data) |
| 172 | + |
| 173 | +#### clear() : Clear display and blink status |
| 174 | + |
| 175 | +Format: |
| 176 | + |
| 177 | +```c |
| 178 | +clear(); |
| 179 | +``` |
| 180 | + |
| 181 | +This function is used to clear all display and blink properties. |
| 182 | + |
| 183 | +#### displayDec() : Display Values In Decimal |
| 184 | + |
| 185 | +Format: |
| 186 | + |
| 187 | +```c |
| 188 | +displayDec(Val, Pos, Width); |
| 189 | +``` |
| 190 | +
|
| 191 | +This function displays the input value in decimal. Only unsigned values are accepted, and the display of negative values requires the user to write the '-' sign manually. If the higher significant digits are out of the display range of the chip, the excess will not be displayed and no error message will be given. |
| 192 | +Val is the value to be displayed, and the range is 0 to 4,294,967,295. |
| 193 | +Pos is the position of the display. The display position is based on the lowest digit, Pos value is the DIG number of the character where the lowest significant digit is located, the value range is 0-31. |
| 194 | +Width is the display width, the valid value range is 0-255. In the binary representation, the lower 7 bits are the display width value, and the 7th bit is the control bit of whether to display leading '0's or not. For example, if the Width is set to 5 and the Val value to be displayed is 132, the display result will be "␣␣132" (␣ stands for blank), if the Width value is 133 (5| 0x80, the highest bit in the binary representation of 5 set to '1'), then the result will be "00132". The valid range of the display width is 1-32. When the display width is set smaller than the width of the actual value, the exceeding part will not be displayed, and when the display width Width is larger than the width of the actual value, the exceeding part will be displayed blank or '0' according to the bit7 of Width. If the display position of the digit is beyond the display range of the actual chip, the excess part will be ignored. |
| 195 | +setDispLowDigOnLeft() and setDispLowDigOnRight() will affect the direction of the digit display. When setDispLowDigOnRight() is called, the lowest digit is displayed at the Pos position, and the higher digits of the displayed value will be displayed at the higher DIG position in order. And when using setDispLowDigOnLeft(), the lowest digit will be displayed at Pos position, and the more significant digits will be displayed at positions smaller than Pos in order. The library defaults to the state of setDispLowDigOnRight(). |
| 196 | +
|
| 197 | +#### displayHex() : Display Values In Hexadecimal |
| 198 | +
|
| 199 | +Format: |
| 200 | +
|
| 201 | +```c |
| 202 | +displayHex(Val, Pos, Width); |
| 203 | +``` |
| 204 | + |
| 205 | +This function displays the input value in hexadecimal. Pos and Width have the same meaning as in displayDec() above, but the difference is that for hexadecimal display, when Width is set to exceed the width of the actual value, the excess part will be displayed as 0, instead of the blank in decimal display. For example, if you input 0xA5, set Width to 5, then the result will be 000A5 |
| 206 | + |
| 207 | +#### displayFloat() : Display Float Point Values |
| 208 | + |
| 209 | +Format: |
| 210 | + |
| 211 | +```c |
| 212 | +displayFloat(Val, Pos, Width, Frac); |
| 213 | +``` |
| 214 | +
|
| 215 | +This function displays a float point value. Pos and Width have the same meaning as in displayDec() above, Frac is the width of the fraction part. Width is the whole display width. The function doesn't deal with the decimal point and negative sign, user must use proper command to turn on/off decimal point and negative sign. |
| 216 | +
|
| 217 | +#### digitBlink() : Digit Blink Control |
| 218 | +
|
| 219 | +Format: |
| 220 | +
|
| 221 | +```c |
| 222 | +digitBlink(Digit, OnOff); |
| 223 | +``` |
| 224 | + |
| 225 | +Control blinking by digit. This function controls the blinking property of one display digit at a time. The blinking property of the 16th - 31st digit, if it's set directly by the user through the sendCmd() function, may be lost if then changed by using this function. The Digit value range is 0-31; OnOff is the set state, 1=blinking, 0=no blinking. |
| 226 | + |
| 227 | +### Examples |
| 228 | + |
| 229 | +The following Sketch uses Serial1 as display port, displays counts from 0-999 in both decimal and hexdecimal format and a float point number starting form 1.23 increased by 0.01 each step. The display changed every second. |
| 230 | + |
| 231 | +```c |
| 232 | + |
| 233 | +``` |
0 commit comments