拉幕式数码显示设计(附Proteus仿真)没事做,看到坛友发的题目就想了一下,因题目不是很清楚,以我的思维有两种理解,仿真中两种显示方式可以使用开关切换
程序如下(附件有源程序和Proteus仿真):
#include "reg52.h"
#define uchar unsigned char
uchar code table1[128]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,//8
0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x07,//87
0x00,0x00,0x00,0x00,0x00,0x7f,0x07,0x7d,//876
0x00,0x00,0x00,0x00,0x7f,0x07,0x7d,0x6d,//8765
0x00,0x00,0x00,0x7f,0x07,0x7d,0x6d,0x66,//87654
0x00,0x00,0x7f,0x07,0x7d,0x6d,0x66,0x4f,
0x00,0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5B,
0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5B,0x06,
0x07,0x7d,0x6d,0x66,0x4f,0x5B,0x06,0x00,
0x7d,0x6d,0x66,0x4f,0x5B,0x06,0x00,0x00,
0x6d,0x66,0x4f,0x5B,0x06,0x00,0x00,0x00,
0x66,0x4f,0x5B,0x06,0x00,0x00,0x00,0x00,
0x4f,0x5B,0x06,0x00,0x00,0x00,0x00,0x00,
0x5B,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//消失,数码管共阴
};
uchar code table2[]={0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x7f,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
0x7f,0x07,0x7d,0x00,0x00,0x00,0x00,0x00,
0x7f,0x07,0x7d,0x6d,0x00,0x00,0x00,0x00,
0x7f,0x07,0x7d,0x6d,0x66,0x00,0x00,0x00,
0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x00,0x00,
0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5B,0x00,
0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5B,0x06,
0x00,0x07,0x7d,0x6d,0x66,0x4f,0x5B,0x06,
0x00,0x00,0x7d,0x6d,0x66,0x4f,0x5B,0x06,
0x00,0x00,0x00,0x6d,0x66,0x4f,0x5B,0x06,
0x00,0x00,0x00,0x00,0x66,0x4f,0x5B,0x06,
0x00,0x00,0x00,0x00,0x00,0x4f,0x5B,0x06,
0x00,0x00,0x00,0x00,0x00,0x00,0x5B,0x06,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar counter,n;
sbit ls138=P3^0;
sbit swich=P3^7;
void timer0() interrupt 1 using 1
{
TH0=(65536-46920)/256;
TH0=(65536-46920)%256;
counter++;
if(counter==20)
{
counter=0;
n+=8;
if(n==128)n=0;
}
}
void delay(uchar i)
{
uchar j;
while(i--)
{
for(j=0;j<248;j++);
}
}
void disp1(uchar i)
{
uchar m;P2=0x00;
for(m=0;m<8;m++)
{
P0=table1
;
P2=~m;
ls138=0;
delay(1);
ls138=1;
i++;
}
}
void disp2(uchar i)
{
uchar m;P2=0x00;
for(m=0;m<8;m++)
{
P0=table2;
P2=~m;
ls138=0;
delay(1);
ls138=1;
i++;
}
}
void main()
{
n=0;
counter=0;
TMOD=0x01;
TH0=(65536-46920)/256;
TH0=(65536-46920)%256;
ET0=1;EA=1;
TR0=1;
while(1)
{
if(swich==1)disp1(n);
else disp2(n);
}
}