https://static.assets-stash.eet-china.com/album/old-resources/2009/5/14/4324c7e4-3f73-4a49-8129-7a1789756cf4.rar/*********************************************************
实现功能:1.跑马灯
2.点阵数字1秒精确显示
3.点阵简单图形显示
********************************************************/
#include <reg51.h>
sbit s0=P3^0;
sbit s1=P3^1;
sbit s2=P3^2;
sbit s3=P3^3;
sbit s4=P3^4;
sbit s5=P3^5;
sbit s6=P3^6;
unsigned char code tab[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char code digittab[10][8]={0xff,0xff,0xc1,0xbe,0xbe,0xc1,0xff,0xff, //0
0xff,0xff,0xff,0xff,0xde,0x80,0xfe,0xff, //1
0xff,0xff,0xd8,0xba,0xba,0xba,0xc6,0xff, //2
0xff,0xff,0xdd,0xb6,0xb6,0xb6,0xc9,0xff, //3
0xff,0xff,0xf3,0xeb,0xdb,0x80,0xfb,0xff, //4
0xff,0xff,0x8d,0xae,0xae,0xae,0xb1,0xff, //5
0xff,0xff,0xc1,0xb6,0xb6,0xb6,0xd9,0xff, //6
0xff,0xff,0xbf,0xbf,0xbf,0xb0,0x8f,0xff, //7
0xff,0xff,0xc9,0xb6,0xb6,0xb6,0xc9,0xff, //8
0xff,0xff,0xcd,0xb6,0xb6,0xb6,0xc1,0xff //9
};
unsigned char code tutab [5][8]={ 0xcf,0xb7,0xbb,0xdd,0xbb,0xb7,0xcf,0xff , //心
0xed,0xeb,0xc3,0xb7,0xc3,0xeb,0xed,0xff, //星
0xff,0xff,0xc7,0xbb,0xbb,0xbb,0xc7,0xff , //圆
0xfb,0xf3,0xeb,0xdb,0xb7,0xaf,0x9f,0xbf, //平行
0xfb,0xf3,0xeb,0xdb,0xeb,0xf3,0xfb,0xff//三角形
};
unsigned int timecount;
unsigned char cnta;
unsigned char cntb;
#define N 253
#define M 253
void delay (int m)
{
unsigned char i,j,k;
for (i=0;i<m;i++)
for (k=0;k<5;k++)
for (j=0;j<253;j++);
}
void delay1 ()
{
unsigned char j;
for (j=0;j<156;j++);
}
void paomadeng ()
{
unsigned temp,a,b,i;
temp="0xfe";
P2=temp;
delay(N);
for(i=1;i<8;i++) //从右到左移动
{
a="temp"<<i;
b="temp">>(8-i);
P2=a|b;
delay(N); //延时
}
for(i=1;i<8;i++) //从左到右的移动
{
a="temp">>i;
b="temp"<<(8-i);
P2=a|b;
delay(N);
}
}
void shuzi ()
{
unsigned char i,j,k;
for (k=0;k<10;k++)
for (j=0;j<254;j++)
{
for (i=0;i<8;i++)
{
P1=tab;
P0=digittab[k];
delay1 ();
}
}
}
void xinxing()
{
unsigned char i;
for (i=0;i<8;i++)
{
P1=tab;
P0=tutab[0];
delay1 ();
}
}
void yuanxing ()
{
unsigned char i;
for (i=0;i<8;i++)
{
P1=tab;
P0=tutab[2];
delay1 ();
}
}
void xingxing ()
{
unsigned char i;
for (i=0;i<8;i++)
{
P1=tab;
P0=tutab[1];
delay1 ();
}
}
void sjxing ()
{
unsigned char i;
for (i=0;i<8;i++)
{
P1=tab;
P0=tutab[4];
delay1 ();
}
}
void xunhuan ()
{
unsigned char i,j,k;
for (k=0;k<5;k++)
for (j=0;j<254;j++)
{
for (i=0;i<8;i++)
{
P1=tab;
P0=tutab[k];
delay1 ();
}
}
}
void main ()
{
P2=0xff;
while (1)
{
if (s0==0)
{
delay (2);
if (s0==0)
paomadeng ();
}
if (s1==0)
{
delay (2);
if (s1==0)
shuzi ();
}
if (s2==0)
{
delay (2);
if (s2==0)
xinxing ();
}
if (s3==0)
{
delay (2);
if (s3==0)
yuanxing ();
}
if (s4==0)
{
delay (2);
if (s4==0)
xingxing ();
}
if (s5==0)
{
delay (2);
if (s5==0)
sjxing ();
}
if (s6==0)
{
delay (2);
if (s6==0)
xunhuan();
}
}
}
文章评论(0条评论)
登录后参与讨论