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--;
}
}