2.10 数码管显示(HC138/HC573)
相关下载:KEIL原工程
程序:
1 //--------------------------------------------------------------------------
2 //来源: http://hi.baidu.com/mculove/home
3 //程序名称: 数码管显示(HC138/HC573)
4 //晶振: 11.0592MHz;
5 //MCU型号: STC89C52RC;
6 //电路板型号: EBV-MV(51实验板);
7 //--------------------------------------------------------------------------
8
9
10
11
12 //--------------------------------------------------------------------------
13 //硬件连接:
14 //EBVn-[VCC] -> MVn-[--VCC--]
15 //EBVn-[GND] -> MVn-[//GND//]
16 //MVn-{EX3}-[Y0] -> MVn-{EX1}-[H8]
17 //MVn-{EX3}-[Y1] -> MVn-{EX1}-[H7]
18 //MVn-{EX3}-[Y2] -> MVn-{EX1}-[H6]
19 //MVn-{EX3}-[Y3] -> MVn-{EX1}-[H5]
20 //MVn-{EX3}-[Y4] -> MVn-{EX1}-[H4]
21 //MVn-{EX3}-[Y5] -> MVn-{EX1}-[H3]
22 //MVn-{EX3}-[Y6] -> MVn-{EX1}-[H2]
23 //MVn-{EX3}-[Y7] -> MVn-{EX1}-[H1]
24 // -> MVn-{EX3}-(VCC)
25 // -> MVn-{EX7}-(VCC)
26
27 //EBVn-[P35] -> MVn-{EX3}-[A]
28 //EBVn-[P36] -> MVn-{EX3}-[B]
29 //EBVn-[P37] -> MVn-{EX3}-[C]
30
31 //EBVn-[P10] -> MVn-{EX7}-[D0]
32 //EBVn-[P11] -> MVn-{EX7}-[D1]
33 //EBVn-[P12] -> MVn-{EX7}-[D2]
34 //EBVn-[P13] -> MVn-{EX7}-[D3]
35 //EBVn-[P14] -> MVn-{EX7}-[D4]
36 //EBVn-[P15] -> MVn-{EX7}-[D5]
37 //EBVn-[P16] -> MVn-{EX7}-[D6]
38 //EBVn-[P17] -> MVn-{EX7}-[D7]
39 //EBVn-[P33] -> MVn-{EX7}-[LE]
40 //EBVn-[P34] -> MVn-{EX7}-[nOE]
41 //--------------------------------------------------------------------------
42
43
44
45
46 //--------------------------------------------------------------------------
47 //实验结果:
48 //
49 //--------------------------------------------------------------------------
50
51
52
53
54
55
56 //------------------------------------------------------
57 //头文件;
58 #include <AT89X52.H>
59
60 #define HC138_A P3_5
61 #define HC138_B P3_6
62 #define HC138_C P3_7
63
64 #define HC573_LE P3_4
65 #define HC573_nOE P3_3
66
67 const unsigned char Segment[10] = {
68 0x3f, //数码管显示数0
69 0x06, //数码管显示数1
70 0x5b, //...
71 0x4f,
72 0x66,
73 0x6d,
74 0x7d,
75 0x07,
76 0x7f,
77 0x6f //数码管显示数9
78 };
79
80 //------------------------------------------------------
81 //函数名:延时程序;
82 void delay(void)
83 {
84 unsigned int i;
85 for(i = 300;i > 0;i--);
86
87 }
88
89
90
91 //------------------------------------------------------
92 //函数名:程序入口;
93 void main(void)
94 {
95 HC573_nOE = 0;
96 HC573_LE = 1; //HC573允许输出
97 while(1)
98 {
99 HC573_nOE = 1; //禁止HC573输出,熄灭数码管
100 HC138_A=0;HC138_B=0;HC138_C=0;//选择第H1数码管位置
101 P1 = Segment[0]; //将数码管0的码数输出
102 HC573_nOE = 0; //允许HC573输出,点亮数码管
103 delay(); //延时
104 HC573_nOE = 1; //禁止HC573输出,熄灭数码管
105 HC138_A=1;HC138_B=0;HC138_C=0;//选择第H2数码管位置
106 P1 = Segment[1]; //将数码管1的码数输出
107 HC573_nOE = 0; //允许HC573输出,点亮数码管
108 delay(); //延时
109 HC573_nOE = 1; //...以下同上
110 HC138_A=0;HC138_B=1;HC138_C=0;
111 P1 = Segment[2];
112 HC573_nOE = 0;
113 delay();
114 HC573_nOE = 1;
115 HC138_A = 1;HC138_B=1;HC138_C = 0;
116 P1 = Segment[3];
117 HC573_nOE = 0;
118 delay();
119 HC573_nOE = 1;
120 HC138_A = 0;HC138_B = 0;HC138_C = 1;
121 P1 = Segment[4];
122 HC573_nOE = 0;
123 delay();
124 HC573_nOE = 1;
125 HC138_A = 1;HC138_B = 0;HC138_C = 1;
126 P1 = Segment[5];
127 HC573_nOE = 0;
128 delay();
129 HC573_nOE = 1;
130 HC138_A = 0;HC138_B = 1;HC138_C = 1;
131 P1 = Segment[6];
132 HC573_nOE = 0;
133 delay();
134 HC573_nOE = 1;
135 HC138_A = 1;HC138_B = 1;HC138_C = 1;
136 P1 = Segment[7];
137 HC573_nOE = 0;
138 delay();
139 }
140 }