一,项目准备过程
1.8*8点阵一个,杜邦线一个,51单片机一个
8*8点阵简介
8*8点阵是由64个发光二极管组成的,共阳极在一端,共阴极在一端(在进行连线的时候注意共阳极与共阴极)在仿真中判断阳极阴极的操作在点阵两端接口分别接正极和负极,如果亮则所接的阳极阴极正确,相反则正阴极接反。如下图:
首先静止的显示爱心,这里可以用一个取模软件
代码如下:
#include "reg52.h"
typedef unsigned int u16;
typedef unsigned char u8;
u8 lie[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
u8 hang[8]={0x00,0x18,0x3C,0x7E,0xFF,0xFF,0x66,0x00};
//0x00,0x18,0x24,0x42,0x81,0x5A,0x24,0x00};
#define LED_col P2
#define LED_row P1
void delay_10us(u16 ten_us)
{
while(ten_us--);
}
void main()
{
u8 i=0;
while(1)
{
for(i=0;i<8;i++)
{
LED_col=~lie[i];
LED_row=hang[i];
delay_10us(100);
LED_row=0x00;
}
}
}
此代码中有两种形式的爱心哦
动态爱心显示:
代码如下:
#include
typedef unsigned int u16;
typedef unsigned char u8;
u8 lie[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
u8 hang[]={
0x00,0x00,0x7e,0x81,0x81,0x7e,0x00,0x00,//0
0x00,0x00,0x82,0xff,0x80,0x00,0x00,0x00,//1
0x00,0x00,0xc2,0xa1,0x91,0x8e,0x00,0x00,//2
0x00,0x00,0x00,0x82,0xfe,0x82,0x00,0x00,//I
0x00,0x1c,0x3e,0x7c,0xf8,0x7c,0x3e,0x1c,//心
0x00,0x00,0x7e,0x80,0x80,0x80,0x7e,0x40,//U
};
void main()
{
u8 i;
u16 k,j;
u16 shu=8*6;
while(1)
{
for(j=0;j<48;j++)
for(i=0;i<8;i++)
{
P2=~(0x80>>i);
P3=hang[(i+j)%shu];
k=1000;while(k--);
P2=0xff;
P3=0x00;
}
}
}
仿真图如下: