原理图能够从http://www.51hei.com/f/ks51.pdf 这儿下载,单片机类型是stc89c51
/**
*功用:点阵向上活动显现I Love U -Love是美丽的心形
*时刻:2014年3月10日16:19:14
*作者:寒竹子
*补白:动画显现原理:动画由32张图片构成,每一毫秒改写一帧图片,每250ms改变一帧,共32帧。
**/
#include
typedef unsigned int uint;
typedef unsigned char uchar;
//74HC138
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
//I Love U 取模编码
uchar code table[] = {/*宽8,高40*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,//开端全黑
0xFF,0xC3,0xE7,0xE7,0xE7,0xE7,0xC3,0xFF,//I
0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7,//heart
0xFF,0x99,0x99,0x99,0x99,0x99,0x81,0xC3,//U
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF//消隐,去掉乱码
};
uchar counter = 0, index = 0;//图片改写索引(要改写32张,每张距离250ms)
void timer0_init();
void HC138_init();
void main(void)
{
timer0_init();
HC138_init();
while (1);
}
/********timer0 init**********/
void timer0_init()
{
TMOD |= 0x01;//T1 方法1
TH0 = 0xFC;
TL0 = 0x67;//装入初值,守时1ms
TR0 = 1;//start T0
EA = 1;//开总中止
ET0 = 1;//开守时器T0中止
}
/**********74HC138 init************/
void HC138_init()
{
ADDR3 = 0;
ENLED = 0;//使能U4
}
/**************timer0 interrupt**************/
void timer0_int() interrupt 1
{
static uchar j = 0;//用于改写每一帧图片,动画由32张图片构成
TH0 = 0xFC;
TL0 = 0x67;//1ms
counter++;//ms++
P0 = 0xFF;//消隐
//动态改写(改写每一帧)
switch (j)
{
case 0: ADDR2 = 0; ADDR1 = 0; ADDR0 = 0;
break;
case 1: ADDR2 = 0; ADDR1 = 0; ADDR0 = 1;
break;
case 2: ADDR2 = 0; ADDR1 = 1; ADDR0 = 0;
break;
case 3: ADDR2 = 0; ADDR1 = 1; ADDR0 = 1;
break;
case 4: ADDR2 = 1; ADDR1 = 0; ADDR0 = 0;
break;
case 5: ADDR2 = 1; ADDR1 = 0; ADDR0 = 1;
break;
case 6: ADDR2 = 1; ADDR1 = 1; ADDR0 = 0;
break;
case 7: ADDR2 = 1; ADDR1 = 1; ADDR0 = 1;
break;
default: break;
}
P0 = table[index + j++];//动态改写每一帧图片
if (j >= 8)
{
j = 0;
}
//改变帧
if (counter >= 250)
{
counter = 0;
index++;//帧数++
if (index >= 32)
{
index = 0;//最多32帧图片
}
}
}