-
#include <msp430f249.h>
-
#include<stdbool.h>
-
-
/************************************************************************************
-
* 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;
-
-
/*sbit dula = P2^0;
-
sbit wela = P2^1;
-
sbit cs88 = P2^3;
-
sbit LCD1602 = P2^5;
-
sbit DS1302 = P2^7;
-
sbit CS88 = P2^2;*/
-
-
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);
-
}
-
}
阅读(1488) | 评论(0) | 转发(0) |