Jump to content
43oh

Binary Clock


Recommended Posts

Hello,

I made a binary clock for the MSP430G2211

I'm pretty sure I saw another binary clock but I made one myself, since the other one was a bit too big.

It shows the seconds, hours, and minutes. Unfortunately, I didn't have enough pins to add a button for time setting, unless you remove the setting function. So I just set the time before I compile the program (change the variables of hour, minutes, seconds)

 

I used the watchdog timer to calibrate the clock.

 

CODE:

#include "msp430g2211.h"

unsigned int seconds = 30;
unsigned int minutes = 11;
unsigned int hours = 10;
unsigned int variable = 0;
unsigned char nmicounter = 0;

void secondsdisplay1 (unsigned int secondnumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = secondnumber & 0x01;
 P1OUT |= BIT7 + BIT6 + BIT4;
 P1OUT &= ~BIT5;

 if (variable == 1)
 {
   P1OUT |= BIT3;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT3;
 }
 secondnumber = 0;
}

void secondsdisplay2 (unsigned int secondnumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = secondnumber & 0x02;
 P1OUT |= BIT7 + BIT6 + BIT4;
 P1OUT &= ~BIT5;

 if (variable == 2)
 {
   P1OUT |= BIT2;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT2;
 }
 secondnumber = 0;
}

void secondsdisplay3 (unsigned int secondnumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = secondnumber & 0x04;
 P1OUT |= BIT7 + BIT6 + BIT5;
 P1OUT &= ~BIT4;

 if (variable == 4)
 {
   P1OUT |= BIT3;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT3;
 }
 secondnumber = 0;
}

void secondsdisplay4 (unsigned int secondnumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = secondnumber & 0x08;
 P1OUT |= BIT7 + BIT6 + BIT5;
 P1OUT &= ~BIT4;

 if (variable == 8)
 {
   P1OUT |= BIT2;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT2;
 }
 secondnumber = 0;
}

void secondsdisplay5 (unsigned int secondnumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = secondnumber & 0x10;
 P1OUT |= BIT7 + BIT6 + BIT5;
 P1OUT &= ~BIT4;

 if (variable == 16)
 {
   P1OUT |= BIT1;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT1;
 }
 secondnumber = 0;
}

void secondsdisplay6 (unsigned int secondnumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = secondnumber & 0x20;
 P1OUT |= BIT7 + BIT6 + BIT5;
 P1OUT &= ~BIT4;

 if (variable == 32)
 {
   P1OUT |= BIT0;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT0;
 }
 secondnumber = 0;
}




void minutesdisplay1 (unsigned int minutenumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = minutenumber & 0x01;
 P1OUT |= BIT7 + BIT6 + BIT4;
 P1OUT &= ~BIT5;

 if (variable == 1)
 {
   P1OUT |= BIT1;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT1;
 }
 minutenumber = 0;
}

void minutesdisplay2 (unsigned int minutenumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = minutenumber & 0x02;
 P1OUT |= BIT7 + BIT6 + BIT4;
 P1OUT &= ~BIT5;

 if (variable == 2)
 {
   P1OUT |= BIT0;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT0;
 }
 minutenumber = 0;
}

void minutesdisplay3 (unsigned int minutenumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = minutenumber & 0x04;
 P1OUT |= BIT5 + BIT6+ BIT4;
 P1OUT &= ~BIT7;

 if (variable == 4)
 {
   P1OUT |= BIT3;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT3;
 }
 minutenumber = 0;
}

void minutesdisplay4 (unsigned int minutenumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = minutenumber & 0x08;
 P1OUT |= BIT5 + BIT6+ BIT4;
 P1OUT &= ~BIT7;

 if (variable == 8)
 {
   P1OUT |= BIT2;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT2;
 }
 minutenumber = 0;
}

void minutesdisplay5 (unsigned int minutenumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = minutenumber & 0x10;
 P1OUT |= BIT5 + BIT6+ BIT4;
 P1OUT &= ~BIT7;

 if (variable == 16)
 {
   P1OUT |= BIT1;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT1;
 }
 minutenumber = 0;
}

void minutesdisplay6 (unsigned int minutenumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = minutenumber & 0x20;
 P1OUT |= BIT5 + BIT6+ BIT4;
 P1OUT &= ~BIT7;

 if (variable == 32)
 {
   P1OUT |= BIT0;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT0;
 }
 minutenumber = 0;
}

void hoursdisplay1 (unsigned int hournumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = hournumber & 0x01;
 P1OUT |= BIT7 + BIT5+ BIT4;
 P1OUT &= ~BIT6;

 if (variable == 1)
 {
   P1OUT |= BIT3;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT3;
 }
 hournumber = 0;
}

void hoursdisplay2 (unsigned int hournumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = hournumber & 0x02;
 P1OUT |= BIT7 + BIT5+ BIT4;
 P1OUT &= ~BIT6;

 if (variable == 2)
 {
   P1OUT |= BIT2;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT2;
 }
 hournumber = 0;
}

