#include
//#define BLKN 4
//#include "reg52.h"
#define BLKN 2 //列锁存器数(=LED显示字数*2)
#define TOTAL 20 //待显示字个数,本例共20个
#define CONIO P1 //显示控制口
***it G=CONIO^4; //CONIO.7为154译码器显示允许控制信号端口,0时输出,1时输出全为高阻态.
***it RCLK=CONIO^5; //CONIO.6为595输出锁存器时钟信号端,1时输出数据,从1到0时锁存输出数据.
***it SCLR=CONIO^6; //CONIO.5为595移位寄存器清零口,平时为1,为0时,输出全为0.
//***it G=0x97;
//***it RCLK =0x96;
//***it SCLR =0x95;
void delay(unsigned int);
void dis1(void);
void dis2(void);
void dis3(void);
void dis4(void);
unsigned char data dispram[64];
unsigned char code Bmp[][32]={
/*-- 文字: 电 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xC0,0x07,0xDE,0xF7,0xDE,0xF7,0xC0,0x07,0xDE,0xF7,
0xDE,0xF7,0xDE,0xF7,0xC0,0x07,0xDE,0xF7,0xFE,0xFD,0xFE,0xFD,0xFF,0x01,0xFF,0xFF},
/*-- 文字: 子 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFF,0xFF,0xC0,0x0F,0xFF,0xDF,0xFF,0xBF,0xFF,0x7F,0xFE,0xFF,0xFE,0xFF,0xFE,0xFB,
0x00,0x01,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFA,0xFF,0xFD,0xFF},
/*-- 文字: 与 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFF,0xFF,0xF7,0xFF,0xF7,0xFB,0xF0,0x01,0xF7,0xFF,0xF7,0xFF,0xF0,0x03,0xFF,0xFB,
0xFF,0xFB,0xFF,0xDB,0x80,0x0B,0xFF,0xFB,0xFF,0xFB,0xFF,0xB7,0xFF,0xCF,0xFF,0xFF},
/*-- 文字: 信 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xF7,0x7F,0xF3,0x9F,0xE7,0xBF,0xE8,0x01,0xCF,0xFF,0xCC,0x07,0xAF,0xFF,0x6C,0x07,
0xEF,0xFF,0xEC,0x07,0xED,0xF7,0xED,0xF7,0xED,0xF7,0xEC,0x07,0xED,0xF7,0xFF,0xFF},
/*-- 文字: 息 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFE,0xFF,0xFD,0xFF,0xE0,0x0F,0xEF,0xEF,0xE0,0x0F,0xEF,0xEF,0xE0,0x0F,0xEF,0xEF,
0xE0,0x0F,0xFF,0xFF,0xF6,0xFF,0xD7,0x7B,0xD7,0x6D,0x97,0xED,0xF8,0x0F,0xFF,0xFF},
/*-- 文字: 工 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFF,0xFF,0xC0,0x03,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,
0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0x00,0x01,0xFF,0xFF,0xFF,0xFF},
/*-- 文字: 程 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xF2,0x07,0x8E,0xF7,0xEE,0xF7,0xEE,0xF7,0x02,0xF7,0xEE,0x07,0xCF,0xFF,0xC4,0x03,
0xAB,0xBF,0xAF,0xBF,0x6C,0x03,0xEF,0xBF,0xEF,0xBF,0xEF,0xBF,0xE8,0x01,0xEF,0xFF},
/*-- 文字: 学 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFE,0xF7,0xEF,0x73,0xF3,0x37,0xF7,0x6F,0x80,0x01,0xBF,0xFB,0x70,0x17,0xFF,0xBF,
0xFF,0x7F,0x80,0x01,0xFF,0x7F,0xFF,0x7F,0xFF,0x7F,0xFF,0x7F,0xFD,0x7F,0xFE,0xFF},
/*-- 文字: 院 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFF,0x7F,0x07,0xBF,0x70,0x01,0x6B,0xFB,0x5F,0xFF,0x5C,0x07,0x6F,0xFF,0x77,0xFF,
0x70,0x01,0x56,0xDF,0x6E,0xDF,0x7E,0xDF,0x7D,0xDD,0x7D,0xDD,0x7B,0xDD,0x77,0xE1},
/*-- 文字: O --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC3,0x83,0x99,0x7D,0x99,0x7D,0x99,0x7D,0x99,0x83,
0x99,0x7D,0x99,0x7D,0x99,0x7D,0xC3,0x83,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
/*-- 文字: 电 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xC0,0x07,0xDE,0xF7,0xDE,0xF7,0xC0,0x07,0xDE,0xF7,
0xDE,0xF7,0xDE,0xF7,0xC0,0x07,0xDE,0xF7,0xFE,0xFD,0xFE,0xFD,0xFF,0x01,0xFF,0xFF},
/*-- 文字: 气 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xF7,0xFF,0xF7,0xFF,0xE0,0x01,0xEF,0xFF,0xDF,0xFF,0xB0,0x07,0xFF,0xFF,0xE0,0x0F,
0xFF,0xEF,0xFF,0xEF,0xFF,0xEF,0xFF,0xEF,0xFF,0xF5,0xFF,0xF5,0xFF,0xF9,0xFF,0xFD},
/*-- 文字: 2 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFF,0xFF,0xFF,0xFF,0xF8,0x1F,0xF3,0xCF,0xE7,0xCF,0xE7,0xCF,0xFF,0x9F,0xFF,0x3F,
0xFE,0x7F,0xFC,0xFF,0xF9,0xFF,0xF3,0xFF,0xE7,0xFF,0xE7,0xF7,0xE0,0x07,0xFF,0xFF},
/*-- 文字: 班 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFE,0xFF,0x06,0x81,0xDE,0xEF,0xDE,0xEF,0xDE,0xEF,0xDA,0xEF,0x02,0x81,0xDA,0xEF,
0xD6,0xEF,0xDE,0xEF,0xDE,0xEF,0xC5,0xEF,0x3D,0xEF,0xFB,0x01,0xF7,0xFF,0xEF,0xFF},
/*-- 文字: 袁 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFE,0xFF,0xFE,0xFF,0xC0,0x07,0xFE,0xFF,0x00,0x01,0xFF,0xFF,0xE0,0x0F,0xEF,0xEF,
0xE0,0x0F,0xFC,0xFB,0xFB,0x77,0xF7,0xAF,0xC7,0xDF,0x35,0xE7,0xF3,0xF1,0xF7,0xFB},
/*-- 文字: 波 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xDF,0xBF,0xEF,0xBF,0xEF,0xBF,0xF8,0x01,0x7B,0xBB,0xAB,0xBF,0xAB,0xBF,0xE8,0x07,
0xDA,0xF7,0xDB,0x6F,0x1B,0x6F,0xDB,0x9F,0xD7,0x9F,0xD7,0x67,0xCE,0xF1,0xD9,0xFB},
/*-- 文字: 成 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFF,0x5F,0xFF,0x6F,0xFF,0x7F,0xC0,0x01,0xDF,0x7F,0xDF,0x7F,0xC1,0x77,0xDD,0x73,
0xDD,0xB7,0xDD,0xAF,0xDD,0xDF,0xD5,0x9F,0xBB,0x6D,0xBE,0xF5,0x79,0xF9,0xFF,0xFD},
/*-- 文字: 功 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFF,0xDF,0xFF,0xDF,0x80,0xDF,0xF7,0xDF,0xF4,0x03,0xF7,0xDB,0xF7,0xDB,0xF7,0xBB,
0xF6,0xBB,0xF1,0xBB,0x0F,0x7B,0xBF,0x7B,0xFE,0xFB,0xFD,0x87,0xFB,0xEF,0xFF,0xFF},
/*-- 文字: 啦 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFD,0xDF,0xFD,0xEF,0x0D,0xEF,0x60,0x01,0x6D,0xFF,0x6D,0xFB,0x6D,0xBB,0x6C,0xBB,
0x69,0xBB,0x05,0xBB,0x7D,0xD7,0xFD,0xD7,0xFD,0xFF,0xF5,0x01,0xFB,0xFF,0xFF,0xFF},
/*-- 文字: ! --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,
0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFF,0xFF,0xFE,0x7F,0xFE,0x7F},
};
/*******************主程序 ********************/
void main(void)
{SCON =0x00; //串行通信
TMOD =0x01; //定时器T0工作方式1、16位方式
TR0 =1; //启动定时器T0
CONIO =0xff; //P1端口初值:允许接收、锁存、显示
IE =0x82; //允许定时器T0中断
EA=1;
EX0=1; //启动外部中断
IT0=0; //低电平触发方式
PT0=1; //设优先级:定时器T0优先
while(1);
}
/********************延时程序 **********************/
void delay(unsigned int dt)
{
register unsigned char bt;
for(;dt;dt--)
for (bt =0;bt<255;bt++);
}
/********显示屏扫描(定时器T0中断)********************/
void leddisplay(void) interrupt 1 using 1
{
register unsigned char i,j=BLKN;
TH0=0xFC; //设定显示屏刷新率每秒62.5帧
TL0=0x18;
i=P1; //读取当前显示的行号
i=++i & 0x0f; //行号加1,屏蔽高4位
do {
j--;
SBUF = dispram[i*BLKN+j]; //送显示数据
while(!ti);TI=0;
} while(j); //完成一行数据的发送
G=1;
P1&=0xf0;
RCLK = 1;
P1 |=i;
RCLK=0;
G=0;
}
//外部中断
void led(void) interrupt 0
{ if(P3^6==0)
dis2();
else if(P3^7==0)
dis1();
}
/************************向内卷屏****************************/
void dis1(void)
{ register unsigned char i,k,l,j,q;
while(1)
{for (i=0; i
{
for (j=0; j<2; j++)
for (k=0; k<8; k++)
{
for (l=0; l<16; l++)
{
for(q=0;q
{
dispram[l*2+q*32] = dispram[l*2+q*32]<<1 | dispram[l*2+1+q*32]>>7;
if(q==BLKN/2-1) dispram[l*2+1+q*32] = dispram[l*2+1+q*32]<<1 | Bmp[i][l*2+j]>>(7-k);
else dispram[l*2+1+q*32] = dispram[l*2+1+q*32]<<1 | dispram[l*2+(q+1)*32]>>7;
}
}
delay(1000);
}
}
delay(3000);
}
}
/***********************左移子程序*****************************/
void dis2(void)
{register unsigned char i,l,k,j,q;
while(1)
{ for (i=0; i
{
for (j=0; j<16; j++)
{
for (k=0; k<15; k++)
{
for(q=0;q
{dispram[k*2+q*32] = dispram[(k+1)*2+q*32];dispram[k*2+1+q*32] = dispram[(k+1)*2+1+q*32];}
}
for(q=0;q
{dispram[30+q*32] = Bmp[q+i*BLKN/2][j*2];dispram[31+q*32] = Bmp[q+i*BLKN/2][j*2+1];}
delay(1000);
}
delay(3000);//滚动暂停
} }
}
/*********************右移子程序********************************/
void dis3(void)
{register unsigned char i,q;
while(1)
{ for (i=0;i<32;i++)
{
for(q=0;q
if (i%2) delay(120);
}
delay(10000);
} }
/******************上移子程序********************************/
void dis4(void)
{register unsigned char i,q,k,j,l;
while(1)
{for (i=0; i
{
for (j=2; j>0; j--)
for (k=0; k<8; k++)
{
for (l=0; l<16; l++)
{
for(q=0;q
{
dispram[l*2+1+q*32] = dispram[l*2+1+q*32]>>1 | dispram[l*2+q*32]<<7;
if(q==0) dispram[l*2+q*32] = dispram[l*2+q*32]>>1 | Bmp[i][l*2+j-1]<<(7-k);
else dispram[l*2+q*32] = dispram[l*2+q*32]>>1 | dispram[l*2+1+(q-1)*32]<<7;
}
}
delay(1000);
}
}
delay(3000);
} }
下载到单片机后,不管按下哪个按键,程序都是按dis2()函数运行的。而且字体运行后,按下按键无效
|