|
#include "reg52.h"
sbit SER=P3^4;
sbit SRCLK=P3^6;
sbit rCLK=P3^5;
#define LEDDZ_COL_PORT P0 //点阵列段码
unsigned char arr[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay_10us(unsigned int x)
{
while(x--);
}
void hc595_write_data(unsigned char dat) //hc595芯片读写函数
{
unsigned char i=0;
for(i=0;i<8;i++)
{
SER=dat>>7; //移位器先读最高位
dat<<=1;
SRCLK=0;
delay_10us(1);
SRCLK=1;
delay_10us(1);
}
rCLK=0; //(上升沿)点阵行段码一起存入寄存器
delay_10us(1);
rCLK=1;
}
void main()
{
unsigned char a=0;
LEDDZ_COL_PORT=0x00;
while(1)
{
for(a=0;a<8;a++)
{
hc595_write_data(0x00); //消隐
hc595_write_data(arr[a]);
delay_10us(50000);
}
}
} |
|