最简单的点阵显像
时间:10-02
整理:3721RD
点击:
#include <AT89X52.H> //包含头文件
unsigned char mode; //显示模式,0-3对应4个表情
unsigned char face1[8]={
0x7C,
0x10,
0x10,
0x10,
0x10,
0x10,
0x10,
0x7C
};
unsigned char face2[8]={
0x00,
0x6C,
0xFE,
0xFE,
0xFE,
0x7C,
0x38,
0x10
};
unsigned char face3[8]={
0x42,
0x42,
0x42,
0x42,
0x42,
0x42,
0x3C,
0x00
};
unsigned char face4[8]={
0x10,
0x38,
0x38,
0x38,
0x10,
0x10,
0x00,
0x10
};
void delay() //延时函数
{
unsigned int c;
c=300;
while(c--){}
}
void main(void) //主函数
{
unsigned int i,j;
mode=0;
P0=0XFF; //P0口各脚输出高电平,点阵不显示
while(1)
{
for(j=0;j<20;j++)
for(i=0;i<8;i++) //点阵8列动态扫描法显示,每次扫描一列并发送数据码
{
if(mode==0) //模式0-3分别对应4种表情,根据模式选择表情所对应的显示码
P0=face1[i];
if(mode==1)
P0=face2[i];
if(mode==2)
P0=face3[i];
if(mode==3)
P0=face4[i];
P2=~(1<<i); //扫描该列
delay(); //延时
}
mode++;
if(mode>3)
mode=0;
}
}
unsigned char mode; //显示模式,0-3对应4个表情
unsigned char face1[8]={
0x7C,
0x10,
0x10,
0x10,
0x10,
0x10,
0x10,
0x7C
};
unsigned char face2[8]={
0x00,
0x6C,
0xFE,
0xFE,
0xFE,
0x7C,
0x38,
0x10
};
unsigned char face3[8]={
0x42,
0x42,
0x42,
0x42,
0x42,
0x42,
0x3C,
0x00
};
unsigned char face4[8]={
0x10,
0x38,
0x38,
0x38,
0x10,
0x10,
0x00,
0x10
};
void delay() //延时函数
{
unsigned int c;
c=300;
while(c--){}
}
void main(void) //主函数
{
unsigned int i,j;
mode=0;
P0=0XFF; //P0口各脚输出高电平,点阵不显示
while(1)
{
for(j=0;j<20;j++)
for(i=0;i<8;i++) //点阵8列动态扫描法显示,每次扫描一列并发送数据码
{
if(mode==0) //模式0-3分别对应4种表情,根据模式选择表情所对应的显示码
P0=face1[i];
if(mode==1)
P0=face2[i];
if(mode==2)
P0=face3[i];
if(mode==3)
P0=face4[i];
P2=~(1<<i); //扫描该列
delay(); //延时
}
mode++;
if(mode>3)
mode=0;
}
}
呵呵
还行
学习下,,,,,,