单片机驱动点阵向上流动显示I Love U -Love漂亮的心形
/**
*功能:点阵向上流动显示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帧图片
}
}
}
单片机驱动点阵流动显 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)