abc18434762843 发表于 2020-3-2 16:23
下边是昨天看到的程序,是八个595级联,主函数里边每个调用的函数都是先移了八位后就直接锁存了,后边再调 ...
不好意思,刚刚那个程序不全,现在补全
#include <reg52.h>
sbit st=P1^5; // 存储脉冲 该脉冲上升沿所有被所存的信号一起输出
sbit sh=P1^6; // 移位脉冲 该脉冲上升沿输出信号移位,但不一定输出
sbit DA=P1^7; // 待移入的数据信号
sbit oe_595=P3^6; // 595使能端
sbit oe_138=P1^4; // 138使能端
unsigned char code zf[4][32]= //从左到右 从上到下 横向8点右高位
{
0x00,0x10,0xFE,0x3F,0x80,0x00,0x80,0x00, //"正"
0x80,0x00,0x80,0x00,0x88,0x08,0x88,0x1F,
0x88,0x00,0x88,0x00,0x88,0x00,0x88,0x00,
0x88,0x00,0x88,0x20,0xFF,0x7F,0x00,0x00,
0x40,0x00,0x40,0x00,0x40,0x20,0xFF,0x7F, //"在"
0x20,0x00,0x20,0x02,0x10,0x02,0x10,0x0A,
0xC8,0x1F,0x0C,0x02,0x0A,0x02,0x09,0x02,
0x08,0x02,0x08,0x22,0xE8,0x7F,0x08,0x00,
0x00,0x00,0x02,0x22,0xE4,0x27,0x24,0x2A, //"测"
0xA1,0x2A,0xA6,0x2A,0xA4,0x2A,0xB0,0x2A,
0xA8,0x2A,0xA4,0x2A,0xA7,0x2A,0x84,0x20,
0x44,0x21,0x24,0x22,0x14,0x2A,0x04,0x10,
0x00,0x04,0x02,0x14,0x04,0x24,0x04,0x04, //"试"
0xF0,0x7F,0x00,0x04,0x07,0x04,0xE4,0x07,
0x84,0x04,0x84,0x08,0x84,0x08,0x84,0x08,
0x94,0x4B,0xEC,0x48,0x44,0x50,0x00,0x20
};
void Delay(unsigned int i) // 延时函数
{
while(--i)
;
}
void SendByte(unsigned char Dat) // 对595写入一个字节数据
{
unsigned char a;
for(a=0;a<8;a++) // 分8次移位输出到锁存器
{
if((Dat&0x80)==0x80) // 判断写0还是写1
{ DA=1; }
else
{ DA=0; }
sh = 0;
st = 0;
sh = 1; // SH上升沿所存移位输出信号
st = 1; // ST上升沿输出锁存数据
Dat=Dat<<1; // 数据移一位
}
}
void main(void) // 主程序
{
oe_595=0;oe_138=1; // 初始化 开595 关138
while(1)
{unsigned char i;
for(i=0;i<16;i++) // 共计16次,因为共有16行要扫描
{
SendByte(zf[0][i*2]);
SendByte(zf[0][i*2+1]);
SendByte(zf[1][i*2]);
SendByte(zf[1][i*2+1]);
SendByte(zf[2][i*2]);
SendByte(zf[2][i*2+1]);
SendByte(zf[3][i*2]);
SendByte(zf[3][i*2+1]); // 送某行的8列显示数据
P1=i; // 送扫描码
oe_138=0; // 开138 显示该行数据
Delay(100); // 延时一会
oe_138=1; // 关138
}
}
} |