51单片机 点阵问题 点阵只闪一下就不亮了
用中断来点亮一个8*8的LED心型P0口为点阵负极,P2口为点阵正极想让点阵长时间显示心形图案,现在只显示一下就灭了***************************...
用中断来点亮一个8*8的LED心型
P0口为点阵负极,P2口为点阵正极
想让点阵长时间显示心形图案,现在只显示一下就灭了
****************************************
# include <reg51.h> // 头文件
unsigned char code image[] = {
0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7 //心形图案代码
};
void main()
{
EA = 1;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
ET0 = 1;
TR0 = 1;
while(1);
}
//中断函数
void InterruptTimer0() interrupt 1
{
static unsigned char i = 0; //动态扫描索引
TH0 = 0xFC;
TL0 = 0x67;
//以下代码完成LED点阵的扫描刷新
P0 = 0xFF;
switch(i)
{
case 0:P2 = 0x01;i++;P0 = image[0];break;
case 1:P2 = 0x02;i++;P0 = image[1];break;
case 2:P2 = 0x04;i++;P0 = image[2];break;
case 3:P2 = 0x08;i++;P0 = image[3];break;
case 4:P2 = 0x10;i++;P0 = image[4];break;
case 5:P2 = 0x20;i++;P0 = image[5];break;
case 6:P2 = 0x40;i++;P0 = image[6];break;
case 7:P2 = 0x80;i++;P0 = image[7];break;
default:break;
}
} 展开
P0口为点阵负极,P2口为点阵正极
想让点阵长时间显示心形图案,现在只显示一下就灭了
****************************************
# include <reg51.h> // 头文件
unsigned char code image[] = {
0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7 //心形图案代码
};
void main()
{
EA = 1;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
ET0 = 1;
TR0 = 1;
while(1);
}
//中断函数
void InterruptTimer0() interrupt 1
{
static unsigned char i = 0; //动态扫描索引
TH0 = 0xFC;
TL0 = 0x67;
//以下代码完成LED点阵的扫描刷新
P0 = 0xFF;
switch(i)
{
case 0:P2 = 0x01;i++;P0 = image[0];break;
case 1:P2 = 0x02;i++;P0 = image[1];break;
case 2:P2 = 0x04;i++;P0 = image[2];break;
case 3:P2 = 0x08;i++;P0 = image[3];break;
case 4:P2 = 0x10;i++;P0 = image[4];break;
case 5:P2 = 0x20;i++;P0 = image[5];break;
case 6:P2 = 0x40;i++;P0 = image[6];break;
case 7:P2 = 0x80;i++;P0 = image[7];break;
default:break;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询