数码管动态扫描应用
电路图
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BRv12eba-1603777049766)(C:\Users\86182\Pictures\Saved Pictures\8段数码管.jpg)]](https://img-blog.csdnimg.cn/2020102713375076.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDY1NzkyNQ==,size_16,color_FFFFFF,t_70#pic_center)
t1动态扫描
#include <reg51.h>
unsigned char code tab1[16] = {0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code tab2[8] ={2,0,2,0,1,0,1,9};
unsigned char code tab3[8] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void delay(unsigned int x)
{
unsigned int i,j;
for(j=0;j<x;j++)
for(i=0;i<120;i++);
}
void main()
{
unsigned char i,m,n;
while(1)
{
for(i=0;i<8;i++)
{
n = tab2[i];
P2 = tab1[n];
P1 = tab3[i];
delay(1);
P1 = 0xff;
delay(1);
}
}
}
t2交替闪烁
#include <reg51.h>
unsigned char code tab[16] = {0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code tab1[8] = {2,0,0,0,0,5,2,3};
unsigned char code tab2[8] = {1,2,3,4,5,6,7,8};
char scan;
char i,j,k;
char *ptr;
void scanner(char *);
void delay(unsigned int x);
main()
{
while(1)
{
ptr = &tab1[0];
scanner(ptr);
ptr = &tab2[0];
scanner(ptr);
}
}
void scanner(char *x)
{
for(k=0;k<30;k++)
{
scan = 1;
for(i=0;i<8;i++)
{
j = *(x+7-i);
P2 = tab[j];
P1 = ~scan;
delay(1);
scan<<=1;
P1 = 0xff;
delay(1);
}
}
}
void delay(unsigned int x)
{
unsigned int i,j;
for(j=0;j<x;j++)
for(i=0;i<120;i++);
}
t3_0飞入显示
#include <reg51.h>
unsigned char code tab[9] = {0xb0,0x38,0x5c,0x2A,0xf9,0x39,0x6d,0x3f,0x00};
char code disp[36][8] = { {8,8,8,8,8,8,8,0},{8,8,8,8,8,8,0,8},{8,8,8,8,8,0,8,8},{8,8,8,8,0,8,8,8},{8,8,8,0,8,8,8,8},{8,8,0,8,8,8,8,8},{8,0,8,8,8,8,8,8},{0,8,8,8,8,8,8,8},
{0,8,8,8,8,8,8,1},{0,8,8,8,8,8,1,8},{0,8,8,8,8,1,8,8},{0,8,8,8,1,8,8,8},{0,8,8,1,8,8,8,8},{0,8,1,8,8,8,8,8},{0,1,8,8,8,8,8,8},
{0,1,8,8,8,8,8,2},{0,1,8,8,8,8,2,8},{0,1,8,8,8,2,8,8},{0,1,8,8,2,8,8,8},{0,1,8,2,8,8,8,8},{0,1,2,8,8,8,8,8},
{0,1,2,8,8,8,8,3},{0,1,2,8,8,8,3,8},{0,1,2,8,8,3,8,8},{0,1,2,8,3,8,8,8},{0,1,2,3,8,8,8,8},
{0,1,2,3,8,8,8,4},{0,1,2,3,8,8,4,8},{0,1,2,3,8,4,8,8},{0,1,2,3,4,8,8,8},
{0,1,2,3,4,8,8,5},{0,1,2,3,4,8,5,8},{0,1,2,3,4,5,8,8},
{0,1,2,3,4,5,8,6},{0,1,2,3,4,5,6,8},
{0,1,2,3,4,5,6,7} };
void scanner(char);
void delay(unsigned int t);
main()
{
char i;
while(1)
{
for(i=0;i<36;i++)
scanner(i);
}
}
void scanner(char x)
{
char i,j,k;
char scan;
for(k=0;k<10;k++)
{
scan = 1;
for(i=0;i<8;i++)
{
j = disp[x][7-i];
P2 = tab[j];
P1 = ~scan;
delay(1);
scan<<=1;
P1 = 0xff;
delay(1);
}
}
}
void delay(unsigned int t)
{
int i,j;
for(i=0;i<t;i++)
for(j=0;j<120;j++);
}