微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 51单片机驱动16X16点阵(上移左移闪烁显示)

51单片机驱动16X16点阵(上移左移闪烁显示)

时间:11-30 来源:互联网 点击:

仿真文件里面有电路图下载地址:http://www.51hei.com/bbs/dpj-20402-1.html,大家可以用protues直接看到效果
下面是源代码:
/*本次16X16点阵显示各种方式的显示程序全部由本人编写,由于本人学习C语言并不是太深,正好借此机会让各位老师学习学习。*/
/*本次显示程序的设计分三个阶断
第一阶段:左移显示方式的设计
第二阶段:上移显示方式的设计
第三阶段:闪烁显示方式的设计 */
#include
#define uchar unsigned char
#define uint unsigned int
uchar table1[]={
0xE0,0x0F,0x10,0x10,0x08,0x20,0x08,0x20,
0x08,0x20,0x10,0x10,0xE0,0x0F,0x00,0x00,/*"O",0*/

0x08,0x20,0xF8,0x3F,0x88,0x20,0xC0,0x01,
0x28,0x26,0x18,0x38,0x08,0x20,0x00,0x00};/*"K",1*//*上移显示的字符*/

uchar code table[]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x0C,0x20,0x0C,0x38,
0x0C,0x0F,0xEC,0x03,
0x7F,0x60,0x0F,0x63,
0xCC,0x31,0x0C,0x18,
0xEC,0x0F,0xEC,0x07,
0x0C,0x0C,0x0C,0x19,
0x8C,0x31,0xCC,0x60,
0x0C,0x20,0x00,0x00,/*"灰",0*/
0x20,0x00,0x30,0x00,
0xF8,0x3F,0xFC,0x7F,
0x6F,0x63,0x6F,0x63,
0xEC,0x63,0xFC,0x63,
0x7C,0x63,0x6C,0x63,
0x64,0x63,0xE0,0x63,
0xE0,0x73,0x00,0x30,
0x00,0x00,0x00,0x00,/*"色",1*/
0x00,0x00,0x9C,0x60,
0xDC,0x60,0x4C,0x66,
0x6C,0x66,0x2C,0x66,
0x0D,0x66,0x0F,0x7E,
0x0E,0x7E,0x2C,0x66,
0x6C,0x66,0x4C,0x66,
0xCC,0x66,0x9C,0x60,
0x1C,0x60,0x00,0x00,/*"空",2*/
0x00,0x00,0xF8,0x7F,
0xFB,0x7F,0x07,0x00,
0xF6,0x0F,0xF0,0x0F,
0x36,0x0D,0x36,0x0D,
0x36,0x0D,0xF6,0x0F,
0xF6,0x2F,0x06,0x60,
0xFE,0x7F,0xFE,0x3F,
0x00,0x00,0x00,0x00,/*"间",3*//*左移显示的字符*/

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
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 code table2[]={
0x60,0x06,0x6C,0x06,
0x6C,0x66,0xFC,0x7F,
0xFE,0x3F,0x66,0x03,
0x66,0x23,0x60,0x30,
0xFF,0x33,0xFF,0x1F,
0x60,0x1C,0x66,0x37,
0x6C,0x63,0x68,0x70,
0x00,0x70,0x00,0x00,/*"我",0*/
0x70,0x08,0x76,0x18,
0xB6,0x5D,0xBE,0x4D,
0xBE,0x67,0xF6,0x6F,
0xF6,0x3D,0xBE,0x35,
0xBE,0x35,0xB3,0x3D,
0xBB,0x6D,0xBF,0x65,
0xF7,0x61,0x70,0x60,
0x00,0x20,0x00,0x00,/*"爱",1*/
0x00,0x00,0xF8,0x18,
0x48,0x20,0x48,0x20,
0x48,0x20,0x48,0x20,
0x88,0x1F,0x00,0x00,/*"5",2*/
0x00,0x00,0x20,0x00,
0x30,0x00,0xF8,0x3F,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,/*"1",3*/
0x00,0x00,0x00,0x18,
0xFC,0x1B,0xFC,0x1B,
0x6D,0x1B,0x6F,0x1B,
0x6E,0x1B,0xFC,0x7F,
0xFC,0x7F,0x6E,0x1B,
0x6F,0x1B,0x6D,0x1B,
0xFC,0x1B,0xFC,0x1B,
0x00,0x18,0x00,0x00,/*"单",4*/
0x00,0x00,0x00,0x60,
0x00,0x38,0xFE,0x1F,
0xFE,0x07,0x30,0x03,
0x30,0x03,0x30,0x03,
0x30,0x03,0x3F,0x03,
0x3F,0x7F,0x30,0x7F,
0x30,0x00,0x30,0x00,
0x00,0x00,0x00,0x00,/*"片",5*/
0x18,0x06,0x98,0x03,
0xFF,0x7F,0xFF,0x7F,
0x98,0x01,0x18,0x23,
0x00,0x70,0xFE,0x3F,
0xFE,0x0F,0x06,0x00,
0x06,0x00,0xFE,0x3F,
0xFE,0x7F,0x00,0x60,
0x00,0x70,0x00,0x00,/*"机",6*/

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
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 v,flag,temp;
uchar i,j,k,shuz,shub,temp1;
uchar a,b,c,d,e,f,numa,numb;
uchar ii,jj,kk;
uchar iii,jjj,kkk;
uchar a3,b3;
uchar num3,temp3;
uchar temp2;
sbit le=P3^0;/*各变量值的初始化*/
void init();/*主函数的初始化声名*/
void init1();/*左移显示方式的初始化声名*/
void init2();/*上移显示方式的初始化声名*/
void init3();/*闪烁显示方式的初始化声名*/
void disp1();/*左移显示子程序声名*/
void disp2();/*上移显示子程序声名*/
void disp3();/*闪烁显示子程序声名*/
void delay(uint z)/*延时函数声名及定义*/
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=110;y>0;y--);
}
}
void main()
{
init();
while(1)//主循环
{
if(flag%3==0)//判断是不是左移显示方式
{
init1();//左移显示初始化
while(flag%3==0)//左移循环控制
{
for(i=0;i<=a;i++)//判断左移的字符个数
for(j=0;j<=v;j++)//向左移动的速度由变量v控制
for(k=i*2;k<(i*2+32);)//显示一幕
if(flag%3==0)//判断有没有中断,flag的值有没有变化
disp1();//若没有中断调用左移显示子程序
else
{
i=a;j=v;k=(i*2+32);//若有中断了初始化左移的各变量
}
}
}
if(flag%3==1)//判断是不是上移显示方式
{
init2();//上移显示初始化
while(flag%3==1)//上移循环控制
{
for(ii=0;ii<=15;ii++)//上移缓冲
{
for(jj=0;jj<=v;jj++)//向上移动的速度由变量v控制
{
for(kk=0;kk<=15;kk++)//显示一幕
if(flag%3==1)//判断有没有中断,flag的值有没有变化
disp2();//若没有中断调用左移显示子程序
else
{
ii=15;jj=v;kk=15;//若有中断了初始化左移的各变量
}
delay(1);
}

}
}
}
if(flag%3==2)//判断是不是闪烁显示方式
{
init3();//闪烁显示初始化
while(flag%3==2)//闪烁循环控制
{
for(iii=0;iii<=6*32;iii=iii+32)//判断闪烁显示的字符个数
for(jjj=0;jjj<=v*10;jjj++)//闪烁显示字符的速度由变量v控制
{
for(kkk=0;kkk<=15;kkk++)//显示一幕
if(flag%3==2)//判断有没有中断,flag的值有没有变化
disp3();//若没有中断调用闪烁显示子程序
num3=0;
temp3=0;//显示完一幕准备下一幕的显示
}
}
}
}
}
void init()//主程序初始化
{
EA=1;//CPU开放所有中断源的中断请求
EX0=1;//允许外部中断0中断
EX1=1;//允许外部中断1中断
IT0=1;//外部中断0采用边沿触发方式产生中断
IT1=1;//外部中断1采用边沿触发方式产生中断
v=15;//设置移动速度的初值
le=0;
}
void init1()//左移显示方式各变量的初始化
{
shuz=4;
shub=1;
a=shuz*16+shub*8+14;
P0=0;
P2=0;
temp1=0;
}
void disp1()//左移显示子程序
{
le=0;
P0=table[k];
k++;
P2=table[k];
k++;
P1=temp1;
le=1;
temp1++;
if(temp1==0x10)
temp1=0x00;
delay(1);

}
void init2()//上移显示方式各变量的初始化
{
P0=0;
P2=0;
temp2=0;
}
void disp2()//上移显示子程序
{
le=0;
numa=kk*2;
numb=kk*2+1;
a=table1[numa];
b=table1[numb];
if(jj==v)
{c=a>>1;
d=b<(8-1);
e=b>>1;
f=a<(8-1);
c=c|d;
table1[numa]=c;
e=e|f;
table1[numb]=e;
}
P0=a;
P2=b;
P1=temp2;
le=1;
temp2++;
if(temp2==0x10)
temp2=0x00;
delay(1);
}
void init3()//闪烁显示方式各变量的初始化
{
P0=0;
P2=0;
num3=0;
temp3=0;
}
void disp3()//闪烁显子程序
{
le=0;
a3=table2[iii+(num3++)];
b3=table2[iii+(num3++)];
P0=a3;
P2=b3;
P1=temp3++;
le=1;
delay(1);
}
void timerr1() interrupt 1//外部中断0的中断程序
{
v=15;//初始化移动速度
flag++;//flag值加1,改变显示方式
temp1=0x00;
temp2=0x00;
temp3=0x00;
}
void timerr0() interrupt 3
{
v=v/3;
if(v==0)
v=150;
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top