2.7 74HC138原理实验

相关下载:KEIL原工程 

 1 //--------------------------------------------------------------------------
2 //来源: http://hi.baidu.com/mculove/home
3 //程序名称: 74HC138原理实验
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-{EX2}-[L1]
17 //MVn-{EX3}-[Y1] -> MVn-{EX2}-[L2]
18 //MVn-{EX3}-[Y2] -> MVn-{EX2}-[L3]
19 //MVn-{EX3}-[Y3] -> MVn-{EX2}-[L4]
20 //MVn-{EX3}-[Y4] -> MVn-{EX2}-[L5]
21 //MVn-{EX3}-[Y5] -> MVn-{EX2}-[L6]
22 //MVn-{EX3}-[Y6] -> MVn-{EX2}-[L7]
23 //MVn-{EX3}-[Y7] -> MVn-{EX2}-[L8]
24 // -> MVn-{EX2}-(VCC)
25 // -> MVn-{EX3}-(VCC)
26
27 //EBVn-[P10] -> MVn-{EX3}-[A]
28 //EBVn-[P11] -> MVn-{EX3}-[B]
29 //EBVn-[P12] -> MVn-{EX3}-[C]
30 //EBVn-[P13] -> MVn-{EX3}-[G1]
31 //--------------------------------------------------------------------------
32
33
34
35
36 //--------------------------------------------------------------------------
37 //实验结果:
38 //控制74HC138的[A,B,C,G1]端口,使[Y0,Y1..Y7]输出预期的值,LED实现了流水灯显示
39 //--------------------------------------------------------------------------
40
41
42
43 //------------------------------------------------------
44 //头文件;
45 #include <AT89X52.H>
46
47 #define HC138_A P1_0
48 #define HC138_B P1_1
49 #define HC138_C P1_2
50 #define HC138_G1 P1_3
51
52 //------------------------------------------------------
53 //延时程序;
54 void delay(void)
55 {
56 unsigned char i,j; //定义变量i,j;
57 for(i = 0;i < 250;i++) //延时程序;
58 for(j = 0;j < 250;j++);
59 }
60
61
62 //------------------------------------------------------
63 //程序入口;
64 void main(void)
65 {
66 while(1)
67 {
68 HC138_G1 = 1; //HC138输出允许
69 HC138_A=0;HC138_B=0;HC138_C=0;//[CBA]值为000B,[Y7..Y0]值为00000001B,L1亮
70 delay(); //延时程序
71 HC138_A=1;HC138_B=0;HC138_C=0;//[CBA]值为001B,[Y7..Y0]值为00000010B,L2亮
72 delay();
73 HC138_A=0;HC138_B=1;HC138_C=0;//[CBA]值为010B,[Y7..Y0]值为00000100B,L3亮
74 delay();
75 HC138_A=1;HC138_B=1;HC138_C=0;//[CBA]值为011B,[Y7..Y0]值为00001000B,L4亮
76 delay();
77 HC138_A=0;HC138_B=0;HC138_C=1;//[CBA]值为100B,[Y7..Y0]值为00010000B,L5亮
78 delay();
79 HC138_A=1;HC138_B=0;HC138_C=1;//[CBA]值为101B,[Y7..Y0]值为00100000B,L6亮
80 delay();
81 HC138_A=0;HC138_B=1;HC138_C=1;//[CBA]值为110B,[Y7..Y0]值为01000000B,L7亮
82 delay();
83 HC138_A=1;HC138_B=1;HC138_C=1;//[CBA]值为111B,[Y7..Y0]值为10000000B,L8亮
84 delay();
85 HC138_G1 = 0; //HC138禁止输出,[Y7..Y0]高阻,L1..L8灭
86 delay();
87 }
88 }



 

 

HC138副本

HC138

posted on 2012-01-05 18:06  mculove  阅读(3070)  评论(0编辑  收藏  举报

导航