2.2 8个LED实现流水灯

相关下载:KEIL原工程

实验效果:8个LED实现流水灯显示

 

 1 //--------------------------------------------------------------------------
2 //程序名称: 8个LED实现流水灯;
3 //晶振: 11.0592MHz;
4 //MCU型号: STC89C52RC;
5 //电路板型号: EBV-MV(51实验板)
6 //--------------------------------------------------------------------------
7 //--------------------------------------------------------------------------
8 //硬件连接:
9 //EBVn-[VCC] -> MVn-[--VCC--]
10 //EBVn-[GND] -> MVn-[//GND//]
11 //EBVn-[P10] -> MVn-{EX2}-[L1]
12 //EBVn-[P11] -> MVn-{EX2}-[L2]
13 //EBVn-[P12] -> MVn-{EX2}-[L3]
14 //EBVn-[P13] -> MVn-{EX2}-[L4]
15 //EBVn-[P14] -> MVn-{EX2}-[L5]
16 //EBVn-[P15] -> MVn-{EX2}-[L6]
17 //EBVn-[P16] -> MVn-{EX2}-[L7]
18 //EBVn-[P17] -> MVn-{EX2}-[L8]
19 // -> MVn-{EX2}-(VCC)
20 //--------------------------------------------------------------------------
21 //------------------------------------------------------
22 //头文件;
23 #include <AT89X52.H>
24 //------------------------------------------------------
25 //延时程序;
26 void delay(void)
27 {
28 unsigned char i,j; //定义变量i,j;
29 for(i = 0;i < 250;i++) //延时程序;
30 for(j = 0;j < 250;j++);
31 }
32 //------------------------------------------------------
33 //程序入口;
34 void main(void)
35 {
36 while(1)
37 {
38 P1 = ~0x01; //P1=B1111 1110即P10低电平
39 delay(); //调用延时程序;
40 P1 = ~0x02; //P1=B1111 1101即P11低电平
41 delay(); //调用延时程序;
42 P1 = ~0x04; //P1=B1111 1011即P12低电平
43 delay(); //调用延时程序;
44 P1 = ~0x08; //P1=B1111 0111即P13低电平
45 delay(); //调用延时程序;
46 P1 = ~0x10; //P1=B1110 1111即P14低电平
47 delay(); //调用延时程序;
48 P1 = ~0x20; //P1=B1101 1111即P15低电平
49 delay(); //调用延时程序;
50 P1 = ~0x40; //P1=B1011 1111即P16低电平
51 delay(); //调用延时程序;
52 P1 = ~0x80; //P1=B0111 1111即P17低电平
53 delay(); //调用延时程序;
54 }
55 }



原理图副本

MCU实验板

posted on 2012-01-04 23:29  mculove  阅读(2272)  评论(0编辑  收藏  举报

导航