用两片74hc595,一个位选,一个段选驱动两个双位数码管,实现30s倒计时,位选、段选均可实现,但段选数码管字符一直闪烁,看不清字符,求帮忙,谢谢啦
#include<msp430x14x.h>
unsigned char seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char wei[9]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff};
void delay(int v)//延时
{
while(v!=0)v--;
}
void Qr0_5951(unsigned char num1)//串行数据输入段选八位
{
unsigned char t;
for(t=0;t<8;t++)
{
if((num1&0x80)==0x80)
{
P2OUT|=BIT4;
}
else
{
P2OUT&=~BIT4;
}
P2OUT|=BIT6;//P2.6移位寄存器上升沿
P2OUT&=~BIT6;
num1=num1<<1;
}
}
void OUT_5951()//并行输出
{
P2OUT&=~BIT5;
P2OUT|=BIT5;//存储器上升沿
P2OUT&=~BIT5;
}
void Qr1_5952(unsigned char num2)//串行数据输入位选八位
{
unsigned char j;
for(j=0;j<8;j++)
{
if((num2&0x80)==0x80)
{
P2OUT|=BIT1;//P2.1口为串行数据
}
else
{
P2OUT&=~BIT1;
}
P2OUT|=BIT2;//P2.2口为移位寄存器
P2OUT&=~BIT2;
num2=num2<<1;
}
}
void OUT_5952()//并行输出位选信号
{
P2OUT&=~BIT0;//P2.0为存储器
P2OUT|=BIT0;
P2OUT&=~BIT0;
}
void main()
{
WDTCTL=WDTPW+WDTHOLD;//关闭看门狗
unsigned char i,h,k;
P2DIR|=(BIT0|BIT1|BIT2|BIT4|BIT5|BIT6);
P2OUT=0x00;
while(1)
{
for(k=30;k!=0;k--)
{
for(i=0;i<2;i++)
{
Qr0_5951(seg[k/10]);//十位段选
OUT_5951();
Qr1_5952(wei[i]);//十位位选
OUT_5952();
delay(300);
}
for(h=2;h<4;h++)
{
Qr0_5951(seg[k%10]);//个位段选
OUT_5951();
Qr1_5952(wei[h]);//个位位选
OUT_5952();
delay(300);
}
}
}
}
此帖出自
小平头技术问答
一周热门 更多>