Chinaunix首页 | 论坛 | 博客
  • 博客访问: 171544
  • 博文数量: 46
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 224
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-21 09:42
个人简介

菜鸟一枚,请多多关照

文章分类

全部博文(46)

文章存档

2016年(3)

2015年(24)

2014年(19)

我的朋友

分类: C/C++

2014-12-09 19:01:39

原文地址:7SEG-msp430f249 作者:yyj1028

#include
#include


/************************************************************************************
*  AUTHOR:  yyj
*  DATE:    2014-11-21
*  MODIFY:  2014-11-21 9:08
*************************************************************************************/


/************************************************************************************
*  progect:       7SEG
*  mcu:           msp430f249
*  component:    7seg-cc、74hc573
*  datesheet:     PxDIR
*************************************************************************************/

#define uchar unsigned char

unsigned long num;
uchar j, k;
unsigned a0, b0, c0, d0, e0, f0;

void delay(uchar i);
void display(uchar a, uchar b, uchar c, uchar d, uchar e, uchar f);

uchar table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x00};

void delay(uchar i)
{
    for(j=i; j>0; j--)
    {
        for(k=250; k>0; k--);
    }
}

void display(uchar a, uchar b, uchar c, uchar d, uchar e, uchar f)
{
    P2DIR = 0xff;
    P2OUT &= ~BIT0;
    //dula = 0;
    P1DIR = 0xff;
    P1OUT = table[a];
    //P0 = table[a];
    P2OUT |= BIT0;
    //dula = 1;
    P2OUT |= BIT0;    
    //dula = 0;
    P2OUT &= ~BIT1;
    //wela = 0;
    //P2DIR = 0xff;
    P1OUT = 0xfe;
    //P0 = 0xfe;
    P2OUT &= ~BIT1;
    //wela = 0;
    P2OUT |= BIT1;
    //wela = 1;
    delay(5);

    P1OUT = table[b];
    P2OUT |= BIT0;
    //dula = 1;
    P2OUT &= ~BIT0;
    //dula = 0;
   // P1DIR = 0xff;
    P1OUT = 0xfd;
    P2OUT |= BIT1;
    //wela = 1;
    P2OUT &= ~BIT1;
    //wela = 0;
    delay(5);

    P1OUT = table[c];
    //P0 = table[c];
    P2OUT |= BIT0;
    //dula = 1;
    P2OUT &= ~BIT0;
    //dula = 0;
    //P1DIR = 0xff;
    P1OUT = 0xfb;
    //P0 = 0xfb;
    P2OUT |= BIT1;
    //wela = 1;
    P2OUT &= ~BIT1;
    //wela = 0;
    delay(5);

    P1OUT = table[d];
    //P0 = table[d];
    P2OUT |= BIT0;
    //dula = 1;
    P2OUT &= ~BIT0;
    //dula = 0;
    //P1DIR = 0xff;
    P1OUT = 0xf7;
    //P0 = 0xf7;
    P2OUT |= BIT1;
    //wela = 1;
    P2OUT &= ~BIT1;
    //wela = 0;
    delay(5);

    P1OUT = table[e];
    //P0 = table[e];
    P2OUT |= BIT0;
    //dula = 1;
    P2OUT &= ~BIT0;
    //dula = 0;
    //P1DIR = 0xff;
    P1OUT = 0xef;
    //P0 = 0xef;
    P2OUT |= BIT1;
    //wela = 1;
    P2OUT &= ~BIT1;
    //wela = 0;
    delay(5);

    P1OUT = table[f];
    //P0 = table[f];
    P2OUT |= BIT0;
    //dula = 1;
    P2OUT &= ~BIT0;
    //dula = 0;
    //P1DIR = 0xff;
    P1OUT = 0xdf;
    //P0 = 0xdf;
    P2OUT |= BIT1;
    //wela = 1;
    P2OUT &= ~BIT1;
    //wela = 0;
    delay(5);
}

void init()
{
    WDTCTL = (0x5a << 8) | (1 << 7);
    P1SEL=0X00;
    P2SEL=0X00;
}

void main()
{
    init();
    num = 87530;
    P1DIR = 0xff;
    P1OUT = 0X00;

    while(1)
    {
        if(num < 10)
        {
            a0 = num; b0 = 16; c0 = 16; d0 = 16; e0 = 16; f0 = 16;
        }

        else
        {
            if(num < 100)
            {
                a0 = num / 10; b0 = num % 10; c0 = 16; d0 = 16; e0 = 16; f0 = 16;
             }

            else 
            {
                if(num < 1000)
                {
                    a0 = num / 100; b0 = num % 100 / 10; c0 = num % 10; d0 = 16; e0 = 16; f0 = 16;
                }

                else 
                {
                    if(num < 10000)
                    {
                        a0 = num / 1000; b0 = num % 1000 / 100; c0 = num % 100 / 10; d0 = num % 10; e0 = 16; f0 = 16;
                    }

                else
                {
                    if(num < 100000)
                    {
                        a0 = num / 10000; b0 = num % 10000 / 1000; c0 = num % 1000 / 100; d0 = num % 100 / 10; e0 = num % 10; f0 = 16;
                     }

                    else
                    {
                        if(num < 1000000)
                        {
                             a0 = num / 100000; b0 = num % 100000 / 10000; c0 = num % 10000 / 1000; d0 = num % 1000 / 100; e0 = num % 100 / 10; f0 = num % 10;
                        }
                 }
            }
        }
    }
}
        
    display(a0, b0, c0, d0, e0, f0);
}
}

阅读(1719) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~