單片機(jī)驅(qū)動(dòng)點(diǎn)陣向上流動(dòng)顯示I Love U -Love漂亮的心形
/**
*功能:點(diǎn)陣向上流動(dòng)顯示I Love U -Love是漂亮的心形
*時(shí)間:2014年3月10日16:19:14
*作者:寒竹子
*備注:動(dòng)畫(huà)顯示原理:動(dòng)畫(huà)由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,//開(kāi)始全黑
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;//裝入初值,定時(shí)1ms
TR0 = 1;//start T0
EA = 1;//開(kāi)總中斷
ET0 = 1;//開(kāi)定時(shí)器T0中斷
}
/**********74HC138 init************/
void HC138_init()
{
ADDR3 = 0;
ENLED = 0;//使能U4
}
/**************timer0 interrupt**************/
void timer0_int() interrupt 1
{
static uchar j = 0;//用于刷新每一幀圖片,動(dòng)畫(huà)由32張圖片構(gòu)成
TH0 = 0xFC;
TL0 = 0x67;//1ms
counter++;//ms++
P0 = 0xFF;//消隱
//動(dòng)態(tài)刷新(刷新每一幀)
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++];//動(dòng)態(tài)刷新每一幀圖片
if (j >= 8)
{
j = 0;
}
//變化幀
if (counter >= 250)
{
counter = 0;
index++;//幀數(shù)++
if (index >= 32)
{
index = 0;//最多32幀圖片
}
}
}
評(píng)論