下面是我的一些源程序,以后留个纪念:
/*
********************************************************************
*****************************16*16点阵******************************
********************************************************************
功能描述:可以将字显示左移右移,和屏,垂直移动
编者:甄亮
最后更改日期:2012.4.25
*/
#include
#include
#define uint unsigned int
#define uchar unsigned char
uint code zima1[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",33*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00,/*"^",30*/
0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,/*"_",31*/
0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00,/*"^",32*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",29*/
0x10,0x04,0x1F,0xFC,0x10,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x0C,0x00,0x00,/*"L",28*/
0x00,0x04,0x00,0x3C,0x03,0xC4,0x1C,0x40,0x07,0x40,0x00,0xE4,0x00,0x1C,0x00,0x04,/*"A",27*/
0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x17,0xC4,0x10,0x04,0x08,0x18,0x00,0x00,/*"E",26*/
0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x11,0xC0,0x11,0x30,0x0E,0x0C,0x00,0x04,/*"R",25*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",23*/
0x08,0x00,0x30,0x02,0x21,0x02,0x22,0x82,0x24,0x82,0x28,0x82,0xA0,0x82,0x60,0xFE,
0x20,0x82,0x28,0x82,0x24,0x82,0x22,0x82,0x21,0x02,0x28,0x02,0x30,0x00,0x00,0x00,/*"空",13*/
0x00,0x00,0x02,0x01,0x42,0x02,0x42,0x04,0x42,0x08,0x42,0x10,0x42,0x60,0x7F,0x80,
0x42,0x40,0x42,0x20,0x42,0x10,0x42,0x08,0x42,0x0C,0x42,0x06,0x02,0x04,0x00,0x00,/*"天",12*/
0x00,0x00,0x3F,0xFF,0x02,0x00,0x91,0x40,0x48,0x78,0x01,0x80,0x4A,0x78,0x4A,0x48,
0x4F,0xC8,0x52,0x48,0x52,0x78,0x42,0x02,0x40,0x01,0x7F,0xFE,0x00,0x00,0x00,0x00,/*"阔",11*/
0x08,0x20,0x06,0x20,0x80,0xFF,0x6F,0x00,0x00,0x80,0x08,0x80,0x1F,0xF8,0xE8,0x88,
0x2C,0xC8,0x2A,0xA8,0x28,0x8A,0x28,0x89,0x2F,0xFE,0x20,0x88,0x20,0x88,0x00,0x00,/*"海",10*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
/***************************zima2******************************************************/
uint code zima2[]={
0x00,0x02,0x00,0x0C,0x3F,0xF2,0x20,0x04,0x2E,0x09,0x22,0x11,0x22,0x62,0xBF,0xA2,
0x62,0x94,0x22,0x88,0x2A,0x94,0x26,0xE4,0x22,0x82,0x22,0x03,0x20,0x02,0x00,0x00,/*"废",0*/
0x08,0x20,0x08,0x30,0xFF,0xE1,0x08,0x42,0x08,0x4C,0x1F,0xF2,0x10,0x22,0x14,0x12,
0x14,0xFE,0xFE,0x02,0x55,0x02,0x55,0xFE,0x51,0x12,0x5B,0x22,0x10,0x02,0x00,0x00,/*"墟",1*/
0x00,0x10,0x1F,0xF8,0x00,0x10,0xFF,0xF0,0x00,0x22,0x1F,0xEC,0x00,0x30,0xFF,0xC0,
0x90,0x3C,0x97,0x84,0x90,0x84,0x9F,0xFC,0x90,0x84,0xF7,0xBE,0x00,0x00,0x00,0x00,/*"崛",2*/
0x02,0x06,0x12,0xF8,0x12,0x04,0x12,0x02,0xFF,0xFE,0x12,0x42,0x12,0x42,0x00,0x02,
0x23,0xE2,0x22,0x12,0x22,0x12,0x22,0x12,0x3E,0x12,0x00,0x72,0x00,0x02,0x00,0x00,/*"起",3*/
0x00,0x04,0x10,0x06,0x10,0x0C,0x10,0x10,0x10,0x18,0x10,0x24,0x90,0x24,0x50,0x44,
0x30,0x82,0x11,0x02,0x12,0x02,0x14,0x02,0x38,0x02,0x10,0x02,0x00,0x02,0x00,0x00,/*"之",0*/
0x00,0x02,0x00,0x0C,0xFF,0xF0,0xA0,0x01,0xAF,0x91,0xAA,0xE2,0xBA,0xBA,0xAA,0xA4,
0xAA,0xA4,0xAA,0xAA,0xAA,0xB2,0xAF,0xA3,0xA0,0x02,0x80,0x02,0x00,0x00,0x00,0x00,/*"厦",5*/
0x00,0x00,0x0E,0x0C,0x10,0x14,0x10,0x24,0x10,0x44,0x11,0x84,0x0E,0x0C,0x00,0x00,/*"2",0*/
0x00,0x00,0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00,/*"0",1*/
0x00,0x00,0x08,0x04,0x08,0x04,0x1F,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00,/*"1",2*/
0x00,0x00,0x0E,0x0C,0x10,0x14,0x10,0x24,0x10,0x44,0x11,0x84,0x0E,0x0C,0x00,0x00,/*"2",3*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xE0,0x03,0x20,0x04,0x24,0x08,0x24,0x1F,0xFC,0x00,0x24,0x00,0x00,/*"4",0*/
0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*".",5*/
0x00,0x00,0x0E,0x0C,0x10,0x14,0x10,0x24,0x10,0x44,0x11,0x84,0x0E,0x0C,0x00,0x00,/*"2",6*/
0x00,0x00,0x1F,0x98,0x10,0x84,0x11,0x04,0x11,0x04,0x10,0x88,0x10,0x70,0x00,0x00,/*"5",7*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*****************************zima3*******************************/
uint code zima3[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x11,0xC0,0x11,0x30,0x0E,0x0C,0x00,0x04,/*"R",25*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uint code zima4[]={
0x04,0x20,0x04,0x20,0x44,0x42,0x44,0x41,0x7F,0xFE,0x84,0x80,0x84,0x80,0x04,0x08,
0x04,0x08,0xFF,0x10,0x04,0xE0,0x44,0x58,0x35,0x84,0x04,0x02,0x04,0x0F,0x00,0x00,/*"我",0*/
0x00,0x02,0x02,0x04,0x4D,0x05,0x69,0x09,0x59,0x32,0x49,0xE2,0x6F,0x54,0x59,0x54,
0xC9,0x48,0x89,0x58,0x99,0x64,0xE9,0x44,0x89,0x02,0x09,0x03,0x0C,0x02,0x00,0x00,/*"爱",1*/
0x00,0x10,0x00,0x10,0x1F,0xD0,0x14,0x90,0x94,0x90,0x74,0x90,0x54,0x90,0x1F,0xFF,
0x14,0x90,0x34,0x90,0xD4,0x90,0x54,0x90,0x1F,0xD0,0x00,0x10,0x00,0x10,0x00,0x00,/*"单",2*/
0x00,0x01,0x00,0x02,0x00,0x0C,0x7F,0xF0,0x08,0x80,0x08,0x80,0x08,0x80,0x08,0x80,
0x08,0x80,0xF8,0x80,0x08,0x80,0x08,0xFF,0x08,0x00,0x18,0x00,0x08,0x00,0x00,0x00,/*"片",3*/
0x10,0x20,0x10,0xC0,0x13,0x00,0xFF,0xFF,0x12,0x00,0x11,0x82,0x10,0x0C,0x00,0x30,
0x7F,0xC0,0x40,0x00,0x40,0x00,0x40,0x00,0x7F,0xFC,0x00,0x02,0x00,0x1E,0x00,0x00,/*"机",4*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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 temp;
***it DS=P1^0;//串行输入14
***it ST=P1^1;// 锁存开关12
***it SH=P1^2;//串行时钟11
***it oe1=P1^3;//高阻.片选1
***it oe2=P1^4;//片选2
***it a=P3^0;
***it b=P3^1;
***it c=P3^2;
***it d=P3^3;
***it oe3=P3^4;
void suo1();
void suo2();
void duan(uchar u);
void delay(uint i);
void wei(uchar w);
void display1();
void display2();
void display3();
void display4();
void main()
{
while(1)
{
delay(1000);
display2();
delay(1000);
display1();
delay(1000);
display3();
delay(1000);
display4();
delay(1000);
}
}
/*************************延时程序*****************************/
void delay(uint i)
{
uint j;
for(i;i>0;i--)
for(j=255;j>0;j--);
}
/*************************段选开关***************************/
void duan(uchar u)
{
uint y,q;
oe1=0;
oe2=0;
q=u;
temp=q;
for(y=0;y<8;y++)//输入一个段码
{
SH=0;//时钟为0
DS=temp&0x80;// 送入串行数据输入端//
SH=1;
temp=temp<<1;//右移
}
}
/*****************74hc595************************/
void wei(uchar w)
{
oe3=0;
switch(w)
{
case 0:d=0;c=0;b=0;a=0;break;
case 1:d=0;c=0;b=0;a=1;break;
case 2:d=0;c=0;b=1;a=0;break;
case 3:d=0;c=0;b=1;a=1;break;
case 4:d=0;c=1;b=0;a=0;break;
case 5:d=0;c=1;b=0;a=1;break;
case 6:d=0;c=1;b=1;a=0;break;
case 7:d=0;c=1;b=1;a=1;break;
case 8:d=1;c=0;b=0;a=0;break;
case 9:d=1;c=0;b=0;a=1;break;
case 10:d=1;c=0;b=1;a=0;break;
case 11:d=1;c=0;b=1;a=1;break;
case 12:d=1;c=1;b=0;a=0;break;
case 13:d=1;c=1;b=0;a=1;break;
case 14:d=1;c=1;b=1;a=0;break;
case 15:d=1;c=1;b=1;a=1;break;
default:break;
}
delay(1);
}
/**************************display 1右移*******************************/
void display1()
{
uchar b=0,q,j;
for(q=136;q>0;q--)
{
for(j=0;j<3;j++)
{
for(b=0;b<16;b++)
{
wei(b);
duan(zima1[(b+q)*2+1]);
duan(zima1[(b+q)*2]);
ST=0;//锁存关
ST=1;//on
P2=0xff;
oe3=1;
}
P2=0xff;
oe1=1;
oe2=1;
}
}
}
/******************* display1左移*******************************/
void display2()
{
uchar b=0,q,j;
for(q=0;q<160;q++)
{
for(j=0;j<3;j++)
{
for(b=0;b<16;b++)
{
wei(b);
duan(zima2[(b+q)*2+1]);
duan(zima2[(b+q)*2]);
ST=0;//锁存关
ST=1;//on
P2=0xff;
oe3=1;
}
P2=0xff;
oe1=1;
oe2=1;
}
}
}
/**************和屏***************我爱单片机*/
void display3()
{
uchar q,b,i;
for(q=8;q>0;q--)
{
for(i=0;i<3;i++)
{
for(b=0;b<8;b++)
{
wei(b);
duan(zima3[(b+q)*2+1]);
duan(zima3[(b+q)*2]);
ST=0;
ST=1;
P2=0xff;
oe3=1;
}
P2=0xff;
oe1=1;
oe2=1;
}
}
for(q=0;q<8;q++)
{ for(i=0;i<3;i++)
{
for(b=9;b<16;b++)
{
wei(b);
duan(zima3[(b+q)*2+1]);
duan(zima3[(b+q)*2]);
ST=0;
ST=1;
P2=0xff;
oe3=1;
}
P2=0xff;
oe1=1;
oe2=1;
}
}
}
/*****************垂直移动************************/
void display4()
{
uchar b=0,q,j,y1,y2,k;
for(q=0;q<16;q++)
{
for(j=0;j<15;j++)
{
for(b=0;b<16;b++)
{
y1=zima4[(b*2)+k*32+1];
y2=zima4[(b)*2+k*32];
y1=_cror_(y1,q);
y2=_cror_(y2,q);
wei(b);
duan(y1);
duan(y2);
ST=0;//锁存关
ST=1;//on
P2=0xff;
oe3=1;
} P2=0xff;
oe1=1;
oe2=1;
}
}
k++;
if(k==16)
{ k=0;
}
oe1=1;
oe2=1;
}
实验体会:
这次所有的原件全部才用的是模块化设计的思路,一个模块一个模块的焊接,然后测试完成,最后综合调试。
下一个实验将是一个功能强大,综合性很强的LCD 液晶显示项目....很具有挑战性....敬请期待....
...........海阔天空.........REAL.........