-
Notifications
You must be signed in to change notification settings - Fork 73
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.
When displayable data is received, the character is displayed at the current cursor position, and then the cursor progresses one spot forward. Upon displaying a character on the fourth digit (right-most), the cursor will progress to the first digit (left-most).
In the example above (printing 12Ab), we assumed the cursor was positioned at digit 1.
Only displayable data will advance the cursor. Command bytes, and command byte data are non-displayable bytes, they will not advance the cursor.
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.