本帖最后由 相信哥咯 于 2011-3-22 22:00 编辑
#include <pic.h>
#define SH RB0
#define DS RB1
#define ST RB2
char led_7[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x39,0x5E,0x79,0x71};
char position[4]={0x7f,0xbf,0xdf,0xef};//
char dis_buff[4]={1,2,3,4};//want to display
//delay time
void delay(void)
{
unsigned char x,y;
for(x=0;x<40;x++)
{
for(y=0;y<5;y++);
}
}
//595 send
void send595(unsigned byte)
{
char i,j;
for(i=0;i<8;i++)
{
SH=0;
j=byte&1<<i;
if(j==0)DS=0;
else DS=1;
SH=1;
}
}
//595 out
void send595out()
{
ST=0;
asm("nop");
ST=1;
}
//led in ative
void disled(void)
{
char i;
for(i=0;i<2;i++)
{
send595(position);
send595(led_7[dis_buff]);
send595out();
delay();
}
}
//main
void main(void)
{
TRISB=0x00;
PORTB=0X00;
while (1)
{
disled();
}
} |