,51单片机控制LED左、右移显示、翻页显示。
时间:10-02
整理:3721RD
点击:
看不懂的地方在在程序注释后面写了 为红色部分,先谢谢了
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit sh_cp=P3^0; //595时钟端
sbit ds=P3^1; //595数据段
sbit st_cp=P3^3; //595锁存端
uchar num=20; //汉字个数
/***************************汉字字模和图像码****************//
uchar code tab[]={ //取码方式,阴码逆向,逐列,16*16
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x40,0x01,0x20,0x02,0x90,0x04,
0x48,0x09,0x24,0x12,0x12,0x24,0x09,0x48,0x04,0x10,0x02,0x20,0x00,0x00,0x00,0x00,/*"《",0*/
0x00,0x10,0x00,0x10,0xF8,0x13,0x49,0x12,0x4A,0x12,0x4C,0x12,0x48,0x12,0xF8,0xFF,
0x48,0x12,0x4C,0x12,0x4A,0x12,0x49,0x12,0xF8,0x13,0x00,0x10,0x00,0x10,0x00,0x00,/*"单",1*/
0x00,0x00,0x00,0x80,0x00,0x60,0xFE,0x1F,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x02,
0x20,0x02,0x3F,0x02,0x20,0xFE,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0x00,/*"片",2*/
0x10,0x04,0x10,0x03,0xD0,0x00,0xFF,0xFF,0x90,0x00,0x10,0x83,0x00,0x60,0xFE,0x1F,
0x02,0x00,0x02,0x00,0x02,0x00,0xFE,0x3F,0x00,0x40,0x00,0x40,0x00,0x78,0x00,0x00,/*"机",3*/
0x80,0x00,0x82,0x80,0x82,0x40,0x82,0x30,0xFE,0x0F,0x82,0x00,0x82,0x00,0x82,0x00,
0x82,0x00,0x82,0x00,0xFE,0xFF,0x82,0x00,0x82,0x00,0x82,0x00,0x80,0x00,0x00,0x00,/*"开",4*/
0x00,0x00,0x00,0x20,0x18,0x10,0x16,0x8C,0x10,0x83,0xD0,0x80,0xB8,0x41,0x97,0x46,
0x90,0x28,0x90,0x10,0x90,0x28,0x92,0x44,0x94,0x43,0x10,0x80,0x00,0x80,0x00,0x00,/*"发",5*/
0x00,0x08,0x00,0x08,0xF8,0x8F,0x88,0x48,0x88,0x28,0xFF,0x1F,0x88,0x08,0x88,0x08,
0x88,0x08,0xFF,0x1F,0x88,0x28,0x88,0x48,0xF8,0x8F,0x00,0x08,0x00,0x08,0x00,0x00,/*"典",6*/
0x20,0x44,0x22,0x42,0xA2,0x49,0x7E,0x48,0x22,0x48,0x22,0x48,0xFE,0x49,0x22,0x7E,
0x22,0x48,0x00,0x48,0x7C,0x48,0x00,0x49,0x00,0x4A,0xFF,0x41,0x00,0x40,0x00,0x00,/*"型",7*/
0x10,0x04,0x10,0x03,0xD0,0x00,0xFF,0xFF,0x90,0x00,0x14,0x89,0xE4,0x4B,0xAF,0x2A,
0xA4,0x1A,0xA4,0x0E,0xA4,0x1A,0xAF,0x2A,0xE4,0x4B,0x04,0x88,0x00,0x80,0x00,0x00,/*"模",8*/
0x20,0x10,0x20,0x30,0x20,0x10,0xFF,0x0F,0x20,0x88,0x20,0x48,0x08,0x21,0x08,0x11,
0x08,0x0D,0xFF,0x03,0x08,0x0D,0x08,0x11,0x08,0x21,0xF8,0x41,0x00,0x81,0x00,0x00,/*"块",9*/
0x40,0x00,0x40,0x00,0x42,0x00,0xCC,0x3F,0x00,0x90,0x40,0x88,0xA0,0x40,0x9E,0x43,
0x82,0x2C,0x82,0x10,0x82,0x28,0x9E,0x46,0xA0,0x41,0x20,0x80,0x20,0x80,0x00,0x00,/*"设",10*/
0x40,0x00,0x40,0x00,0x42,0x00,0xCC,0x7F,0x00,0x20,0x40,0x10,0x40,0x00,0x40,0x00,
0x40,0x00,0xFF,0xFF,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x00,0x00,/*"计",11*/
0x00,0x00,0x00,0x00,0x02,0x20,0x04,0x10,0x09,0x48,0x12,0x24,0x24,0x12,0x48,0x09,
0x90,0x04,0x20,0x02,0x40,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"》",12*/
/********************************“心”*************************************/
0x00,0x00,0xE0,0x00,0xF0,0x01,0xF8,0x03,0xFC,0x07,0xFC,0x0F,0xF8,0x1F,0xF0,0x3F,
0xF0,0x3F,0xF8,0x1F,0xFC,0x0F,0xFC,0x07,0xF8,0x03,0xF0,0x01,0xE0,0x00,0x00,0x00,/*"未命名文件",0*/
/*********************************清屏字模********************************/
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,
};
void send(uchar dat595);
void delay(uint n);
void disp(uchar k);
void dispmove(void);
void main()
{
while(1)
{
dispmove();
}
}
void send(uchar dat595) //595发送8位扫描段码子程序
{
uchar dat=dat595; //把要发送的数据给dat
uint i;
for(i=0;i<8;i++) //8位发送循环
{
dat<<=1; //数据左移一位给CY
ds=CY; //数据送至595数据端
sh_cp=0;
sh_cp=1;
}
}
void delay(uint n)
{
uint i,j;
for(i=0;i<n;i++)
for(j=0;j<100;j++);
}
void disp(uchar k)
{
uchar i,row,j,m;
uint g;
for(j=0;j<5;j++) // 动态显示5次,再移动
{
row=0x08; //74138的编码初值08第一行有效
for(i=0;j<16;i++) //16行循环有效
{
st_cp=0; 595锁存端无效
for(m=6;m>0;m--) 6组16*16数据发送循环
{
g=2*i+2*k+m*32-32; //取字模 {这里看不懂为什取字模是这样的}
send(tab[g+1]); //上半屏
send(tab[g]); //下半屏
}
P1=row;
row++;
st_cp=1;
delay(1);
}
}
}
void dispmove(void) //左、右移动、翻页显示
{
uchar k,j;
for(k=0;k<16*(num-6);k++) //num个字,6个16*16点的Led显示屏。K++为向后取码则左移
{
disp(k); //16*(num-6)为需要的点数{这里的点数是什么意思}
}
for(k=16*(num-6);k>0;k--) //K--为向后取码则右移
{
disp(k);
}
for(j=0;j<3;j++)
{
for(k=16;k>0;k--)
{
disp(16*16*j);
}
}
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit sh_cp=P3^0; //595时钟端
sbit ds=P3^1; //595数据段
sbit st_cp=P3^3; //595锁存端
uchar num=20; //汉字个数
/***************************汉字字模和图像码****************//
uchar code tab[]={ //取码方式,阴码逆向,逐列,16*16
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x40,0x01,0x20,0x02,0x90,0x04,
0x48,0x09,0x24,0x12,0x12,0x24,0x09,0x48,0x04,0x10,0x02,0x20,0x00,0x00,0x00,0x00,/*"《",0*/
0x00,0x10,0x00,0x10,0xF8,0x13,0x49,0x12,0x4A,0x12,0x4C,0x12,0x48,0x12,0xF8,0xFF,
0x48,0x12,0x4C,0x12,0x4A,0x12,0x49,0x12,0xF8,0x13,0x00,0x10,0x00,0x10,0x00,0x00,/*"单",1*/
0x00,0x00,0x00,0x80,0x00,0x60,0xFE,0x1F,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x02,
0x20,0x02,0x3F,0x02,0x20,0xFE,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0x00,/*"片",2*/
0x10,0x04,0x10,0x03,0xD0,0x00,0xFF,0xFF,0x90,0x00,0x10,0x83,0x00,0x60,0xFE,0x1F,
0x02,0x00,0x02,0x00,0x02,0x00,0xFE,0x3F,0x00,0x40,0x00,0x40,0x00,0x78,0x00,0x00,/*"机",3*/
0x80,0x00,0x82,0x80,0x82,0x40,0x82,0x30,0xFE,0x0F,0x82,0x00,0x82,0x00,0x82,0x00,
0x82,0x00,0x82,0x00,0xFE,0xFF,0x82,0x00,0x82,0x00,0x82,0x00,0x80,0x00,0x00,0x00,/*"开",4*/
0x00,0x00,0x00,0x20,0x18,0x10,0x16,0x8C,0x10,0x83,0xD0,0x80,0xB8,0x41,0x97,0x46,
0x90,0x28,0x90,0x10,0x90,0x28,0x92,0x44,0x94,0x43,0x10,0x80,0x00,0x80,0x00,0x00,/*"发",5*/
0x00,0x08,0x00,0x08,0xF8,0x8F,0x88,0x48,0x88,0x28,0xFF,0x1F,0x88,0x08,0x88,0x08,
0x88,0x08,0xFF,0x1F,0x88,0x28,0x88,0x48,0xF8,0x8F,0x00,0x08,0x00,0x08,0x00,0x00,/*"典",6*/
0x20,0x44,0x22,0x42,0xA2,0x49,0x7E,0x48,0x22,0x48,0x22,0x48,0xFE,0x49,0x22,0x7E,
0x22,0x48,0x00,0x48,0x7C,0x48,0x00,0x49,0x00,0x4A,0xFF,0x41,0x00,0x40,0x00,0x00,/*"型",7*/
0x10,0x04,0x10,0x03,0xD0,0x00,0xFF,0xFF,0x90,0x00,0x14,0x89,0xE4,0x4B,0xAF,0x2A,
0xA4,0x1A,0xA4,0x0E,0xA4,0x1A,0xAF,0x2A,0xE4,0x4B,0x04,0x88,0x00,0x80,0x00,0x00,/*"模",8*/
0x20,0x10,0x20,0x30,0x20,0x10,0xFF,0x0F,0x20,0x88,0x20,0x48,0x08,0x21,0x08,0x11,
0x08,0x0D,0xFF,0x03,0x08,0x0D,0x08,0x11,0x08,0x21,0xF8,0x41,0x00,0x81,0x00,0x00,/*"块",9*/
0x40,0x00,0x40,0x00,0x42,0x00,0xCC,0x3F,0x00,0x90,0x40,0x88,0xA0,0x40,0x9E,0x43,
0x82,0x2C,0x82,0x10,0x82,0x28,0x9E,0x46,0xA0,0x41,0x20,0x80,0x20,0x80,0x00,0x00,/*"设",10*/
0x40,0x00,0x40,0x00,0x42,0x00,0xCC,0x7F,0x00,0x20,0x40,0x10,0x40,0x00,0x40,0x00,
0x40,0x00,0xFF,0xFF,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x00,0x00,/*"计",11*/
0x00,0x00,0x00,0x00,0x02,0x20,0x04,0x10,0x09,0x48,0x12,0x24,0x24,0x12,0x48,0x09,
0x90,0x04,0x20,0x02,0x40,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"》",12*/
/********************************“心”*************************************/
0x00,0x00,0xE0,0x00,0xF0,0x01,0xF8,0x03,0xFC,0x07,0xFC,0x0F,0xF8,0x1F,0xF0,0x3F,
0xF0,0x3F,0xF8,0x1F,0xFC,0x0F,0xFC,0x07,0xF8,0x03,0xF0,0x01,0xE0,0x00,0x00,0x00,/*"未命名文件",0*/
/*********************************清屏字模********************************/
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,
};
void send(uchar dat595);
void delay(uint n);
void disp(uchar k);
void dispmove(void);
void main()
{
while(1)
{
dispmove();
}
}
void send(uchar dat595) //595发送8位扫描段码子程序
{
uchar dat=dat595; //把要发送的数据给dat
uint i;
for(i=0;i<8;i++) //8位发送循环
{
dat<<=1; //数据左移一位给CY
ds=CY; //数据送至595数据端
sh_cp=0;
sh_cp=1;
}
}
void delay(uint n)
{
uint i,j;
for(i=0;i<n;i++)
for(j=0;j<100;j++);
}
void disp(uchar k)
{
uchar i,row,j,m;
uint g;
for(j=0;j<5;j++) // 动态显示5次,再移动
{
row=0x08; //74138的编码初值08第一行有效
for(i=0;j<16;i++) //16行循环有效
{
st_cp=0; 595锁存端无效
for(m=6;m>0;m--) 6组16*16数据发送循环
{
g=2*i+2*k+m*32-32; //取字模 {这里看不懂为什取字模是这样的}
send(tab[g+1]); //上半屏
send(tab[g]); //下半屏
}
P1=row;
row++;
st_cp=1;
delay(1);
}
}
}
void dispmove(void) //左、右移动、翻页显示
{
uchar k,j;
for(k=0;k<16*(num-6);k++) //num个字,6个16*16点的Led显示屏。K++为向后取码则左移
{
disp(k); //16*(num-6)为需要的点数{这里的点数是什么意思}
}
for(k=16*(num-6);k>0;k--) //K--为向后取码则右移
{
disp(k);
}
for(j=0;j<3;j++)
{
for(k=16;k>0;k--)
{
disp(16*16*j);
}
}
}
绑定ing
不错的文档,值得收藏