取模软件使用
一、打开软件->新建图像->输入高度、宽度->确定
二、点“模拟动画”->"放大格点”->黑色填充(黑色表示高电平1,白色表示低电平0)->构造图像,点修改图像中的“黑白反显图像”(可以点击“基本操作,保存图像”)
三、点击参数设置->其他选项->选中“横向取模”"字节倒序"(因为取模软件中左边为高位,右边为低位;我们实际电路图中刚好相反)
四、点击取模方式,选择C51格式,生成字节(0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7,)
点阵图像静态显示
实际原理图:
显示“❤”,代码:
#include <reg52.h>
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
unsigned char image[] = {0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7};
unsigned char THR0,TLR0;
void ConfigTimer(unsigned long ms);
void main()
{
unsigned char cnt = 0;
unsigned int i = 0;
ENLED = 0;
ADDR3 = 0;
ConfigTimer(1); //计算定时1ms,需要赋的初值,存在在 THR0,TLR0中
TMOD = TMOD & 0xF0;
TMOD = TMOD | 0x01; //设置定时器模式1 ,不影响高四位
TH0 = THR0; //定时器赋初值
TL0 = TLR0;
EA = 1; //使能总中断
ET0= 1; //使能T0中断
TR0 = 1; //启动定时器T0
while(1);
}
void ConfigTimer(unsigned long ms)
{
unsigned long temp;
temp = 65536 - ms*11059200/1000/12; //ms最大定时71ms
THR0 = (unsigned char)(temp>>8); //取计数值高八位 ,计数值不会超过65535,最多占用16位。
TLR0 = (char)temp; //取计数值低八位
}
void InterruptTimer0() interrupt 1 //每间隔1ms,点亮点整中的某一排,循环往复不停歇
{
static unsigned char i = 0;
TH0 = THR0;
TL0 = TLR0;
P0 = 0xff; //消隐
switch(i)
{
case 0:ADDR2=0;ADDR1=0;ADDR0=0;P0=image[i];i++;break;
case 1:ADDR2=0;ADDR1=0;ADDR0=1;P0=image[i];i++;break;
case 2:ADDR2=0;ADDR1=1;ADDR0=0;P0=image[i];i++;break;
case 3:ADDR2=0;ADDR1=1;ADDR0=1;P0=image[i];i++;break;
case 4:ADDR2=1;ADDR1=0;ADDR0=0;P0=image[i];i++;break;
case 5:ADDR2=1;ADDR1=0;ADDR0=1;P0=image[i];i++;break;
case 6:ADDR2=1;ADDR1=1;ADDR0=0;P0=image[i];i++;break;
case 7:ADDR2=1;ADDR1=1;ADDR0=1;P0=image[i];i=0;break;
default:break;
}
}
点阵图像动态显示
I ❤ U纵向移动,代码:
#include <reg52.h>
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
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}; //共40个元素
unsigned char THR0,TLR0;
void ConfigTimer(unsigned long ms);
void main()
{
unsigned char cnt = 0;
unsigned int i = 0;
ENLED = 0;
ADDR3 = 0;
ConfigTimer(1); //计算定时1ms,需要赋的初值,存在在 THR0,TLR0中
TMOD = TMOD & 0xF0;
TMOD = TMOD | 0x01; //设置定时器模式1 ,不影响高四位
TH0 = THR0; //定时器赋初值
TL0 = TLR0;
EA = 1; //使能总中断
ET0= 1; //使能T0中断
TR0 = 1; //启动定时器T0
while(1);
}
void ConfigTimer(unsigned long ms)
{
unsigned long temp;
temp = 65536 - ms*11059200/1000/12; //ms最大定时71ms
THR0 = (unsigned char)(temp>>8); //取计数值高八位 ,计数值不会超过65535,最多占用16位。
TLR0 = (char)temp; //取计数值低八位
}
void InterruptTimer0() interrupt 1 //每间隔1ms,点亮点整中的某一排,循环往复不停歇
{
static unsigned char i = 0; //索引
static unsigned char cnt = 0;
static unsigned char tmr = 0; //定时
TH0 = THR0;
TL0 = TLR0;
P0 = 0xff; //消隐
switch(i)
{
case 0:ADDR2=0;ADDR1=0;ADDR0=0;P0=image[i+cnt];i++;break;
case 1:ADDR2=0;ADDR1=0;ADDR0=1;P0=image[i+cnt];i++;break;
case 2:ADDR2=0;ADDR1=1;ADDR0=0;P0=image[i+cnt];i++;break;
case 3:ADDR2=0;ADDR1=1;ADDR0=1;P0=image[i+cnt];i++;break;
case 4:ADDR2=1;ADDR1=0;ADDR0=0;P0=image[i+cnt];i++;break;
case 5:ADDR2=1;ADDR1=0;ADDR0=1;P0=image[i+cnt];i++;break;
case 6:ADDR2=1;ADDR1=1;ADDR0=0;P0=image[i+cnt];i++;break;
case 7:ADDR2=1;ADDR1=1;ADDR0=1;P0=image[i+cnt];i=0;break;
default:break;
}
//每250ms更换一副图像
tmr++;
if(tmr==250)
{
tmr=0;
cnt++;
if(cnt==32)
cnt=0;
}
}
点阵倒计时(从9到0):
#include <reg52.h>
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
unsigned char code image[10][8] = {
{0xFF,0xC3,0xDB,0xDB,0xC3,0xDF,0xDF,0xC3}, //取模9
{0xFF,0xC3,0xDB,0xDB,0xC3,0xDB,0xDB,0xC3},
{0xFF,0xC3,0xDF,0xDF,0xDF,0xDF,0xDF,0xDF},
{0xFF,0xC3,0xFB,0xFB,0xC3,0xDB,0xDB,0xC3},
{0xFF,0xC3,0xFB,0xFB,0xC3,0xDF,0xDF,0xC3},
{0xFF,0xDB,0xDB,0xDB,0xC3,0xDF,0xDF,0xDF},
{0xFF,0xC3,0xDF,0xDF,0xC3,0xDF,0xDF,0xC3},
{0xFF,0xC3,0xDF,0xDF,0xC3,0xFB,0xFB,0xC3},
{0xFF,0xE7,0xEF,0xEF,0xEF,0xEF,0xEF,0xC7},
{0xFF,0xC3,0xDB,0xDB,0xDB,0xDB,0xDB,0xC3}, //取模0
};
unsigned char THR0,TLR0;
void ConfigTimer(unsigned long ms);
void main()
{
unsigned char cnt = 0;
unsigned int i = 0;
ENLED = 0;
ADDR3 = 0;
ConfigTimer(1); //计算定时1ms,需要赋的初值,存在在 THR0,TLR0中
TMOD = TMOD & 0xF0;
TMOD = TMOD | 0x01; //设置定时器模式1 ,不影响高四位
TH0 = THR0; //定时器赋初值
TL0 = TLR0;
EA = 1; //使能总中断
ET0= 1; //使能T0中断
TR0 = 1; //启动定时器T0
while(1);
}
void ConfigTimer(unsigned long ms)
{
unsigned long temp;
temp = 65536 - ms*11059200/1000/12; //ms最大定时71ms
THR0 = (unsigned char)(temp>>8); //取计数值高八位 ,计数值不会超过65535,最多占用16位。
TLR0 = (char)temp; //取计数值低八位
}
void InterruptTimer0() interrupt 1 //每间隔1ms,点亮点整中的某一排,循环往复不停歇
{
static unsigned char i = 0; //索引
static unsigned char cnt = 0; //图像标志
static unsigned int tmr = 0; //定时,不能定义为char
TH0 = THR0;
TL0 = TLR0;
P0 = 0xff; //消隐
switch(i)
{
case 0:ADDR2=0;ADDR1=0;ADDR0=0;P0=image[cnt][i];i++;break;
case 1:ADDR2=0;ADDR1=0;ADDR0=1;P0=image[cnt][i];i++;break;
case 2:ADDR2=0;ADDR1=1;ADDR0=0;P0=image[cnt][i];i++;break;
case 3:ADDR2=0;ADDR1=1;ADDR0=1;P0=image[cnt][i];i++;break;
case 4:ADDR2=1;ADDR1=0;ADDR0=0;P0=image[cnt][i];i++;break;
case 5:ADDR2=1;ADDR1=0;ADDR0=1;P0=image[cnt][i];i++;break;
case 6:ADDR2=1;ADDR1=1;ADDR0=0;P0=image[cnt][i];i++;break;
case 7:ADDR2=1;ADDR1=1;ADDR0=1;P0=image[cnt][i];i=0;break;
default:break;
}
//每1s更换一副图像
tmr++;
if(tmr==1000)
{
tmr=0;
cnt++;
if(cnt==10)
cnt=0;
}
}