2.11 数码管显示(HC138/HC164)

相关下载:KEIL原工程

程序:

  1 //--------------------------------------------------------------------------
2 //来源: http://hi.baidu.com/mculove/home
3 //程序名称: 数码管显示(HC138/HC164)
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-{EX4}-(VCC)
26 //EBVn-[P35] -> MVn-{EX3}-[A]
27 //EBVn-[P36] -> MVn-{EX3}-[B]
28 //EBVn-[P37] -> MVn-{EX3}-[C]
29 //EBVn-[P32] -> MVn-{EX4}-[DA]
30 //EBVn-[P33] -> MVn-{EX4}-[CK]
31 //EBVn-[P34] -> MVn-{EX4}-[nRS]
32 //--------------------------------------------------------------------------
33
34
35 //------------------------------------------------------
36 //头文件;
37 #include <AT89X52.H>
38
39 #define HC138_A P3_5
40 #define HC138_B P3_6
41 #define HC138_C P3_7
42
43 #define HC164_DA P3_2
44 #define HC164_CK P3_3
45 #define HC164_nRA P3_4
46
47 const unsigned char Segment[10] = {
48 0x3f,
49 0x06,
50 0x5b,
51 0x4f,
52 0x66,
53 0x6d,
54 0x7d,
55 0x07,
56 0x7f,
57 0x6f
58 };
59
60 //------------------------------------------------------
61 //函数名:延时程序;
62 void delay(void)
63 {
64 unsigned int i;
65 for(i = 300;i > 0;i--);
66
67 }
68
69 //------------------------------------------------------
70 //函数名:HC164驱动程序:
71 //输入参数:输出的数据
72 void HC164(unsigned char Data)
73 {
74 unsigned char i;
75 for(i = 0;i < 8;i++) //循环8次,将一字节数据输出
76 {
77 HC164_CK = 0; //HC164_CK时钟脚低电平
78 if(Data & 0x80)HC164_DA = 1;//HC164_DA数据脚输出数据
79 else HC164_DA = 0;
80 HC164_CK = 1; //HC164_CK时钟脚高电平
81 Data <<= 1; //数据寄存器移位
82 }
83 }
84
85 //------------------------------------------------------
86 //函数名:程序入口;
87 void main(void)
88 {
89 while(1)
90 {
91 HC164_nRA = 0; //禁止HC573输出,熄灭数码管
92 HC164_nRA = 1;
93 HC138_A = 0;HC138_B = 0;HC138_C = 0;//选择第H1数码管位置
94 HC164(Segment[7]); //将数码管0的码数输出
95 delay(); //延时
96
97 HC164_nRA = 0; //禁止HC573输出,熄灭数码管
98 HC164_nRA = 1;
99 HC138_A = 1;HC138_B = 0;HC138_C = 0;//选择第H2数码管位置
100 HC164(Segment[6]); //将数码管1的码数输出
101 delay(); //延时
102
103 HC164_nRA = 0;
104 HC164_nRA = 1;
105 HC138_A = 0;HC138_B = 1;HC138_C = 0;
106 HC164(Segment[5]);
107 delay();
108
109 HC164_nRA = 0;
110 HC164_nRA = 1;
111 HC138_A = 1;HC138_B = 1;HC138_C = 0;
112 HC164(Segment[4]);
113 delay();
114
115 HC164_nRA = 0;
116 HC164_nRA = 1;
117 HC138_A = 0;HC138_B = 0;HC138_C = 1;
118 HC164(Segment[3]);
119 delay();
120
121 HC164_nRA = 0;
122 HC164_nRA = 1;
123 HC138_A = 1;HC138_B = 0;HC138_C = 1;
124 HC164(Segment[2]);
125 delay();
126
127 HC164_nRA = 0;
128 HC164_nRA = 1;
129 HC138_A = 0;HC138_B = 1;HC138_C = 1;
130 HC164(Segment[1]);
131 delay();
132
133 HC164_nRA = 0;
134 HC164_nRA = 1;
135 HC138_A = 1;HC138_B = 1;HC138_C = 1;
136 HC164(Segment[0]);
137 delay();
138 }
139 }



DLED1副本

DLED1

posted on 2012-01-05 20:48  mculove  阅读(1311)  评论(0编辑  收藏  举报

导航