点亮点阵以及点阵的图像显示
点亮左上角点阵
#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++;
}
本文来自博客园,作者:EricsT,转载请注明原文链接:https://www.cnblogs.com/EricsT/p/18536126