数码管动态扫描显示方式
扫描二维码
随时随地手机看文章
数码管依次显示1-6,并保持造成视觉停留状态,也叫动态扫描显示
1#include
2#define uint unsigned int
3#define uchar unsigned char
4sbit dula=P2^6;
5sbit wela=P2^7;
6uchar timer,numwe,numdu; //timer定时器计数 temp数字临时存放
7//数字字码表 0-F 8uchar code table[]={
90x3f,0x06,0x5b,0x4f,
100x66,0x6d,0x7d,0x07,
110x7f,0x6f,0x77,0x7c,
120x39,0x5e,0x79,0x7113};
14uchar code we[]={
150xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F16};
17void init();
18void display();
19void main()
20{
21 init();
22 display();
23}
2425void init()
26{
27 TMOD=1;
28 TH0=0xFC;
29 TL0=0x66;
30 ET0=1;
31 EA=1;
32 TR0=1;
33}
34void display()
35{
36 wela=1;
37 P0=0xF8;
38 wela=0;
39 P0=0xFF;
40 dula=1;
41 P0=0x00;
42 dula=0;
43 numdu=1;
44while (1)
45 {
46if (timer==1)
47 {
48 timer=0;
49 wela=1;
50 P0=we[numwe];
51 wela=0;
52 P0=0xFF;
53 numwe++;
54if(numwe==6)
55 numwe=0;
5657 dula=1;
58 P0=table[numdu];
59 dula=0;
60 numdu++;
61if(numdu==7)
62 numdu=1;
63 P0=0xFF;
64 }
65 }
66}
67void delay() interrupt 168{
69 TH0=0xFC;
70 TL0=0x66;
71 timer++;
72}
73