//-------------------------------------------
//8*8矩阵循环显示字符和数字
//显示字符串在数组disstr[]中申明
//-------------------------------------------
#include<reg51.h>
#include<intrins.h>
#include<string.h>
#include<absacc.h>
#define uchar unsigned char
#define uint unsigned int
//--------------------------------------------
//X向字模
//--------------------------------------------
uchar code Table_of_Digits[40][8]=
{
{0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00},//0
{0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00},//1
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},//2
{0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00},//3
{0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00},//4
{0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00},//5
{0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00},//6
{0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00},//7
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},//8
{0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00},//9
{0x00,0x3E,0x48,0x48,0x48,0x3E,0x00,0x00},//A
{0x00,0x00,0x7E,0x52,0x5A,0x6E,0x00,0x00},//B
{0x00,0x00,0x3C,0x42,0x42,0x24,0x00,0x00},//C
{0x00,0x00,0x7E,0x42,0x42,0x3C,0x00,0x00},//D
{0x00,0x00,0x7E,0x52,0x52,0x52,0x00,0x00},//E
{0x00,0x00,0x7E,0x50,0x50,0x40,0x00,0x00},//F
{0x00,0x3C,0x42,0x42,0x4A,0x2E,0x00,0x00},//G
{0x00,0x00,0x7E,0x10,0x10,0x7E,0x00,0x00},//H
{0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00},//I
{0x00,0x00,0x0C,0x02,0x02,0x7C,0x00,0x00},//J
{0x00,0x00,0x7F,0x08,0x14,0x22,0x00,0x00},//K
{0x00,0x00,0x7E,0x02,0x02,0x02,0x00,0x00},//L
{0x00,0x7E,0x20,0x10,0x20,0x7E,0x00,0x00},//M
{0x00,0x00,0x7E,0x30,0x08,0x06,0x7E,0x00},//N
{0x00,0x3C,0x42,0x42,0x42,0x42,0x3C,0x00},//O
{0x00,0x00,0x7E,0x48,0x48,0x70,0x00,0x00},//P
{0x00,0x3C,0x42,0x46,0x43,0x3C,0x00,0x00},//Q
{0x00,0x00,0x7E,0x58,0x5C,0x72,0x00,0x00},//R
{0x00,0x00,0x64,0x92,0x92,0x4C,0x00,0x00},//S
{0x00,0x40,0x40,0x7E,0x40,0x40,0x00,0x00},//T
{0x00,0x00,0x7C,0x02,0x02,0x7C,0x00,0x00},//U
{0x00,0x00,0x60,0x18,0x06,0x18,0x60,0x00},//V
{0x00,0x7E,0x0C,0x18,0x0C,0x7E,0x00,0x00},//W
{0x00,0x42,0x24,0x18,0x18,0x24,0x42,0x00},//X
{0x00,0x40,0x20,0x1E,0x20,0x40,0x00,0x00},//Y
{0x00,0X00,0x46,0x5A,0x72,0x42,0x00,0x00},//Z
};
//---------------------------------------
uchar code xdat[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
uchar code ydat[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//---------------------------------------
uchar i=0;
uchar j=0;
uchar t=0;
uchar Num_Index,disnum,disnum1;
uchar key;
uchar xi;
uchar yi;
uint len; //显示的字符串长度
uchar buffer[16];
//---------------------------------------
uchar code disstr[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; //显示内容自己可以任意定义,注意只能是大些字母和数字
//---------------------------------------
#define wei XBYTE[0xa000]
sbit dat=P1^1;
sbit clk=P1^0;
sbit ls0=P2^4;
sbit ls1=P2^5;
sbit ls2=P2^6;
sbit ls3=P2^7;
//---------------------------------------
//用74LS164来输出一个8位的数据,
//点亮相应的LED
//---------------------------------------
void sendbyte(uchar byte)
{
uchar num,c;
num=byte;
for(c=0;c<8;c++)
{
clk=0;
dat=num&0x01; //每一位的输出
clk=1; //每一次上升沿,输出一位数据
num>>=1; //右移位赋值 ,以供下一位的输出
}
}
//---------------------------------------
//主程序
//---------------------------------------
void main()
{
Num_Index=0; //从0 开始显示
TMOD=0x01; //T0 方式0
TH0=(65536-2000)/256; //2ms 定时
TL0=(65536-2000)%256;
IE=0x82;
key=0;
xi=0;
yi=0;
TR0=1; //启动T0
len=strlen(disstr);
while(1);
}
//---------------------------------------
//定时器0 中断函数
//显示控制
//---------------------------------------
void LED_Screen_Display() interrupt 1
{
uchar m,n;
TH0=(65536-2000)/256; //2ms 定时
TL0=(65536-2000)%256;
if(i==0)
{
if(disstr[Num_Index]>='A')disnum=disstr[Num_Index]-'A'+10; //求显示字符在字库中的位置
else disnum=disstr[Num_Index]-'0';
if(disstr[Num_Index+1]>='A')disnum1=disstr[Num_Index+1]-'A'+10; //连续取两个赋给缓冲器,便于滚动显示
else disnum1=disstr[Num_Index+1]-'0';
for(m=0;m<8;m++)buffer[m]=Table_of_Digits[disnum][m]; //给显示缓冲区赋值
for(m=0;m<8;m++)buffer[m+8]=Table_of_Digits[disnum1][m];
}
P0=0xff;
P2=0xa0;
P0=~buffer[i+n];
P2=0x00;
sendbyte(xdat[n]);
if(++n==8) n=0; //每屏一个数字由8 个字节构成
if(++t>=60) //每个数字刷新显示一段时间
{
i++;i%=8;
t=0;
if(i==0)
{
Num_Index++;
if(Num_Index>=(len-1))Num_Index=0; //显示下一个数字
}
}
}
|