Chinaunix首页 | 论坛 | 博客
  • 博客访问: 551660
  • 博文数量: 156
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1183
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-22 11:42
文章分类

全部博文(156)

文章存档

2015年(67)

2014年(89)

分类: C/C++

2014-11-27 19:55:07


  1. #include <msp430f249.h>
  2. #include<stdbool.h>

  3. /************************************************************************************
  4. * AUTHOR: yyj
  5. * DATE: 2014-11-21
  6. * MODIFY: 2014-11-21 9:08
  7. *************************************************************************************/

  8. /************************************************************************************
  9. * progect: 7SEG
  10. * mcu: msp430f249
  11. * component: 7seg-cc、74hc573
  12. * datesheet: PxDIR
  13. *************************************************************************************/

  14. #define uchar unsigned char

  15. unsigned long num;
  16. uchar j, k;
  17. unsigned a0, b0, c0, d0, e0, f0;

  18. /*sbit dula = P2^0;
  19. sbit wela = P2^1;
  20. sbit cs88 = P2^3;
  21. sbit LCD1602 = P2^5;
  22. sbit DS1302 = P2^7;
  23. sbit CS88 = P2^2;*/

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

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

  27. void delay(uchar i)
  28. {                        
  29.     for(j=i; j>0; j--)
  30.     {
  31.         for(k=250; k>0; k--);
  32.     }
  33. }

  34. void display(uchar a, uchar b, uchar c, uchar d, uchar e, uchar f)
  35. {
  36.     P2DIR = 0xff;
  37.     P2OUT &= ~BIT0;
  38.     //dula = 0;
  39.     P1DIR = 0xff;
  40.     P1OUT = table[a];
  41.     //P0 = table[a];
  42.     P2OUT |= BIT0;
  43.     //dula = 1;
  44.     P2OUT |= BIT0;
  45.     //dula = 0;
  46.     P2OUT &= ~BIT1;
  47.     //wela = 0;
  48.     //P2DIR = 0xff;
  49.     P1OUT = 0xfe;
  50.     //P0 = 0xfe;
  51.     P2OUT &= ~BIT1;
  52.     //wela = 0;
  53.     P2OUT |= BIT1;
  54.     //wela = 1;
  55.     delay(5);

  56.     P1OUT = table[b];
  57.     P2OUT |= BIT0;
  58.     //dula = 1;
  59.     P2OUT &= ~BIT0;
  60.     //dula = 0;
  61.     //P1DIR = 0xff;
  62.     P1OUT = 0xfd;
  63.     P2OUT |= BIT1;
  64.     //wela = 1;
  65.     P2OUT &= ~BIT1;
  66.     //wela = 0;
  67.     delay(5);

  68.     P1OUT = table[c];
  69.     //P0 = table[c];
  70.     P2OUT |= BIT0;
  71.     //dula = 1;
  72.     P2OUT &= ~BIT0;
  73.     //dula = 0;
  74.     //P1DIR = 0xff;
  75.     P1OUT = 0xfb;
  76.     //P0 = 0xfb;
  77.     P2OUT |= BIT1;
  78.     //wela = 1;
  79.     P2OUT &= ~BIT1;
  80.     //wela = 0;
  81.     delay(5);

  82.     P1OUT = table[d];
  83.     //P0 = table[d];
  84.     P2OUT |= BIT0;
  85.     //dula = 1;
  86.     P2OUT &= ~BIT0;
  87.     //dula = 0;
  88.     //P1DIR = 0xff;
  89.     P1OUT = 0xf7;
  90.     //P0 = 0xf7;
  91.     P2OUT |= BIT1;
  92.     //wela = 1;
  93.     P2OUT &= ~BIT1;
  94.     //wela = 0;
  95.     delay(5);

  96.     P1OUT = table[e];
  97.     //P0 = table[e];
  98.     P2OUT |= BIT0;
  99.     //dula = 1;
  100.     P2OUT &= ~BIT0;
  101.     //dula = 0;
  102.     //P1DIR = 0xff;
  103.     P1OUT = 0xef;
  104.     //P0 = 0xef;
  105.     P2OUT |= BIT1;
  106.     //wela = 1;
  107.     P2OUT &= ~BIT1;
  108.     //wela = 0;
  109.     delay(5);

  110.     P1OUT = table[f];
  111.     //P0 = table[f];
  112.     P2OUT |= BIT0;
  113.     //dula = 1;
  114.     P2OUT &= ~BIT0;
  115.     //dula = 0;
  116.     //P1DIR = 0xff;
  117.     P1OUT = 0xdf;
  118.     //P0 = 0xdf;
  119.     P2OUT |= BIT1;
  120.     //wela = 1;
  121.     P2OUT &= ~BIT1;
  122.     //wela = 0;
  123.     delay(5);
  124. }

  125. void init()
  126. {
  127.     WDTCTL = (0x5a << 8) | (1 << 7);
  128.     P1SEL=0X00;
  129.     P2SEL=0X00;
  130. }

  131. void main()
  132. {
  133.     init();
  134.     num = 87530;
  135.     P1DIR = 0xff;
  136.     P1OUT = 0X00;

  137.     while(1)
  138.     {
  139.         if(num < 10)
  140.         {
  141.             a0 = num; b0 = 16; c0 = 16; d0 = 16; e0 = 16; f0 = 16;
  142.         }

  143.         else
  144.         {
  145.             if(num < 100)
  146.             {
  147.                 a0 = num / 10; b0 = num % 10; c0 = 16; d0 = 16; e0 = 16; f0 = 16;     
  148.             }

  149.             else
  150.             {
  151.                 if(num < 1000)
  152.                 {
  153.                     a0 = num / 100; b0 = num % 100 / 10; c0 = num % 10; d0 = 16; e0 = 16; f0 = 16;
  154.                 }

  155.                 else
  156.                 {
  157.                     if(num < 10000)
  158.                     {
  159.                         a0 = num / 1000; b0 = num % 1000 / 100; c0 = num % 100 / 10; d0 = num % 10; e0 = 16; f0 = 16;
  160.                     }

  161.                     else
  162.                     {
  163.                         if(num < 100000)
  164.                         {
  165.                             a0 = num / 10000; b0 = num % 10000 / 1000; c0 = num % 1000 / 100; d0 = num % 100 / 10; e0 = num % 10; f0 = 16;
  166.                         }

  167.                         else
  168.                         {
  169.                             if(num < 1000000)
  170.                             {
  171.                                 a0 = num / 100000; b0 = num % 100000 / 10000; c0 = num % 10000 / 1000; d0 = num % 1000 / 100; e0 = num % 100 / 10; f0 = num % 10;
  172.                             }
  173.                         }
  174.                     }
  175.                 }
  176.                 
  177.             }
  178.         }
  179.         
  180.         display(a0, b0, c0, d0, e0, f0);
  181.     }
  182. }


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