Close

Arduino (Uno/Mega) MC14499 code

A project log for Next Bus 7-segments display

Next bus departure in real time

tjTJ 03/08/2015 at 11:330 Comments

Arduino Uno:

//MC14499
static int latchPin = 8; //enable
static int clockPin = 12; //clock
static int dataPin = 11; //data

Arduino Mega:

//MC14499
static int latchPin = A0; //enable
static int clockPin = 49; //clock
static int dataPin = 48; //data

Common:

void mc14499ShiftOut(byte val)
{
      for (int i = 0; i < 4; i++)  {
            digitalWrite(dataPin, !!(val & (1 << (3 - i))));
            digitalWrite(clockPin, HIGH);
            digitalWrite(clockPin, LOW);            
      }
}
/*
b1 => Green  7-segment "bus 1"
b2 => Green  7-segment "bus 2"
h1 => Orange 7-segment "hours 1"
h2 => Orange 7-segment "hours 2"
m1 => Orange 7-segment "minutes 1"
m2 => Orange 7-segment "minutes 2"
s1 => Orange 7-segment "seconds 1"
s2 => Orange 7-segment "seconds 2"
*/
static void affi7(byte b1, byte b2, byte h1, byte h2, byte m1, byte m2, byte s1, byte s2)
{
 digitalWrite(latchPin, LOW);
 mc14499ShiftOut(B00001111);
 mc14499ShiftOut(s2);
 mc14499ShiftOut(s1);
 mc14499ShiftOut(m2);
 mc14499ShiftOut(m1);
 mc14499ShiftOut(B00001111);
 mc14499ShiftOut(b2);
 mc14499ShiftOut(b1);
 mc14499ShiftOut(h1);
 mc14499ShiftOut(h2);
 digitalWrite(latchPin, HIGH);
}
static void affi(int bus, int hours, int minutes, int seconds)
{
 byte s2 = (byte)(seconds-(seconds/10)*10);
 byte s1 = (byte)(seconds/10);
 byte m2 = (byte)(minutes-(minutes/10)*10);
 byte m1 = (byte)(minutes/10);
 byte b2 = (byte)(bus-(bus/10)*10);
 byte b1 = (byte)(bus/10);
 byte h2 = (byte)(hours-(hours/10)*10);
 byte h1 = (byte)(hours/10);
 if (b1 == 0)
   b1 = 0xFF;
 if (hours == 0xFFFF) {
   h1 = 0xFF;
   h2 = 0xFF;
   
   if (minutes == 0xFFFF) {
     m1 = 0xFF;
     m2 = 0xFF;
   }
 }
 affi7(b1, b2, h1, h2, m1, m2, s1, s2);
}
void setup()  //arduino setup
{
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}
On the picture:
void loop()
{
  affi(2, 19, 50, 00);
}

Discussions