点阵的动画显示之上下移动
250ms上移
#include <reg52.h>
unsigned char code LedChar[] =
{
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7
};
unsigned char code image[] =
{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xC3, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xC3, 0xFF,
0x99, 0x00, 0x00, 0x00, 0x81, 0xC3, 0xE7, 0xFF,
0x99, 0x99, 0x99, 0x99, 0x99, 0x81, 0xC3, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
void main(void)
{
TMOD = 0x01;//定时器0设置为模式1
TH0 = 0xFC;//设置定时器0的初始值,0.001s
TL0 = 0x67;
EA = 1;//中断总开关使能
ET0 = 1;//定时器0中断使能
TR0 = 1;//启动定时器0
while (1);
}
void interrupt0() interrupt 1
{
static unsigned char i = 0;
static unsigned char index = 0;
static unsigned char tmr = 0;
TH0 = 0xFC;//重新设置定时器0的初始值,0.001s
TL0 = 0x67;
if (i > 7)
i = 0;
P1 = LedChar[i];
P0 = image[i + index];
i++;
tmr++;
if (tmr >= 250)//250ms开始移动
{
tmr = 0;
index++;
if (index >= 32)
index = 0;
}
}
250ms下移
#include <reg52.h>
unsigned char code LedChar[] =
{
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7
};
unsigned char code image[] =
{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xC3, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xC3, 0xFF,
0x99, 0x00, 0x00, 0x00, 0x81, 0xC3, 0xE7, 0xFF,
0x99, 0x99, 0x99, 0x99, 0x99, 0x81, 0xC3, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
void main(void)
{
TMOD = 0x01;//定时器0设置为模式1
TH0 = 0xFC;//设置定时器0的初始值,0.001s
TL0 = 0x67;
EA = 1;//中断总开关使能
ET0 = 1;//定时器0中断使能
TR0 = 1;//启动定时器0
while (1);
}
void interrupt0() interrupt 1
{
static unsigned char i = 0;
static unsigned char index = 32;
static unsigned char tmr = 0;
TH0 = 0xFC;//重新设置定时器0的初始值,0.001s
TL0 = 0x67;
if (i > 7)
i = 0;
P1 = LedChar[i];
P0 = image[i + index];
i++;
tmr++;
if (tmr >= 250)//250ms开始移动
{
tmr = 0;
if (0 == index)
index = 32;
index--;
}
}
本文来自博客园,作者:EricsT,转载请注明原文链接:https://www.cnblogs.com/EricsT/p/18537585