2.8 74HC164原理实验

相关下载:KEIL原工程

 

 1 //--------------------------------------------------------------------------
2 //来源: http://hi.baidu.com/mculove/home
3 //程序名称: 74HC164原理实验
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-{EX4}-[Q0] -> MVn-{EX2}-[L1]
17 //MVn-{EX4}-[Q1] -> MVn-{EX2}-[L2]
18 //MVn-{EX4}-[Q2] -> MVn-{EX2}-[L3]
19 //MVn-{EX4}-[Q3] -> MVn-{EX2}-[L4]
20 //MVn-{EX4}-[Q4] -> MVn-{EX2}-[L5]
21 //MVn-{EX4}-[Q5] -> MVn-{EX2}-[L6]
22 //MVn-{EX4}-[Q6] -> MVn-{EX2}-[L7]
23 //MVn-{EX4}-[Q7] -> MVn-{EX2}-[L8]
24 // -> MVn-{EX2}-(VCC)
25 // -> MVn-{EX4}-(VCC)
26 //EBVn-[P10] -> MVn-{EX4}-[DA]
27 //EBVn-[P11] -> MVn-{EX4}-[CK]
28 //EBVn-[P12] -> MVn-{EX4}-[nRS]
29 //--------------------------------------------------------------------------
30
31
32
33
34 //--------------------------------------------------------------------------
35 //实验结果:
36 //控制74HC164的[DA,CK,nRS]端口,使[Q0,Q1..Q7]输出预期的值,LED实现了流水灯显示
37 //--------------------------------------------------------------------------
38 //------------------------------------------------------
39 //头文件;
40 #include <AT89X52.H>
41
42 #define HC164_DA P1_0
43 #define HC164_CK P1_1
44 #define HC164_nRA P1_2
45
46
47 //------------------------------------------------------
48 //函数名:延时程序;
49 void delay(void)
50 {
51 unsigned char i,j; //定义变量i,j;
52 for(i = 0;i < 250;i++) //延时程序;
53 for(j = 0;j < 250;j++);
54 }
55
56
57 //------------------------------------------------------
58 //函数名:HC164驱动程序:
59 //输入参数:输出的数据
60 void HC164(unsigned char Data)
61 {
62 unsigned char i;
63 for(i = 0;i < 8;i++) //循环8次,将一字节数据输出
64 {
65 HC164_CK = 0; //HC164_CK时钟脚低电平
66 if(Data & 0x80)HC164_DA = 1; //HC164_DA数据脚输出数据
67 else HC164_DA = 0;
68 HC164_CK = 1; //HC164_CK时钟脚高电平
69 Data <<= 1; //数据寄存器移位
70 }
71 }
72
73 //------------------------------------------------------
74 //函数名:程序入口;
75 void main(void)
76 {
77 HC164_nRA = 1;
78 while(1)
79 {
80 HC164(~0x01); //将11111110B赋值到HC164输出,使L1亮
81 delay(); //延时程序
82 HC164(~0x02); //将11111101B赋值到HC164输出,使L2亮
83 delay();
84 HC164(~0x04); //将11111011B赋值到HC164输出,使L3亮
85 delay();
86 HC164(~0x08); //将11110111B赋值到HC164输出,使L4亮
87 delay();
88 HC164(~0x10); //将11101111B赋值到HC164输出,使L5亮
89 delay();
90 HC164(~0x20); //将11011111B赋值到HC164输出,使L6亮
91 delay();
92 HC164(~0x40); //将10111111B赋值到HC164输出,使L7亮
93 delay();
94 HC164(~0x80); //将01111111B赋值到HC164输出,使L8亮
95 delay();
96 }
97 }

 

HC164副本

HC164

posted on 2012-01-05 19:08  mculove  阅读(6940)  评论(0编辑  收藏  举报

导航