赞
踩
- #include <reg52.h>
-
- int m;
- unsigned char code leds[8] = {0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe};
-
- void delay(unsigned int i)
- {
- unsigned int j;
- unsigned char k;
-
- for(j=i; j>0; j--)
- for(k=125; k>0 ;k--);
- }
-
- int main()
- {
- while(1)
- {
- for(m = 0; m < 8; m++)
- {
- P1 = leds[m];
- delay(500);
- }
- }
-
- return 0;
- }
使用
if语句实现led灯的控制,i类似于标志位控制进行循环转移
- i = 0;
- while(1)
- {
- P1 = leds[i++];
- delay(5000);
- if(i == 8) i = 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。