|
- #include <reg51.h>
- #include <intrins.h>
- #define uchar unsigned char //无符号字符型
- void delay(unsigned int time) {
- int i, j;
- for (i = 0; i < time; i++)
- for (j = 0; j < 1275; j++);
- }
- void main()
- {
- uchar i ,temp;
- while(1)
- {
- temp=0xfe;
- for(i=0;i<7;i++)
- {
- P2=temp;
- delay(90);
- temp=_crol_(temp,1);
- }
- for(i=0;i<7;i++)
- {
- P2=temp;
- delay(90);
- temp=_cror_(temp,1);
- }
- }
-
- }
复制代码- #include <reg51.h>
- #define u8 unsigned char //无符号字符型
- #define u16 unsigned int
- void delay(unsigned int time) {
- int i, j;
- for (i = 0; i < time; i++)
- for (j = 0; j < 1275; j++);
- }
- void main() {
- char leds[8] = {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F};
- int i;
- while(1) {
- for (i = 0; i < 8; i++) {
- P2 = leds[i];
- delay(100); // 调用延时函数
- }
- }
- }
复制代码
|
|