#include <msp430.h>
#define uchar unsigned char
#define uint unsigned int
uchar duan[]={0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83, 0xc6,0xa1,0x86,0x8e};
uchar num=0,ge,shi;
void delay(uint x)
{
uint y,z;
for(y=x;y>0;y--)
for(z=12000;z>0;z--);
}
void main(void)
{
WDTCTL = WDTHOLD + WDTPW ;
P6DIR |= 0xff;
P2DIR |= BIT4+BIT5;
P2DS |= BIT4;
TA0CCTL0 = CCIE; /* Capture/compare interrupt enable */
TA0CCR0 = 32768;
TA0CTL=TASSEL_1+MC_1;
_BIS_SR(GIE);
while(1)
{
shi=num/10;
P6OUT = duan[shi];
P2OUT &=~ BIT4;
P2OUT |= BIT5;
//delay(200);
ge=num%10;
P6OUT = duan[ge];
P2OUT &=~ BIT5;
P2OUT |= BIT4;
//delay(200);
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
num++;
if(num==99)
{
num=0;
}
} |