點亮左上角點陣
#include <reg52.h>
void main(void)
{
P0 = 0xFE;
P1 = 0xE0;
while (1);
}
點亮第一排點陣
#include <reg52.h>
void main(void)
{
P0 = 0x00;
P1 = 0xE0;
while (1);
}
利用中斷點亮所有點陣
#include <reg52.h>
unsigned char code LedChar[] =
{
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7
};
void main(void)
{
TMOD = 0x10;//定時器1設定為模式1
TH1 = 0xFC;//設定定時器1的初值,0.001s
TL1 = 0x67;
EA = 1;//中斷總使能
ET1 = 1;//定時器1使能
TR1 = 1;//開啟定時器1
while (1);//等待中斷
}
/* 定時器1的中斷函式 */
void interrupt_(void) interrupt 3
{
static i = 0;
TH1 = 0xFC;//重新賦初值,0.001s
TL1 = 0x67;
if (i > 7)
i = 0;
P1 = LedChar[i];
P0 = 0x00;
i++;
}
利用數模工具以及中斷點亮心形圖案
#include <reg52.h>
unsigned char code LedChar[] =
{
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7
};
unsigned char code image[] =
{
0xFF, 0x99, 0x00, 0x00, 0x00, 0x81, 0xC3, 0xE7
};
void main(void)
{
TMOD = 0x10;//定時器1設定為模式1
TH1 = 0xFC;//設定定時器1的初值,0.001s
TL1 = 0x67;
EA = 1;//中斷總使能
ET1 = 1;//定時器1使能
TR1 = 1;//開啟定時器1
while (1);//等待中斷
}
/* 定時器1的中斷函式 */
void interrupt_(void) interrupt 3
{
static i = 0;
TH1 = 0xFC;//重新賦初值,0.001s
TL1 = 0x67;
if (i > 7)
i = 0;
P1 = LedChar[i];
P0 = image[i];
i++;
}