#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
unsigned char code taba[]={0x81,0xf3,0x49,0x61,0x33,0x25,0x05,0xf1,0x01,0x21,0x41,0x07,0x8d,0x43,0x0d,0x1d,0x85,0x13,0x23};
unsigned char code tabb[]={0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x01};
#define uchar unsigned char
#define uint unsigned int
//uchar num,num1
sbit SHCP=P1^6; //移位时钟
sbit STCP=P1^5; //并行输出时钟
sbit DS=P1^4; //串行数据输入
void delay1ms()
{
unsigned char i,j;
for(i=0;i<10;i++)
for(j=0;j<33;j++)
;
}
void delaynms(unsigned char n)
{
unsigned char i;
for(i=0;i<n;i++)
delay1ms();
}
//====控制595数据并行输出=============
void outchar()
{
STCP=0; //拉低锁存器控制时钟脉冲
STCP=1; //上升沿将数据送到输出锁存器
}
//====向595中写入一个字节的数据======
void putchar(uchar dat)
{
uchar m;
for(m=0;m<8;m++)
{
SHCP=0; //拉低移位时钟脉冲
DS=dat&0x80; //将数据送到串行数据输入端上
SHCP=1; //上升沿发生移位(移入一个数据)
dat=dat<<1; //数据移位
}
}
//=============主程序================
void main()
{
uchar i,j;
while(1){
for(i=0;i<8;i++)
putchar(tabb[i]);
putchar(taba[i]);
outchar();
delaynms(100);
}
}
怎么修改呢、我是新手请大神们帮帮忙 |