Skip to content

Instantly share code, notes, and snippets.

@Anubisss
Created December 25, 2013 17:46
Show Gist options
  • Save Anubisss/8125260 to your computer and use it in GitHub Desktop.
Save Anubisss/8125260 to your computer and use it in GitHub Desktop.
Multiplexing three seven-segment TIL309 red LED displays with a MSP430 microcontroller. Counts from -99 to 999. Video: http://youtu.be/sDOHmbwP8FU
#include <msp430.h>
#define DISPLAY1 BIT4
#define DISPLAY2 BIT5
#define DISPLAY3 BIT6
#define DISPLAY_ALL DISPLAY1 | DISPLAY2 | DISPLAY3
#define LATCH_MINUS 0x0B // minus (-) on the LED display
void DisplayNumber(int num)
{
int firstDigit;
int secondDigit;
int thirdDigit;
if (num < 0)
{
firstDigit = LATCH_MINUS;
secondDigit = (num / 10) * -1;
thirdDigit = (num % 10) * -1;
}
else
{
firstDigit = num / 100;
secondDigit = (num / 10) % 10;
thirdDigit = num % 10;
}
P1OUT = firstDigit | DISPLAY_ALL;
P1OUT &= ~DISPLAY1;
P1OUT = secondDigit | DISPLAY_ALL;
P1OUT &= ~DISPLAY2;
P1OUT = thirdDigit | DISPLAY_ALL;
P1OUT &= ~DISPLAY3;
}
int main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR = BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5 | BIT6; // make port 1.0-1.6 to output
int num = -99;
while (num < 1000)
{
DisplayNumber(num++);
__delay_cycles(80000);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment