Special Commands
This page will discuss the Serial 7-Segment Display's special commands:
- Clear display
- Cursor control
- Decimal, colon, and apostrophe control
- Brightness control
- Individual segment control
- Baud rate configuration
- I2C address configuration
- Factory reset.
First, a quick breakdown of the commands, their control byte and any data bytes:
Special Command | Command byte | Data byte range | Data byte description |
Clear display | 0x76 | None | |
Decimal control | 0x77 | 0-63 | 1 bit per decimal |
Cursor control | 0x79 | 0-3 | 0=left=most, 3=right-most |
Brightness control | 0x7A | 0-255 | 0=dimmest, 255=brightest |
Digit 1 control | 0x7B | 0-127 | 1 bit per segment |
Digit 2 control | 0x7C | 0-127 | 1 bit per segment |
Digit 3 control | 0x7D | 0-127 | 1 bit per segment |
Digit 4 control | 0x7E | 0-127 | 1 bit per segment |
Baud rate config | 0x7F | 0-11 | See baud section |
I2C address Config | 0x80 | 1-126 | Data byte is I2C addres |
Factory reset | 0x80 | None |
The clear display command performs two functions:
- Clear the display - all LEDs, including segments and decimal points, are turned off.
- Reset the cursor to position 1, the left-most digit.
The clear display command byte is 0x76
.
There is no data byte, so any displayable data sent after the clear display command will be displayed on digit 1.
Arduino Sample Snippet (Serial Mode): To make the display read 12Ab., we can't be guaranteed that the cursor is at position 1. To ensure that it is, we can use the clear display command before sending our data.
// ... after initializing Serial at the correct baud rate... Serial.write(0x76); // Clear display command, resets cursor Serial.write(0x01); // Hex value for 1, will display '1' Serial.write('2'); // ASCII value for '2', will display '2' Serial.write(0x0A); // Hex value for 10, will display 'A' Serial.write('B'); // ASCII value for 'B', will display 'b'
Note: The clear display command byte value is equivalent to the ASCII value for the 'v' character. This value was chosen because 'v' is not all that displayable on a 7-segment display.
You can control the cursor using the cursor control command. To move the cursor, first send the cursor control byte 0x79
, then send an 8-bit data byte with value between 0 and 3. A data value of 0 will set the cursor to position 1 (left-most), a value of 3 will set the cursor to the right-most digit.
###Example: Using the Move Cursor Command
To set the cursor to the second digit (the digit immediately left of the colon), send the following 2-byte sequence: [0x79][0x01]
Sample Arduino Snippet (Serial Mode):
// ... after initializing Serial at the correct baud rate... Serial.write(0x79); // Send the Move Cursor Command Serial.write(0x01); // Send the data byte, with value 1 Serial.write(7); // Write a 7, should be displayed on 2nd digit
If the data byte is outside the allowable range (0-3), the cursor command is ignored.
Or, you can reset the cursor to position 1 by issuing the clear display command.
This command gives you control over each of the four decimal points, the colon, and the apostrophe between digits 3 and 4.
To turn on or off any of the decimal points first send the decimal control command 0x77
followed by a data byte.
Each of the six least significant bytes of the data byte represent one decimal point (or two in the case of the colon). A 1 will turn the decimal point on, a 0 will turn it off. The most significant two bits in the data byte have no effect on the display.
The following figure shows the bit representation for each decimal point (0 is the least significant bit):
Bit: | 7 (msb) | 6 | 5 | 4 | 3 | 2 | 1 | 0 (lsb) |
Segment: | X | X | Apostrophe | Colon | Digit 4 | Digit 3 | Digit 2 | Digit 1 |
Note: Because they're wired together inside the LED, the two decimal points cannot be individually controlled. Both will either be on or off.
To turn on the colon, apostrophe, and far-right decimal point we need to set bits 4, 5, and 3, respectively. Our data byte will therefore be: 0b00111000
(ie. hex 0x38
, or decimal 56
).
So a two byte sequence of 0x77``0x38
should be sent.
Sample Arduino Snippet (Serial mode)
// ... after initializing Serial at the correct baud rate... Serial.write(0x77); // Decimal control command Serial.write(0b00111000); // Turns on colon, apostrophoe, and far-right decimal
The brightness of the display can be controlled via internal PWM.
To control the brightness of the display, first send the special command character 0x7A
, followed by a data byte. The data byte can be any number between 0 and 255. 0 represents the dimmest setting, while 255 sets the display to its brightest.
After the screen receives the brightness command, the brightness value is written into the processor's volatile memory. So the display will retain the same brightness level upon power cycling.
Note: The brightness command will have no effect on the currently displayed values. The display will remain the same.
To set the display to the dimmest possible setting, we need to send 0 for the data byte. The required two-byte stream would be: 0x7A``0x00
.
Sample Arduino Snippet (Serial Mode)
// ... after initializing Serial at the correct baud rate... Serial.write(0x7A); // Brightness control command Serial.write((byte) 0); // dimmest value (must type-def 0)