单片机汉字8x8点阵LED动态显示程序
为什么给点阵编程的时候,编程之前还亮一点点,而程序烧进去以后灯就全灭了,而且我再改程序也没用了,这是什么原因?哪位大神指教....
为什么给点阵编程的时候,编程之前还亮一点点,而程序烧进去以后灯就全灭了,而且我再改程序也没用了,这是什么原因?哪位大神指教.
展开
1个回答
展开全部
这个程序验证过,你可以参考试试:
//-------------------------------------------
//8*8矩阵循环显示字符和数字
//显示字符串在数组disstr[]中申明
//-------------------------------------------
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
//--------------------------------------------
uchar code Table_of_Digits[40][8]=
{
{0x1C,0x22,0x22,0x22,0x22,0x22,0x22,0x1C},//0
{0x08,0x18,0x08,0x08,0x08,0x08,0x08,0x1C},//1
{0x1C,0x22,0x02,0x02,0x1C,0x20,0x20,0x3E},//2
{0x1C,0x22,0x02,0x1C,0x02,0x02,0x22,0x1C},//3
{0x08,0x18,0x28,0x48,0x7C,0x08,0x08,0x08},//4
{0x3E,0x20,0x20,0x3E,0x02,0x02,0x22,0x1C},//5
{0x1C,0x22,0x20,0x3C,0x22,0x22,0x22,0x1C},//6
{0x3E,0x02,0x04,0x08,0x10,0x10,0x10,0x10},//7
{0x1C,0x22,0x22,0x1C,0x22,0x22,0x22,0x1C},//8
{0x1C,0x22,0x22,0x22,0x1E,0x02,0x22,0x1C},//9
{0x00,0x1C,0x22,0x22,0x22,0x3E,0x22,0x22},//A
{0x00,0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C},//B
{0x00,0x1C,0x22,0x20,0x20,0x20,0x22,0x1C},//C
{0x00,0x3C,0x22,0x22,0x22,0x22,0x22,0x3C},//D
{0x00,0x3E,0x20,0x20,0x3E,0x20,0x20,0x3E},//E
{0x00,0x3E,0x20,0x20,0x3E,0x20,0x20,0x20},//F
{0x00,0x1C,0x22,0x20,0x3E,0x22,0x22,0x1C},//G
{0x00,0x22,0x22,0x22,0x3E,0x22,0x22,0x22},//H
{0x00,0x1C,0x08,0x08,0x08,0x08,0x08,0x1C},//I
{0x00,0x3E,0x08,0x08,0x08,0x08,0x28,0x18},//J
{0x00,0x20,0x2C,0x30,0x20,0x30,0x2C,0x20},//K
{0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x3E},//L
{0x00,0x42,0x66,0x5A,0x42,0x42,0x42,0x42},//M
{0x00,0x00,0x2C,0x32,0x22,0x22,0x22,0x22},//n
{0x00,0x1C,0x22,0x22,0x22,0x22,0x22,0x1C},//O
{0x00,0x3C,0x22,0x22,0x3C,0x20,0x20,0x20},//P
{0x00,0x1C,0x22,0x22,0x22,0x2A,0x26,0x1F},//Q
{0x00,0x38,0x24,0x24,0x38,0x30,0x28,0x24},//R
{0x00,0x1C,0x22,0x20,0x1C,0x02,0x22,0x1C},//S
{0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08},//T
{0x00,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//U
{0x00,0x22,0x22,0x22,0x14,0x14,0x08,0x00},//V
{0x00,0x41,0x41,0x49,0x55,0x55,0x63,0x41},//W
{0x00,0x00,0x42,0x24,0x18,0x18,0x24,0x42},//X
{0x00,0x22,0x22,0x14,0x08,0x10,0x20,0x00},//Y
{0x00,0x3E,0x02,0x04,0x08,0x10,0x20,0x3E},//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;
uchar key;
uchar xi;
uchar yi;
//---------------------------------------
uchar code disstr[]="C201600102020";
//---------------------------------------
sbit we1=P1^1;
sbit we2=P1^3;
//---------------------------------------
//主程序
//---------------------------------------
void main()
{
//P1=0x80;
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;
EX0=1;
IT0=1;
TR0=1; //启动T0
while(1);
}
//---------------------------------------
//外部中断0 中断函数
//按键处理
//---------------------------------------
void ext_int0() interrupt 0
{
key++;
key&=0x03;
}
//---------------------------------------
//定时器0 中断函数
//显示控制
//---------------------------------------
void LED_Screen_Display() interrupt 1
{
TH0=(65536-2000)/256; //2ms 定时
TL0=(65536-2000)%256;
switch(key)
{
//显示点阵图形
case 0:
P0=0xff;
if(Num_Index==0)disnum=disstr[Num_Index]-'A'+10;
else disnum=disstr[Num_Index]-'0';
we1=1;
P0=~Table_of_Digits[disnum][i];
we1=0;
P0=0xff; //输出位码和段码
we2=1;
P0=ydat[i];
we2=0;
if(++i==8) i=0; //每屏一个数字由8 个字节构成
if(++t==250) //每个数字刷新显示一段时间
{
t=0;
if(++Num_Index==13) Num_Index=0; //显示下一个数字
}
break;
//流水灯“点”模式
case 1:
we1=1;
P0=~xdat[xi];
we1=0;
we2=1;
P0=ydat[yi];
we2=0;
if(++t==250) //每个数字刷新显示一段时间
{
t=0;
yi++;
if(yi>7){yi=0;xi++;}
if(xi>7)xi=0;
}
break;
//流水灯“行列”模式
case 2:
we1=1;
P0=0x00;
we1=0;
P0=0xff; //输出位码和段码
we2=1;
P0=xdat[i];
we2=0;
if(++t==250) //每个数字刷新显示一段时间
{
if(++i==8) i=0; //每屏一个数字由8 个字节构成
t=0;
}
break;
default:
key=0;
i=0;
j=0;
t=0;
xi=0;
yi=0;
Num_Index=0;
we1=1;
P0=0xff;
we1=0;
we2=1;
P1=0x80;
we2=0;
break;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |