Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define HT1632_CMD_SYSDIS 0x00 // CMD= 0000-0000-x Turn off oscil
- #define HT1632_CMD_SYSON 0x01 // CMD= 0000-0001-x Enable system oscil
- #define HT1632_CMD_LEDOFF 0x02 // CMD= 0000-0010-x LED duty cycle gen off
- #define HT1632_CMD_LEDON 0x03 // CMD= 0000-0011-x LEDs ON
- #define HT1632_CMD_BLOFF 0x08 // CMD= 0000-1000-x Blink OFF
- #define HT1632_CMD_BLON 0x09 // CMD= 0000-1001-x Blink On
- #define HT1632_CMD_SLVMD 0x10 // CMD= 0001-00xx-x Slave Mode
- #define HT1632_CMD_MSTMD 0x14 // CMD= 0001-01xx-x Master Mode
- #define HT1632_CMD_RCCLK 0x18 // CMD= 0001-10xx-x Use on-chip clock
- #define HT1632_CMD_EXTCLK 0x1C // CMD= 0001-11xx-x Use external clock
- #define HT1632_CMD_COMS00 0x20 // CMD= 0010-ABxx-x commons options
- #define HT1632_CMD_COMS01 0x24 // CMD= 0010-ABxx-x commons options
- #define HT1632_CMD_COMS10 0x28 // CMD= 0010-ABxx-x commons options
- #define HT1632_CMD_COMS11 0x2C // P-MOS OUTPUT AND 16COMMON OPTION
- #define HT1632_CMD_PWM 0xA0 // CMD= 101x-PPPP-x PWM duty cycle
- #define HT1632_ID_CMD 4 /* ID = 100 - Commands */
- #define HT1632_ID_RD 6 /* ID = 110 - Read RAM */
- #define HT1632_ID_WR 5 /* ID = 101 - Write RAM */
- #define DATA_PIN 2
- #define WR_PIN 3
- #define CS_PIN 4
- void setup() {
- pinMode(DATA_PIN, OUTPUT);
- pinMode(WR_PIN, OUTPUT);
- pinMode(CS_PIN, OUTPUT);
- digitalWrite(DATA_PIN, HIGH);
- digitalWrite(WR_PIN, HIGH);
- digitalWrite(CS_PIN, HIGH);
- digitalWrite(CS_PIN, LOW);
- /* init display once after startup */
- ht1632_write_data_MSB(3, HT1632_ID_CMD, false); // IDs are 3 bits
- ht1632_write_data_MSB(8, HT1632_CMD_SYSDIS, true); // 8 bits
- ht1632_write_data_MSB(8, HT1632_CMD_SYSON, true); // 8 bits
- ht1632_write_data_MSB(8, HT1632_CMD_COMS11, true); // 8 bits
- ht1632_write_data_MSB(8, HT1632_CMD_LEDON, true); // 8 bits
- ht1632_write_data_MSB(8, HT1632_CMD_BLOFF, true); // 8 bits
- ht1632_write_data_MSB(8, HT1632_CMD_PWM+15, true); // 8 bits
- digitalWrite(CS_PIN, HIGH);
- }
- void loop() {
- // #####################################################
- digitalWrite(CS_PIN, LOW);
- ht1632_write_data_MSB(3, HT1632_ID_WR, false);
- ht1632_write_data_MSB(7, 0, false);
- uint8_t i;
- for(i = 0; i<48; ++i)
- {
- ht1632_write_data(8,0xFF); // I was sending "1" here, thats why I was getting only two rows to light up
- }
- digitalWrite(CS_PIN, HIGH);
- // #####################################################
- delay(500);
- // #####################################################
- digitalWrite(CS_PIN, LOW);
- ht1632_write_data_MSB(3, HT1632_ID_WR, false);
- ht1632_write_data_MSB(7, 0, false);
- for(i = 0; i<48; ++i)
- {
- ht1632_write_data(8,0);
- }
- digitalWrite(CS_PIN, HIGH);
- // #####################################################
- delay(500);
- }
- void ht1632_write_data_MSB(uint8_t cnt, uint8_t data, uint8_t extra)
- {
- int8_t i;
- for(i = cnt - 1; i >= 0; i--)
- {
- digitalWrite(WR_PIN, LOW);
- if ((data >> i) & 1)
- {
- digitalWrite(DATA_PIN, HIGH);
- }
- else
- {
- digitalWrite(DATA_PIN, LOW);
- }
- digitalWrite(WR_PIN, HIGH);
- }
- // Send an extra bit
- if (extra)
- {
- digitalWrite(WR_PIN, LOW);
- digitalWrite(DATA_PIN, HIGH);
- digitalWrite(WR_PIN, HIGH);
- }
- }
- void ht1632_write_data(uint8_t cnt, uint8_t data)
- {
- uint8_t i;
- for (i = 0; i < cnt; i++)
- {
- digitalWrite(WR_PIN, LOW);
- if ((data >> i) & 1) {
- digitalWrite(DATA_PIN, HIGH);
- }
- else {
- digitalWrite(DATA_PIN, LOW);
- }
- digitalWrite(WR_PIN, HIGH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement