我的单片机世界第一盏灯

来源:互联网 发布:办公软件基础教程 编辑:程序博客网 时间:2024/05/16 17:33
#include<reg52.h>
sbit LED0 = P0^0; 
sbit LED1 = P0^1; 
sbit LED2 = P0^2; 
sbit LED3 = P0^3; 
sbit LED4 = P0^4; 
sbit LED5 = P0^5; 
sbit LED6 = P0^6; 
sbit LED7 = P0^7; 


void Delay(unsigned int n)
{
unsigned int i = 0,j = 0;
for(i = n;i > 0;i--)
{
   for(j = n/2;j > 0; j--)
{}
}
}




void main()
{
    while(1)
{
   LED0 = 0; 
Delay(500); 
LED2 = 0;
Delay(500);
LED4 = 0;
Delay(500);
LED6 = 0;
Delay(500);


        LED7 = 0; 
Delay(500); 
LED5 = 0;
Delay(500);
LED3 = 0;
Delay(500);
LED1 = 0;
Delay(500);


LED0 = 1;
Delay(500);
LED2 = 1;
Delay(500);
LED4 = 1;
Delay(500);
LED6 = 1;
Delay(500);

LED7 = 1; 
Delay(500); 
LED5 = 1;
Delay(500);
LED3 = 1;
Delay(500);
LED1 = 1;
Delay(500);
}
}
0 0
原创粉丝点击