中断+数码管

#include "MSP430F149.h"
int g_led[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void IO_init()
{
P1DIR = 0xff;
P2DIR = 0xff;
}

int get_num(int i)
{
if(i>=0 && i<10)
{
return g_led[i];
}
return 0XFF;
}
void echo_num(long num)
{
if(0<=num && num<=99999999)
{
int n;
for(n=0;n<8 && num;++n)
{
P1OUT = 0;
P2OUT = 7-n;
P1OUT = get_num( num );
num /= 10;

__delay_cycles(1000);
}
}
}

void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
IO_init();
P2DIR &= ~BIT3;
P2IE = 0;
P2IES = 0;
P2IFG = 0;
P2IE |= BIT3;
P2IES &= ~BIT3;
_BIS_SR(LPM4_bits+GIE);
while(1);
//int i;
}

#pragma vector = PORT2_VECTOR
__interrupt void ITR00()
{
while(1)
{
long i;
for(i=0;i<100000000;++i)
{
echo_num(i);
__delay_cycles(10);
}
}
}

你可能感兴趣的:(单片机)