#include <msp430x14x.h>
void second();
void minute();
void hour();
int h1 =0,h2 = 0,m1 = 0,m2 = 0,s1 = 0,s2 = 0;
int temp=0;
int Temp=0;
#define duan_l P6OUT &= ~BIT6
#define duan_h P6OUT |= BIT6
#define wei_l P5OUT &= ~BIT5
#define wei_h P5OUT |= BIT5
char duan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
char wei[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void main( )
{
WDTCTL = WDTPW + WDTHOLD;
TACTL = TASSEL_1 + TACLR + MC_1;
CCTL0 |= CCIE;
CCR0 = 32767;
P1DIR = 0XF0;
P3DIR = 0XFF;
P3OUT = 0X00;
P5DIR = 0XFF;
P5OUT = 0XFF;
P6DIR = 0XFF;
P6OUT = 0XFF;
P4DIR = 0XFF;
P4OUT = 0XFF;
P1DIR=0xf0;
P1OUT=0x0f;
P1IE=0x0f;
P1IES=0x0f;
P1IFG=0x00;
while(1)
{
_BIS_SR(CPUOFF + GIE);
}
}
#pragma vector=PORT1_VECTOR
__interrupt void PORT1()
{
switch(P1IFG)
{
case 0x01://控制小时数码管
{
h1++;
if(h1 >= 10)
{
h1 = 0;
h2++;
}
if(h2>=2&&h1==4)
{
h1= h2 = 0;
}
P1IFG=0x00;
break;
}
case 0x02://控制分钟
{
m1++;
if(m1 >= 10)
{
m1 = 0;
m2++;
}
if(m2>=6)
{
m2 = 0;
h1++;
}
P1IFG=0x00;
break;
}
case 0x04://控制秒
{
s1++;
if(s1 >= 10)
{
s1 = 0;
s2++;
}
if(s2 >= 6)
{
s2=0;
m1++;
}
P1IFG=0x00;
break;
}
case 0x08://控制时间暂停与启动
{
Temp++;
if(Temp==2)
{
Temp=0;
temp=0;
}
else
temp=1;
P1IFG=0x00;
break;
}
}
}
#pragma vector = TIMERA0_VECTOR
__interrupt void smlight(void)
{
for(int i=0;i<2000;i++)
{
P4OUT = duan[s1];
duan_h;
duan_l;
P4OUT =wei[0];
wei_h;
wei_l;
P4OUT = 0XFF;
wei_h;
wei_l;
P4OUT = duan[s2];
duan_h;
duan_l;
P4OUT =wei[1];
wei_h;
wei_l;
P4OUT = 0XFF;
wei_h;
wei_l;
P4OUT = 0X40;
duan_h;
duan_l;
P4OUT = wei[2];
wei_h;
wei_l;
P4OUT = 0XFF;
wei_h;
wei_l;
P4OUT = duan[m1];
duan_h;
duan_l;
P4OUT =wei[3];
wei_h;
wei_l;
P4OUT = 0XFF;
wei_h;
wei_l;
P4OUT = duan[m2];
duan_h;
duan_l;
P4OUT =wei[4];
wei_h;
wei_l;
P4OUT = 0XFF;
wei_h;
wei_l;
P4OUT = 0X40;
duan_h;
duan_l;
P4OUT = wei[5];
wei_h;
wei_l;
P4OUT = 0XFF;
wei_h;
wei_l;
P4OUT = duan[h1];
duan_h;
duan_l;
P4OUT = wei[6];
wei_h;
wei_l;
P4OUT = 0XFF;
wei_h;
wei_l;
P4OUT = duan[h2];
duan_h;
duan_l;
P4OUT =wei[7];
wei_h;
wei_l;
P4OUT = 0XFF;
wei_h;
wei_l;
}
if(temp != 1)
{
second();
minute();
hour();
}
}
void second()
{
s1++;
if(s1 == 10)
{
s1 = 0;
s2++;
}
}
void minute()
{
if(s2==6)
{
s2 = 0;
m1++;
}
if(m1 == 10)
{
m1 = 0;
m2++;
}
}
void hour()
{
if(m2==6)
{
m2 = 0;
h1++;
}
if(h1 ==10)
{
h1 = 0;
h2++;
}
if(h2 == 2&&h1==4)
h2 = 0;
}