This is just for anyone who might still struggle with the 32x8 display (HT1632C chip!).
Here is the code (based on WestfW code) that simply lights up all the LEDs and then turns them off again.
(that said I have on several occasions seem the Arduino behave oddly when playing around with 24x16 and 32x8 code and NMOS/PMOS settings, so I don't know if I have come across a bug in the SW loader or something else). The ht1632.h file is just the basic command codes as per the datasheet.
/*
* demo8x32 - Arduino demo program for Holtek HT1632C LED driver chip,
* based on code from Bill Westfield.
*/
#include "ht1632.h"
/*
* Set these constants to the values of the pins connected to the SureElectronics Module
*/
static const byte ht1632_data = 9; // Data pin (pin 7)
static const byte ht1632_wrclk = 10; // Write clock pin (pin 5)
static const byte ht1632_cs = 11; // Chip Select (1, 2, 3, or 4)
// The should also be a common GND.
// The module with all LEDs like draws about 200mA,
// which makes it PROBABLY powerable via Arduino +5V
/*
* ht1632_writebits
* Write bits (up to 8) to h1632 on pins ht1632_data, ht1632_wrclk
* Chip is assumed to already be chip-selected
* Bits are shifted out from MSB to LSB, with the first bit sent
* being (bits & firstbit), shifted till firsbit is zero.
*/
void ht1632_chipselect(byte chipno)
{
DEBUGPRINT("\nHT1632(%d) ", chipno);
digitalWrite(chipno, 0);
}
void ht1632_chipfree(byte chipno)
{
DEBUGPRINT(" [done %d]", chipno);
digitalWrite(chipno, 1);
}
void ht1632_writebits (byte bits, byte firstbit)
{
DEBUGPRINT(" ");
while (firstbit) {
DEBUGPRINT((bits&firstbit ? "1" : "0"));
digitalWrite(ht1632_wrclk, LOW);
if (bits & firstbit) {
digitalWrite(ht1632_data, HIGH);
}
else {
digitalWrite(ht1632_data, LOW);
}
digitalWrite(ht1632_wrclk, HIGH);
firstbit >>= 1;
}
}
static void ht1632_sendcmd (byte command)
{
ht1632_chipselect(ht1632_cs); // Select chip
ht1632_writebits(HT1632_ID_CMD, 1<<2); // send 3 bits of id: COMMMAND
ht1632_writebits(command, 1<<7); // send the actual command
ht1632_writebits(0, 1); /* one extra dont-care bit in commands. */
ht1632_chipfree(ht1632_cs); //done
}
static void ht1632_senddata (byte address, byte data)
{
ht1632_chipselect(ht1632_cs); // Select chip
ht1632_writebits(HT1632_ID_WR, 1<<2); // send ID: WRITE to RAM
ht1632_writebits(address, 1<<6); // Send address
ht1632_writebits(data, 1<<3); // send 4 bits of data
ht1632_chipfree(ht1632_cs); // done
}
void setup ()
{
pinMode(ht1632_cs, OUTPUT);
digitalWrite(ht1632_cs, HIGH); /* unselect (active low) */
pinMode(ht1632_wrclk, OUTPUT);
pinMode(ht1632_data, OUTPUT);
ht1632_sendcmd(HT1632_CMD_SYSDIS); // Disable system
ht1632_sendcmd(HT1632_CMD_COMS00); // 16*32, PMOS drivers
//ht1632_sendcmd(HT1632_CMD_MSTMD); /* Master Mode */
ht1632_sendcmd(HT1632_CMD_SYSON); /* System on */
ht1632_sendcmd(HT1632_CMD_LEDON); /* LEDs on */
for (byte i=0; i<64; i++)
ht1632_senddata(i, 0); // clear the display!
delay(1000);
Serial.begin(9600); // DS1307 clock chip setup
Serial.println("We wait a bit...");
delay(5000);
Serial.println("Now we begin!");
}
void loop ()
{
byte bits;
byte addr;
for (addr=0; addr < 64; addr++) { // Shift in ON bits
for (bits=8; ; bits=(bits>>1)+8) {
//for (bits=1; bits<255; bits=(bits<<1)+1) {
ht1632_senddata(addr, bits);
Serial.print("addr: ");
Serial.print(addr, HEX);
Serial.print(" bits: ");
Serial.println(bits, DEC);
delay(10);
if (bits == 15) break;
}
}
delay(1000);
for (addr=0; addr < 64; addr++) { // Now shift in OFF bits
for (bits=15; ; bits=(bits>>1)) {
ht1632_senddata(addr, bits);
delay(10);
if (bits == 0) break;
}
}
delay(300);
}
demo8x32_simple.pde (3.55 KB)
ht1632.h (1.44 KB)
