晕死,同是一片HC595 4位led 和16f887a,在开发板上让两位led显示不同数字都可以,在产品上显示闪烁太厉害了,就是使能第一位显示数字再使能第二位显示数字,可是第一位显示第二位就灭,第二位显示第一位就灭,求大神指导,程序如下:
#include <pic.h> //调用头文件,可以去PICC软件下去查找PIC16F88X单片机的头文件
__CONFIG(XT&WDTDIS&LVPDIS&BORDIS); //定义配置字,
#define CLK RB3
#define DATA RB4
#define LOAD RB5
#define key0 RB0
#define key1 RB1
#define key2 RB2
const unsigned char LED[11]=
{
~0x3f, //0
~0x06, //1
~0x5b, //2
~0x4f, //3
~0x66, //4
~0x6d, //5
~0x7d, //6
~0x07, //7
~0x7f, //8
~0x6f, //9
~0x80, //.
};
void delay1(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
{
for(j=0;j<10;j++);
}
}
/*HC595控制LED*/
void senddata(unsigned char x,unsigned char y)//y值为LED_ENBLE=1,2,4,8分别对应第1,2,3,4位LED
{
PORTD=~y;
unsigned char i;
for(i=0;i<8;i++)
{
if((x<<i)&0x80)DATA=1;
else
DATA=0;
CLK=0;
NOP();
CLK=1;
}
LOAD=0;
NOP();
LOAD=1;
}
void main(void)
{
ANSEL=0X00; //所有IO为数字IO
ANSELH=0X00; //所有IO为数字IO
OSCCON=0X08;
TRISB=0B00000111; //RB3-5设置为输出
TRISD=0B00000000; //RD设置为输出
unsigned char a;
unsigned char b;
unsigned char c;
unsigned int d=23;
senddata(LED[d/10],1);
senddata(LED[d%10],2);
}
#include <pic.h> //调用头文件,可以去PICC软件下去查找PIC16F88X单片机的头文件
__CONFIG(XT&WDTDIS&LVPDIS&BORDIS); //定义配置字,
#define CLK RB3
#define DATA RB4
#define LOAD RB5
#define key0 RB0
#define key1 RB1
#define key2 RB2
const unsigned char LED[11]=
{
~0x3f, //0
~0x06, //1
~0x5b, //2
~0x4f, //3
~0x66, //4
~0x6d, //5
~0x7d, //6
~0x07, //7
~0x7f, //8
~0x6f, //9
~0x80, //.
};
void delay1(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
{
for(j=0;j<10;j++);
}
}
/*HC595控制LED*/
void senddata(unsigned char x,unsigned char y)//y值为LED_ENBLE=1,2,4,8分别对应第1,2,3,4位LED
{
PORTD=~y;
unsigned char i;
for(i=0;i<8;i++)
{
if((x<<i)&0x80)DATA=1;
else
DATA=0;
CLK=0;
NOP();
CLK=1;
}
LOAD=0;
NOP();
LOAD=1;
}
void main(void)
{
ANSEL=0X00; //所有IO为数字IO
ANSELH=0X00; //所有IO为数字IO
OSCCON=0X08;
TRISB=0B00000111; //RB3-5设置为输出
TRISD=0B00000000; //RD设置为输出
unsigned char a;
unsigned char b;
unsigned char c;
unsigned int d=23;
senddata(LED[d/10],1);
senddata(LED[d%10],2);
}