|
各位大神,我想用MSP430F5529驱动四位的数码管,但是在进位的代码上有点卡壳,个位正常,打开其他位的就会出现和个位同步计时的效果。
/*设计项目:
设计时间:
设计人员:
软件描述:
硬件描述:
* a:P6.1
* b:P6.0
* c:P3.5
* d:P3.3
* e:P3.2
* f:P6.3
* g:P6.4
* h:P3.6
* 第一个数码管 P1.2
* 第二个数码管 P1.3
* 第三个数码管 P1.4
* 第四个数码管 P1.5
* 项目说明:
*/
#include
#include"intrinsics.h"
/*
* main.c
*//***********函数使用前声明************/
void GPIO_init();
void display();
void zero();
void one();
void two();
void three();
void four();
void five();
void six();
void seven();
void eight();
void nine();
unsigned int ge,shi,bai,qian;
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
GPIO_init();
display();
return 0;
}
void GPIO_init()
{
P1DIR = BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7;
P1OUT = 0X00;
P3DIR = BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7;
P3OUT = 0X00;
P6DIR = BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7;
P6OUT = 0X00;
P1OUT |= (BIT2+BIT3+BIT4+BIT5); //关闭位选??
}
void display()
{
unsigned int ge,shi,bai,qian;
{
for(qian=0;qian<10;qian++)
{
for(bai=0;bai<10;bai++)
{
for(shi=0;shi<10;shi++)
{
for(ge=0;ge<1;ge++)
{
P1OUT &= ~BIT5; //打开个位位选信号
zero();
_delay_cycles(500000);
one();
_delay_cycles(500000);
two();
_delay_cycles(500000);
three();
_delay_cycles(500000);
four();
_delay_cycles(500000);
five();
_delay_cycles(500000);
six();
_delay_cycles(500000);
seven();
_delay_cycles(500000);
eight();
_delay_cycles(500000);
nine();
_delay_cycles(500000);
}
//P1OUT |= BIT4+BIT3+BIT2;//关闭其余位位选信号
}
}
}
}
}
void zero()
{
P3OUT = BIT2+BIT3+BIT5; //a,b,c,d,e,f
P6OUT = BIT0+BIT1+BIT3;
}
void one()
{
P6OUT = BIT0;
P3OUT = BIT5;
}
void two()
{
P6OUT = BIT0+BIT1+BIT4;
P3OUT = BIT2+BIT3;
}
void three()
{
P6OUT = BIT0+BIT1+BIT4;
P3OUT = BIT5+BIT3;
}
void four()
{
P6OUT = BIT0+BIT3+BIT4;
P3OUT = BIT5;
}
void five()
{
P6OUT = BIT3+BIT1+BIT4;
P3OUT = BIT5+BIT3;
}
void six()
{
P6OUT = BIT3+BIT4;
P3OUT = BIT2+BIT5+BIT3;
}
void seven()
{
P6OUT = BIT0+BIT1;
P3OUT = BIT5;
}
void eight()
{
P6OUT = BIT0+BIT1+BIT3+BIT4;
P3OUT = BIT2+BIT3+BIT5;
}
void nine()
{
P6OUT = BIT0+BIT1+BIT3+BIT4;
P3OUT = BIT5;
}
|
|