potatochipsspz 2024-03-07 21:49 采纳率: 100%
浏览 86
已结题

Proteus仿真中数码管和LED不亮

Proteus仿真中数码管和LED不亮,求帮改代码

img

代码如下:

#include <msp430f249.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long

uchar NUM[16] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; // 共阴
volatile int time = 0;

void init_clk()
{
    unsigned char i;
    WDTCTL = WDTPW + WDTHOLD;
    BCSCTL1 &= ~XT2OFF;
    BCSCTL2 |= SELM_2 + DIVM_0 + SELS + DIVS_0;
    do
    {
        IFG1 &= ~OFIFG;
        for (i = 0; i < 0xff; i++) _NOP();
    } 
    while ((IFG1 & OFIFG) != 0);
    IFG1 &= ~OFIFG;
}

void Close_IO()
{
    P1DIR = 0xFF;
    P1OUT = 0xFF;
    P2DIR = 0xFF;
    P2OUT = 0xFF;
    P3DIR = 0xFF;
    P3OUT = 0xFF;
    P4DIR = 0xFF;
    P4OUT = 0xFF;
    P5DIR = 0xFF;
    P5OUT = 0xFF;
    P6DIR = 0xFF;
    P6OUT = 0xFF;
}

void displayNumber(int num)
{
    P3OUT = NUM[num % 10];
    P6OUT = NUM[num / 10];
}

void main()
{
    int i;
    init_clk();
    Close_IO();

    TACTL = TASSEL1 + ID0 + ID1 + TACLR+TAIE;
    P3DIR |= 0xff;
    P3OUT |= 0xff;
    P6DIR |= 0xff;
    P6OUT |= 0Xff;
    P2DIR = 0xFF;
    P2SEL = 0;
    P2OUT = 0x00;
    P4DIR = 0xFF;
    P4SEL = 0;
    P4OUT = 0x00;
    TACTL |= MC0;
    TACCR0 = 8000;
    _EINT();
while(1)
{
if (time ==1)
{
    P3OUT^= BIT1;
    P6OUT^=BIT1;
    P3OUT^=BIT5;
    P6OUT^=BIT5;
    P4OUT=NUM[6];P2OUT=NUM[0];
    time ++;
    i=9;
}
else if(time%100==0&&time<1000&&time>0)
{P4OUT=NUM[5];P2OUT=NUM[i];--i;time++;}
else if(time==1000)
{P4OUT=NUM[5];P2OUT=NUM[0];time ++;i=9;}
else if(time%100==0&&time<2000&&time >1000)
{P4OUT=NUM[4];P2OUT=NUM[i];--i;time++;}
else if(time ==2000)
{P4OUT=NUM[4];P2OUT=NUM[0];time ++;i=9;}
else if(time%100 ==0&&time <3000&&time>2000)
{P4OUT=NUM[3];P2OUT=NUM[i];--i; time++;}
else if(time ==3000)
{P4OUT=NUM[3];P2OUT=NUM[0];time ++;i=9;}
else if(time % 100==0&&time <4000&&time>3000)
{P4OUT=NUM[2];P2OUT=NUM[i];--i;time++;}
else if(time ==4000)
{P4OUT=NUM[2];P2OUT=NUM[0];time ++;i=9;}
else if(time%100 ==0&&time<5000&&time>4000)
{P4OUT=NUM[1];P2OUT=NUM[i];--i;time++;}
else if(time ==5000)
{P4OUT=NUM[1];P2OUT=NUM[0];time ++ ;i=9;}
else if(time %100 ==0&&time <6000&&time>5000)
{P4OUT=NUM[0];P2OUT=NUM[i]; --i; time ++;}
else if (time ==6000)
{P3OUT^=BIT5 +BIT6;
P4OUT=0x00;P2OUT=0x00;
time ++;
}
else if(time == 6100)
{P3OUT^=BIT6;P6OUT^=BIT5;
time++;
}
else if(time == 6200)
{
P3OUT^=BIT6;P6OUT^=BIT5;
time ++ ;
}
else if (time == 6300)
{ P3OUT^=BIT6 +BIT7; P6OUT^=BIT5;P6OUT^=BIT1;P6OUT^= BIT2;P6OUT^=BIT6;
P3OUT^= BIT1 +BIT2;
P4OUT=NUM[6];P2OUT=NUM[0];
time++;
i=9;
}
else if(time%100 ==0&&time <7300&&time >6300)
{P4OUT=NUM[5];P2OUT=NUM[i];--i; time ++;} //数码管显示51 ~59
else if(time ==7300)
{P4OUT=NUM[5];P2OUT=NUM[0];time ++;i =9;}
else if(time% 100 ==0&&time <8300&&time>7300)
{P4OUT=NUM[4];P2OUT=NUM[i];--i;time ++;}
else if(time ==8300)
{P4OUT=NUM[4];P2OUT=NUM[0];time ++ ;i=9;}
else if(time %100 ==0&&time<9300&&time >8300)
{P4OUT=NUM[3];P2OUT=NUM[i];--i;time++;}
else if(time ==9300)
{P4OUT=NUM[3];P2OUT=NUM[0];time ++ ;i=9;}
else if(time%100 ==0&&time <10300&&time >9300)
{P4OUT=NUM[2];P2OUT =NUM[i];--i;time++;}
else if(time ==10300)
{P4OUT=NUM[2];P2OUT=NUM[0];time ++;i=9;}
else if(time%100 ==0&&time <11300&&time >10300)
{P4OUT=NUM[1];P2OUT =NUM[i];--i; time++;}
else if(time == 11300)
{P4OUT =NUM[1];P2OUT=NUM[0];time ++;i=9;}
else if(time%100==0&&time<12300&&time >11300)
{P4OUT=NUM[0];P2OUT=NUM[i];--i;time++;}
else if (time ==12300) //12300
{P3OUT^= BIT2 + BIT3; //东西方向绿灯灭,黄灯亮
P4OUT=0x00;P2OUT=0x00;
time ++;
}
else if(time ==12400)
{ P3OUT^=BIT3;P6OUT^= BIT2;
time ++;
}
else if(time == 12500)
{ P3OUT^=BIT3;P6OUT^= BIT2;
time ++;
}
else if(time ==12600)
{P3OUT^=BIT3;P6OUT^=BIT2;P6OUT^=BIT6;
P3OUT^= BIT7;
time ++;
}
else if (time ==12610)
time=0;
}
}

#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
{
    TAIV = 0;

    switch (TAIV)
    {
    case 2:
        break;
    case 4:
        break;
    case 10:
        break;
    }
}

  • 写回答

19条回答 默认 最新

  • zhuoxu6 2024-03-13 00:01
    关注

    中断处理代码有问题,并且检查一下Proteus版本,你改成这样试一试:

    #pragma vector=TIMERA1_VECTOR
    __interrupt void Timer_A(void)
    {
        //TACTL &= ~TAIFG; // Clear the interrupt flag
    
        switch (TAIV)
        {
        case 2:
            break;
        case 4:
            break;
        case 10:
            time++;
            break;
        }
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(18条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月13日
  • 已采纳回答 3月13日
  • 创建了问题 3月7日