Help with display code.

Hi,

I am working on a small chess clock using a SCD 55104A display Basically it is a serial display that requires serial data on 1 pin, a clock on 1 pin and load pin.

EDIT: datasheet URL at Mouser:
http://www.mouser.com/ds/2/311/0.145%20%20%20%20%2010-Character%205x5%20Dot%20Matrix%20Serial%20Input-335490.pdf

I have no problems writing to the display, or sending the correct opcodes to do things like reset the display or set the brightness of the display. What I’m having trouble with is updating the display with my clock data. My code runs, and updates the time, but doesn’t display the time in the loop. If I reset the display via a reset pin, or send a reset opcode, it will show the updated time, but only once, then it will go blank again.

Here is an example of a sketch that shows the problem.

#include <avr/pgmspace.h>

//standard ascii 5x5 font
static unsigned char Font5x5[] PROGMEM = {
//static unsigned char Font5x5[] = {
  // ' ':
  0x00, 0x20, 0x40, 0x60, 0x80,
  // '!':
  0x04, 0x24, 0x44, 0x60, 0x84,
  // '"':
  0x0A, 0x2A, 0x40, 0x60, 0x80,
  // '#':
  0x0A, 0x3F, 0x4A, 0x7F, 0x8A,
  // '

So the setup works, and I see the “Hello world” text, and then I see the 0123456789. Then I see 00:00:382, very quickly and then the display goes blank. If I send a reset (0xC0) half a second later, then I see something like 00:00:892.

This is running on an Attiny 84 (8Mhz Internal Osc.) using the arduino-tiny core. I have a 20uF Electrolytic, and 3 .1uF discs near the uP and the display.

var-size returns this:
text data bss dec hex filename
3894 16 12 3922 f52

Thanks for any help. Let me know if I need to send more info.

Jimmy

EDIT: var-size output got colored. Added speed of Attiny:
  0x0F, 0x34, 0x4E, 0x65, 0x9E,
  // ‘%’:
  0x19, 0x3A, 0x44, 0x6B, 0x93,
  // ‘&’:
  0x08, 0x34, 0x4D, 0x72, 0x8D,
  // ‘’’:
 
*****Truncated the font to save space here ******

// ’ } ':
  0x0C, 0x24, 0x42, 0x64, 0x8C,
  // ‘~’:
  0x00, 0x27, 0x5C, 0x60, 0x80,
};

const int loadPin = 8;
const int dataPin = 7;
const int clkPin = 9;
const int resetPin = 10;
const int ledPin = 3;

const int button1 = 0;
const int button2 = 1;
const int button3 = 2;

int currentTimer = 280000;
int timerLastCheck = millis();
int currentTimerMinutes = 0;
int currentTimerSeconds = 0;

boolean ledOn = false;

boolean button1state = 0;
boolean button2state = 0;
boolean button3state = 0;

boolean timerDone = false;

char timerDisplay[11] = “”;

