控制16X16大点阵滚动显示:中国加油!
74LS138:
================================================================
引脚说明:
A0~A2:地址输入端
STA(E1):选通端
/STB(/E2)、/STC(/E3):选通端(低电平有效)
/Y0~/Y7:输出端(低电平有效)
VCC:电源正
GND:地
================================================================
功能说明:
①当一个选通端(E1)为高电平,另两个选通端((/E2))和(/E3))为低电平时,可将地址端(A0、A1、A2)的二进制编码在Y0至Y7对应的输出端以低电平译出。(即输
出为Y0至Y7的非)比如:A2A1A0=110时,则Y6输出端输出低电平信号。②利用 E1、E2和E3可级联扩展成 24 线译码器;若外接一个反相器还可级联扩展成 32 线译码器。
③若将选通端中的一个作为数据输入端时,74LS138还可作数据分配器。
④可用在8086的译码电路中,扩展内存。
================================================================
74HC595:
74HC595是一个8位串行输入、并行输出的位移缓存器:并行输出为三态输出。在SCK 的上升沿,串行数据由SER输入到内部的8位位移缓存器,并由Q7’输出,而并行输出则是在LCK的上升沿将在8位位移缓存器的数据存入到8位并行输出缓存器。当串行数据输入端OE的控制信号为低使能时,并行输出端的输出值等于并行输出缓存器所存储的值。而当OE为高电位,也就是输出关闭时,并行输出端会维持在高阻抗状态。
符号--------------------------------引脚 ----------------------------描述
Q0–Q7---------------------第15脚,第1-7脚--------------8位并行数据输出,
GND----------------------------- 第8脚 ----------------------地
Q7’ ------------------------------- 第9脚---------------------- 串行数据输出
MR------------------------------- 第10脚--------------------- 主复位(低电平)
SHCP ----------------------------第11脚---------------------- 数据输入时钟线
STCP---------------------------- 第12脚--------------------- 输出存储器锁存时钟线
OE --------------------------------第13脚 ---------------------输出有效(低电平)
DS --------------------------------第14脚--------------------- 串行数据输入
VCC------------------------------ 第16脚 ---------------------电源
关于级联可以参考这篇文章:74HC595级联介绍
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
#define Lie P1
sbit SHCP = P2^0;
sbit DS = P2^1;
sbit STCP = P2^2;
uchar code led[ ] ={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xF8,0x03,0x08,0x01,0x08,0x01,0x08,0x01,0x08,0x01,0x08,0x01,0xFF,0xFF,
0x08,0x01,0x08,0x01,0x08,0x01,0x08,0x01,0x08,0x01,0xF8,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xFF,0x02,0x40,0x0A,0x50,0x8A,0x50,0x8A,0x50,0x8A,0x50,0xFA,0x5F,
0x8A,0x50,0x8A,0x56,0x8A,0x54,0x0A,0x50,0x02,0x40,0xFE,0xFF,0x00,0x00,0x00,0x00,
0x10,0x40,0x10,0x20,0x10,0x10,0xFF,0x0F,0x10,0x20,0x10,0x40,0xF0,0x3F,0x00,0x00,
0x00,0x00,0xF8,0x7F,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x7F,0x00,0x00,0x00,0x00,
0x10,0x04,0x62,0x04,0x44,0xFE,0x08,0x01,0x00,0x00,0xF0,0xFF,0x10,0x42,0x10,0x42,
0x10,0x42,0xFF,0x7F,0x10,0x42,0x10,0x42,0x10,0x42,0xF0,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x78,0x00,0x78,0x80,0x33,0xE0,0x03,
0xF8,0x01,0xFE,0x00,0x7F,0x00,0x1F,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
//uchar led[]={}
void shift16bit(uchar dat1,uchar dat2) //595??16???
{
uchar i;
STCP=0;
for(i=0;i<8;i++)
{
SHCP=0;
if(dat1 & 0x80) DS=1;
else DS=0;
dat1<<=1;
SHCP=1;
}
for(i=0;i<8;i++)
{
SHCP=0;
if(dat2 &0x80) DS=1;
else DS=0;
dat2<<=1;
SHCP=1;
}
STCP=1;
}
void delay(uint x)
{
uint i;
for(i=0;i<x;i++);
}
void main()
{
uchar i,x=0;
uint n;
while(1)
{
for(n=0;n<5;n++) //控制滚动速度
for(i=0;i<16;i++)//控制字形代码共16列
{
Lie=i;
shift16bit(led[2*i+2*x+1],led[2*i+2*x]);//取出每一列的数据
delay(100);
}
x++;
if(x==96) x=0;
}
}