关于51单片机以及74HC595,8x8点阵的使用 6个(16x16点阵)
(入门者写勿喷) 仿真图 链接:https://pan.baidu.com/s/1JSrtxjnzWJyPfvOLtnEGkg 提取码:zkmf
代码如下 `#include <at89x51.h> #include “intrins.h” typedef unsigned int uint; typedef unsigned char uchar;
sbit SRCLK1 = P1^0;
sbit SER1 = P1^1;
sbit RCLK1 = P1^2;
sbit SRCLK2 = P1^3;
sbit SER2 = P1^4;
sbit RCLK2 = P1^5;
// 负责扫描
uchar code ledwei[]={ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; // 滚动显示 uchar code ledduan1[]={ // 起始屏幕空白 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,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,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,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,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,0x00,0x00,0x00,0xF0,0x0F,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x04, 0xFF,0xFF,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x04,0xF0,0x0F,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xFE,0xFF,0x02,0x40,0x12,0x48,0x92,0x48,0x92,0x48,0x92,0x48, 0xF2,0x4F,0x92,0x48,0x92,0x4A,0x92,0x4C,0x12,0x48,0x02,0x40,0xFE,0xFF,0x00,0x00, 0x00,0x00,0x40,0x00,0x44,0x80,0x24,0x88,0x14,0x84,0x7F,0x42,0x94,0x45,0x24,0x29, 0x00,0x11,0x24,0x11,0x14,0x09,0x7F,0x05,0x14,0x03,0x24,0x00,0x44,0x00,0x40,0x00, 0x00,0x00,0x20,0x00,0x24,0x08,0x24,0x48,0x24,0x84,0xFE,0x7F,0x23,0x02,0x22,0x41, 0x20,0x40,0x20,0x20,0xFF,0x13,0x20,0x0C,0x22,0x14,0x2C,0x22,0xA0,0x41,0x20,0xF8, 0x00,0x00,0x00,0x00,0xF8,0x7F,0x0C,0x21,0x0B,0x21,0x08,0x21,0x08,0x21,0xF8,0x7F, 0x40,0x00,0x30,0x00,0x8F,0x00,0x08,0x43,0x08,0x80,0x08,0x40,0xF8,0x3F,0x00,0x00, 0x00,0x00,0x40,0x00,0x44,0x80,0x24,0x88,0x14,0x84,0x7F,0x42,0x94,0x45,0x24,0x29, 0x00,0x11,0x24,0x11,0x14,0x09,0x7F,0x05,0x14,0x03,0x24,0x00,0x44,0x00,0x40,0x00,
// 显示 去除乱码
0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x0F,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x04, 0xFF,0xFF,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x04,0xF0,0x0F,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xFE,0xFF,0x02,0x40,0x12,0x48,0x92,0x48,0x92,0x48,0x92,0x48, 0xF2,0x4F,0x92,0x48,0x92,0x4A,0x92,0x4C,0x12,0x48,0x02,0x40,0xFE,0xFF,0x00,0x00, 0x00,0x00,0x40,0x00,0x44,0x80,0x24,0x88,0x14,0x84,0x7F,0x42,0x94,0x45,0x24,0x29, 0x00,0x11,0x24,0x11,0x14,0x09,0x7F,0x05,0x14,0x03,0x24,0x00,0x44,0x00,0x40,0x00, 0x00,0x00,0x20,0x00,0x24,0x08,0x24,0x48,0x24,0x84,0xFE,0x7F,0x23,0x02,0x22,0x41, 0x20,0x40,0x20,0x20,0xFF,0x13,0x20,0x0C,0x22,0x14,0x2C,0x22,0xA0,0x41,0x20,0xF8, 0x00,0x00,0x00,0x00,0xF8,0x7F,0x0C,0x21,0x0B,0x21,0x08,0x21,0x08,0x21,0xF8,0x7F, 0x40,0x00,0x30,0x00,0x8F,0x00,0x08,0x43,0x08,0x80,0x08,0x40,0xF8,0x3F,0x00,0x00, 0x00,0x00,0x40,0x00,0x44,0x80,0x24,0x88,0x14,0x84,0x7F,0x42,0x94,0x45,0x24,0x29, 0x00,0x11,0x24,0x11,0x14,0x09,0x7F,0x05,0x14,0x03,0x24,0x00,0x44,0x00,0x40,0x00,
}; //静止显示 uchar code inc [] = { 0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x0F,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x04, 0xFF,0xFF,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x04,0xF0,0x0F,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xFE,0xFF,0x02,0x40,0x12,0x48,0x92,0x48,0x92,0x48,0x92,0x48, 0xF2,0x4F,0x92,0x48,0x92,0x4A,0x92,0x4C,0x12,0x48,0x02,0x40,0xFE,0xFF,0x00,0x00, 0x00,0x00,0x40,0x00,0x44,0x80,0x24,0x88,0x14,0x84,0x7F,0x42,0x94,0x45,0x24,0x29, 0x00,0x11,0x24,0x11,0x14,0x09,0x7F,0x05,0x14,0x03,0x24,0x00,0x44,0x00,0x40,0x00, 0x00,0x00,0x20,0x00,0x24,0x08,0x24,0x48,0x24,0x84,0xFE,0x7F,0x23,0x02,0x22,0x41, 0x20,0x40,0x20,0x20,0xFF,0x13,0x20,0x0C,0x22,0x14,0x2C,0x22,0xA0,0x41,0x20,0xF8, 0x00,0x00,0x00,0x00,0xF8,0x7F,0x0C,0x21,0x0B,0x21,0x08,0x21,0x08,0x21,0xF8,0x7F, 0x40,0x00,0x30,0x00,0x8F,0x00,0x08,0x43,0x08,0x80,0x08,0x40,0xF8,0x3F,0x00,0x00, 0x00,0x00,0x40,0x00,0x44,0x80,0x24,0x88,0x14,0x84,0x7F,0x42,0x94,0x45,0x24,0x29, 0x00,0x11,0x24,0x11,0x14,0x09,0x7F,0x05,0x14,0x03,0x24,0x00,0x44,0x00,0x40,0x00,
};
void delay(uchar xms) //延时函数 for与while { uint i,j; for(i=xms; i>0; i–){ for(j=240; j>0; j–){ }} } void delay1(uint i){ while(i–); }
void Hc595SendByte(uchar dat1,uchar dat2,uchar dat3,uchar dat4,uchar dat5,uchar dat6,uchar dat7,uchar dat8,uchar dat9,uchar dat10,uchar dat11,uchar dat12,uchar dat13,uchar dat14){ uchar a; SRCLK1 = 1; RCLK1 = 1; SRCLK2 = 1; RCLK2 = 1; for(a=0;a<8;a++) //发送8位数 1 { SER1 = dat1 >> 7; //从最高位开始发送 dat1 <<= 1; SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 2
{
SER1 = dat2 >> 7; //从最高位开始发送
dat2 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 3
{
SER1 = dat3 >> 7; //从最高位开始发送
dat3 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 4
{
SER1 = dat4 >> 7; //从最高位开始发送
dat4 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 5
{
SER1 = dat5 >> 7; //从最高位开始发送
dat5 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 6
{
SER1 = dat6 >> 7; //从最高位开始发送
dat6 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 7
{
SER1 = dat7 >> 7; //从最高位开始发送
dat7 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 8
{
SER1 = dat8 >> 7; //从最高位开始发送
dat8 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 9
{
SER1 = dat9 >> 7; //从最高位开始发送
dat9 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 10
{
SER1 = dat10 >> 7; //从最高位开始发送
dat10 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 11
{
SER1 = dat11 >> 7; //从最高位开始发送
dat11 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 12
{
SER1 = dat12 >> 7; //从最高位开始发送
dat12 <<= 1;
SRCLK1 = 0; //发送时序
SRCLK1 = 1;
}
for(a=0;a<8;a++) //发送8位数 13
{
SER2 = dat13 >> 7; //从最高位开始发送
dat13 <<= 1;
SRCLK2 = 0; //发送时序
SRCLK2 = 1;
}
for(a=0;a<8;a++) //发送8位数 14
{
SER2 = dat14 >> 7; //从最高位开始发送
dat14 <<= 1;
SRCLK2 = 0; //发送时序
SRCLK2 = 1;
}
RCLK1 = 0;
RCLK2 = 0;
RCLK1 = 1;
RCLK2 = 1;
} // ********************* 列扫描 ************************* void main(){ uint i,a,s; while(1) { for(a=0;a<3213;a+=2) //汉字的切换 { if(a==3212){a=326;} for(s=0;s<1000000;s++) //控制运行速度(极限静止) { for(i=0;i<16;i++) //显示每个汉字 { // 静止 Hc595SendByte(inc[2i+a+160+1],inc[2i+a+160],inc[2i+a+128+1],inc[2i+a+128],inc[2i+a+96+1],inc[2i+a+96],inc[2i+a+64+1],inc[2i+a+64],inc[2i+a+32+1],inc[2i+a+32],inc[2i+a+1],inc[2i+a],ledwei[i+16],ledwei[i]); // 滚动 //Hc595SendByte(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); //Hc595SendByte(ledduan1[2i+a+160+1],ledduan1[2i+a+160],ledduan1[2i+a+128+1],ledduan1[2i+a+128],ledduan1[2i+a+96+1],ledduan1[2i+a+96],ledduan1[2i+a+64+1],ledduan1[2i+a+64],ledduan1[2i+a+32+1],ledduan1[2i+a+32],ledduan1[2i+a+1],ledduan1[2*i+a],ledwei[i+16],ledwei[i]);
}
}
}
}
}
`
|