void setup(){
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  pinMode(resetPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clkPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(loadPin, OUTPUT);
  digitalWrite(resetPin, LOW);
  delay(200);
  digitalWrite(resetPin, HIGH);
  //updateTimer();
  writeByte(0xC0);
  hello();
}

void hello(){
  setBrightness(1);
  displayChar(‘H’, 0);
  displayChar(‘e’, 1);
  displayChar(‘l’, 2);
  displayChar(‘l’, 3);
  displayChar(‘o’, 4);
  displayChar(’ ', 5);
  displayChar(‘w’, 6);
  displayChar(‘o’, 7);
  displayChar(‘r’, 8);
  displayChar(‘l’, 9);
  displayChar(‘d’, 9);
  delay(100);
  displayChar(‘0’, 0);
  displayChar(‘1’, 1);
  displayChar(‘2’, 2);
  displayChar(‘3’, 3);
  displayChar(‘4’, 4);
  displayChar(‘5’, 5);
  displayChar(‘6’, 6);
  displayChar(‘7’, 7);
  displayChar(‘8’, 8);
  displayChar(‘9’, 9);
 
 
  delay(500);
  writeByte(0xC0);
  setBrightness(2);
}
 
void writeByte(const char a){
  digitalWrite(loadPin, LOW);
  for (int b = 0; b <= 7; b++) {
    digitalWrite(dataPin, bitRead(a, b));
    digitalWrite(clkPin, HIGH);
    digitalWrite(clkPin, LOW);
  }
  digitalWrite(loadPin, HIGH);
}

void writeChar(byte c){
  int d = (c - 0x20) *5;
  for (int i = 0; i < 5; i++) {
    writeByte(pgm_read_byte(&Font5x5[d + i]));
  }
}

//the opcodes for digit position on display
void displayChar(const char myChar, int myPos){
  switch(myPos){
  case 0:
    writeByte(0xB0);
    break;
  case 1:
    writeByte(0xB1);
    break;
  case 2:
    writeByte(0xB2);
    break;
  case 3:
    writeByte(0xB3);
    break;
  case 4:
    writeByte(0xB4);
    break;
  case 5:
    writeByte(0xB5);
    break;
  case 6:
    writeByte(0xB6);
    break;
  case 7:
    writeByte(0xB7);
    break;
  case 8:
    writeByte(0xB8);
    break;
  case 9:
    writeByte(0xB9);
    break;
  }
  writeChar(myChar);
  delay(10);
}

void setBrightness(int brightLevel){
  switch(brightLevel){
  case 1:
    writeByte(0xF6);
    break;
  case 2:
    writeByte(0xF5);
    break;
  case 3:
    writeByte(0xF4);
    break;
  case 4:
    writeByte(0xF3);
    break;
  case 5:
    writeByte(0xF2);
    break;
  case 6:
    writeByte(0xF1);
    break;
  case 7:
    writeByte(0xF0);
    break;
  }
}

void loop(){
  button2state = digitalRead(button2);
  if (button2state == LOW) {
      writeByte(0xC0);
    }
  print_time(millis());
}

// argument is time in milliseconds
void print_time(unsigned long t_milli)
{
  char buffer[11];
  int days, hours, mins, secs;
  int fractime;
  unsigned long inttime;

inttime  = t_milli / 1000;
  fractime = t_milli % 1000;
  // inttime is the total number of number of seconds
  // fractimeis the number of thousandths of a second

// number of days is total number of seconds divided by 24 divided by 3600
  days    = inttime / (243600);
  inttime  = inttime % (24
3600);

// Now, inttime is the remainder after subtracting the number of seconds
  // in the number of days
  hours    = inttime / 3600;
  inttime  = inttime % 3600;

// Now, inttime is the remainder after subtracting the number of seconds
  // in the number of days and hours
  mins    = inttime / 60;
  inttime  = inttime % 60;

// Now inttime is the number of seconds left after subtracting the number
  // in the number of days, hours and minutes. In other words, it is the
  // number of seconds.
  secs = inttime;

sprintf(buffer, “%02d:%02d.%03d”, mins, secs, fractime);
  for(int i = 0; i < 10; i++) {
    displayChar(buffer[i], i );
  }
}


So the setup works, and I see the "Hello world" text, and then I see the 0123456789. Then I see 00:00:382, very quickly and then the display goes blank. If I send a reset (0xC0) half a second later, then I see something like 00:00:892. 

This is running on an Attiny 84 (8Mhz Internal Osc.) using the arduino-tiny core. I have a 20uF Electrolytic, and 3 .1uF discs near the uP and the display. 

var-size returns this: 
text data bss dec hex filename
3894 16 12 3922 f52 

Thanks for any help. Let me know if I need to send more info. 

Jimmy

EDIT: var-size output got colored. Added speed of Attiny

The link to the device in your post does not work.

Thanks Bob! I edited the original with the url.

I am afraid that I cannot help with your problem but I do have some observations on your program.

For instance, instead of

 switch(myPos){
  case 0:
    writeByte(0xB0);
    break;
  case 1:
    writeByte(0xB1);
    break;
  case 2:
    writeByte(0xB2);
    break;

etc

why not just

writeByte(0xB0 + myPos);

and similarly with the brightness.

writeByte(0xF7 - brightness);

Thanks for the tips. I will try your suggestions to tighten up the code.

I’ve attached a schematic in case anyone sees something wrong with the way I’ve hooked it up.

const int button1 = 0;
const int button2 = 1;
const int button3 = 2;

Perhaps you should get your “buttons” (properly known as switches) off the hardware serial pins, so you could debug your code.

Thanks Paul. Does the Attiny 84 have 'hardware serial pins?'

Right now, I'm trying to use the LED as a way to debug.

thanks, Jimmy