第二十七课 点阵之三 动画1
程序讲解:
/*--------------------------------------------------------------*/
//LED8*8显示
#include <reg52.h>
#include "74HC595.H"
/*--------------------------------------------------------------*/
//全局变量定义
unsigned char disram[8]; //显示缓冲区
/*--------------------------------------------------------------*/
//图像代码 (可以用图像软件取 文章结尾有个下载链接)
unsigned char code pic[][8] = {
0x00,0x00,0x3C,0x42,0x42,0x3C,0x00,0x00, //0
0x00,0x00,0x00,0x44,0x7E,0x40,0x00,0x00, //1
0x00,0x00,0x76,0x52,0x52,0x5E,0x00,0x00, //2
0x00,0x00,0x52,0x52,0x52,0x7E,0x00,0x00, //3
0x00,0x10,0x18,0x14,0x7E,0x10,0x00,0x00, //4
0x00,0x00,0x5E,0x52,0x52,0x72,0x00,0x00, //5
0x00,0x00,0x7E,0x52,0x52,0x72,0x00,0x00, //6
0x00,0x00,0x02,0x02,0x02,0x7E,0x00,0x00, //7
0x00,0x00,0x7E,0x52,0x52,0x7E,0x00,0x00, //8
0x00,0x00,0x5E,0x52,0x52,0x7E,0x00,0x00, //9
0x44,0x7E,0x40,0x00,0x7E,0x42,0x7E,0x00, //10
0x00,0x18,0xE4,0x1D,0xE4,0x18,0x00,0x00, //01
0x10,0x08,0xE4,0x1D,0xE4,0x08,0x10,0x00, //02
0x04,0x04,0xE4,0x1D,0xE4,0x04,0x04,0x00, //03
//0x01,0xC2,0x24,0x1D,0x24,0xC2,0x01,0x00, //04
0x81,0x42,0x24,0x1D,0x24,0x42,0x81,0x00, //05
};
/*--------------------------------------------------------------*/
//定时器初始化
void T0_init(void)
{
TMOD = 0x01;
TH0 = 0xf8; //2ms
TL0 = 0x36;
IE = 0x82;
TR0 = 1;
}
/*-------------- ------------------------------------------------*/
//清除显示缓存区,即清屏
void clr_ram(void)
{
unsigned char i;
for(i = 0; i < 8; i++) disram = 0x00;
}
/*--------------------------------------------------------------*/
//显示图像函数
volatile void dis_pic(unsigned char num)
{
unsigned char i;
for(i = 0; i < 8; i++) disram = pic[num]; //将要显示的数据存到数据缓存区
}
/*--------------------------------------------------------------*/
//定时器中断服务
void T0_intservice(void) interrupt 1
{
static unsigned char n;
TH0 = 0xf8; //2ms
TL0 = 0x36;
Ser_IN(0x01 << n); //列扫
Ser_IN(~disram[n]); //行数据
Par_OUT(); //上升沿锁存输出
n++; if(n == 8) n = 0; //循环扫描
}
/*--------------------------------------------------------------*/
//延时500000+0us 函数定义
void delay500ms(void)
{
unsigned char i,j,k;
for(i=205;i>0;i--)
for(j=116;j>0;j--)
for(k=9;k>0;k--);
}
/*--------------------------------------------------------------*/
//延时200000+0us 函数定义
void delay(void)
{
unsigned char i,j,k;
for(i=201;i>0;i--)
for(j=32;j>0;j--)
for(k=14;k>0;k--);
}
/*--------------------------------------------------------------*/
//主函数
void main (void)
{
char i;
T0_init(); //定时器初始化
clr_ram(); //清显示缓冲区
for(i = 10; i >=0; i--) {delay500ms(); dis_pic(i);} //显示图像代码的前11行
while(1)
{
for(i = 11; i < 15; i++) {delay(); dis_pic(i);} //显示图像代码的后4行
}
}
本节重点
1、如何利用二维函数存储图片及如何显示二维函数中的图片信息
演示视频(动画一):
http://v.youku.com/v_show/id_XOTIzNjU0MjA=.html
相关程序(动画一):https://static.assets-stash.eet-china.com/album/old-resources/2009/6/3/ad3144c7-8dc6-4340-8093-eeeb65e844b5.rar
演示视频(动画二):
http://v.youku.com/v_show/id_XOTIzNjU1MDQ=.html
相关程序(动画二):https://static.assets-stash.eet-china.com/album/old-resources/2009/6/3/d9712d26-b597-4a47-88d8-cf3de82513d0.rar
单片机工具集下载:
http://blog.ednchina.com/Alexi2008/231927/message.aspx
文章评论(0条评论)
登录后参与讨论