msp430g2553 数码管实例操作

in 单片机 with 0 comment

利用LED动态显示实现:

控制MSP430G2553各I/O端口来实现控制四位共阳数码管实现“YOU”的向左流动显示。
注意:实际显示为“YOU■”

#include <msp430g2553.h>
unsigned char data[4]={0x91,0xc0,0xc1,0xFF};
unsigned char i=0,step=0;
void delay();

void main (void)
{
    WDTCTL  = WDT_ADLY_1000;
    IE1 |=WDTIE;
    P1DIR=0XFF;
    P2DIR=0XFF;
    P1OUT=0XFF;
    P2OUT=0XFF;
    _EINT();
    while(1)
    {
        switch(step)
        {
        case 0:
            P2OUT=~(1<<i);
            P1OUT=data[(i+0)%4];
            delay();
            i++;
            if(i==4) i=0;
            break;

        case 1:
                    P2OUT=~(1<<i);
                    P1OUT=data[(i+1)%4];
                    delay();
                    i++;
                    if(i==4) i=0;
                    break;

        case 2:
                    P2OUT=~(1<<i);
                    P1OUT=data[(i+2)%4];
                    delay();
                    i++;
                    if(i==4) i=0;
                    break;

        case 3:
                    P2OUT=~(1<<i);
                    P1OUT=data[(i+3)%4];
                    delay();
                    i++;
                    if(i==4) i=0;
                    break;
        }

}
    }
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
    step++;
    if (step==4) step=0;
}

void delay(void)
{
    unsigned int k ;
    for (k=1000;k>0;k--)
        _NOP();
}

请输入图片描述

Responses