void hoursdisplay3 (unsigned int hournumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = hournumber & 0x04;
 P1OUT |= BIT7 + BIT5+ BIT4;
 P1OUT &= ~BIT6;

 if (variable == 4)
 {
   P1OUT |= BIT1;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT1;
 }
 hournumber = 0;
}

void hoursdisplay4 (unsigned int hournumber)
{
 P1OUT = BIT5+BIT6+BIT7+BIT4;
 variable = hournumber & 0x08;
 P1OUT |= BIT7 + BIT5+ BIT4;
 P1OUT &= ~BIT6;

 if (variable == 8)
 {
   P1OUT |= BIT0;
 }

 if (variable == 0)
 {
   P1OUT &= ~BIT0;
 }
 hournumber = 0;
}

void main( void )
{
 // Stop watchdog timer to prevent time out reset
 WDTCTL = WDT_ADLY_1000 + WDTNMI + WDTNMIES;
 IE1 = WDTIE + NMIIE;
 P1DIR = 0XFF;
 P1OUT = 0;

 __bis_SR_register(GIE);

 for(;
 {
   minutesdisplay1(minutes);
 minutesdisplay2(minutes);
 minutesdisplay3(minutes);
 minutesdisplay4(minutes);
 minutesdisplay5(minutes);
 minutesdisplay6(minutes);
 hoursdisplay1(hours);
 hoursdisplay2(hours);
 hoursdisplay3(hours);
 hoursdisplay4(hours);
 secondsdisplay1(seconds);
 secondsdisplay2(seconds);
 secondsdisplay3(seconds);
 secondsdisplay4(seconds);
 secondsdisplay5(seconds);
 secondsdisplay6(seconds);
 IE1 = WDTIE + NMIIE;
 nmicounter = 0;}
}

#pragma vector = WDT_VECTOR
__interrupt void wdtinterrupt1 (void)
{
 seconds++;

 if (seconds == 60)
 {
   seconds = 0;
   minutes++;
 }

 if (minutes >= 60)
 {
   minutes = 0;
   hours++;
 }

 if (hours == 13)
   hours = 1;

 __bis_SR_register_on_exit(GIE);
}

#pragma vector = NMI_VECTOR
__interrupt void nmiinterrupt1 (void)
{
 if (nmicounter == 0){
 minutes++;
 nmicounter = 1;}
 IFG1 &= ~NMIIFG;
 __bis_SR_register_on_exit(GIE);
}

 

SCHEMATIC:

G2r2W.png

 

And a PCB that I made is attached as a gerber file. It is 5cmx2.5cm Since two 50mm x 25mm PCBs can fit on a 50mmx50mm square, it's twenty PCBs for ten bucks at iTead. I don't know what I'm going to do with 20 clocks though. Does anyone want a PCB? I have no need for twenty of them, but that's the cheapest price I could find.

 

BOTTOM:

rnEWy.png

 

TOP:

rmPxT.png

 

PLACEMENT:

ZRy80.png

 

BTW that's a 1.5 kohm resistor. Don't know why it doesn't show...

debouncing is still a problem.

 

And this concludes my first project on 43oh. :P

 

EDIT: Added reset pin function

BINARYCLOCK.zip

Link to post
Share on other sites

This was a test RST pin code, but it didn't work that well. The light went on and never went back down when pressed again.

 

#include "msp430g2211.h"

char interruptcounter = 0;

void main (void)
{
 WDTCTL = WDTPW + WDTHOLD + WDTNMI + WDTNMIES;
 IE1 = NMIIE;
 P1DIR = BIT6;
 P1OUT = 0;

 __bis_SR_register(GIE);
 for(;
 {interruptcounter = 0;}
}


#pragma vector = NMI_VECTOR
__interrupt void nmistuff (void)
{
 if (interruptcounter == 0){
 P1OUT ^= BIT6;
 interruptcounter = 1;}
 __bis_SR_register_on_exit(GIE);
}

 

Never mind I had to clear the flag and reenable the interrupt

Link to post
Share on other sites

What kind of Leds are you using? I don't know if its safe to connect 4 Leds to one pin of the MSP430, the specification says s.th about 14mA per Port?

 

I am asking because i managed to blow a pin on my MSP using the exact same setup, but i was using multiple 20mA leds, so no suprise there.

 

-lastaid

Link to post
Share on other sites
What kind of Leds are you using? I don't know if its safe to connect 4 Leds to one pin of the MSP430, the specification says s.th about 14mA per Port?

 

I am asking because i managed to blow a pin on my MSP using the exact same setup, but i was using multiple 20mA leds, so no suprise there.

 

-lastaid

Oh, what?! I set it up and kept it running for a day, almost, before disconnecting it...

 

I didn't know that you could blow a pin by connecting LEDs like that. I'm using those normal 3mm red LEDs on the pins...

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...