因仑“3+1”工程特种兵精英论坛

标题: 闪烁灯 [打印本页]

作者: 123321    时间: 2015-4-14 20:54
标题: 闪烁灯
#include "reg52.h"
//#define uchar unsigned char
//#define uint  unsigned int
sbit  P10=P1^0;
void mDelay(unsigned int Delay)
{  unsigned int i;
for(;Delay>0;Delay--)
{ for(i=0;i<124;i++)
  {;}
}
}

void main()
{ for(;;)
{ P10=!P10;  //取反 P1.0
  mDelay(1000); //延时1秒。如果是2000那么是2秒
}
}
#include<reg52.h>                 //库文件
#define uchar unsigned char//宏定义无符号字符型
#define uint unsigned int  //宏定义无符号整型
/********************************************************************
                            I/O定义
*********************************************************************/
sbit LED=P1^0;         //定义单片机P1口的第0位 (即P1.0)
/********************************************************************
                            延时函数
*********************************************************************/
void delay()//延时程序
{
uchar m,n,s;
for(m=20;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}
/********************************************************************
                            主函数
*********************************************************************/
void main()
{
        while(1)   //无限循环
        {
         LED=0;           //点亮P1.0口灯
         delay();  //延时
         LED=1;           //熄灭P1.0口灯
         delay();  //延时
        }
}       
/********************************************************************
                              结束
*********************************************************************/[attach]2265[/attach]






欢迎光临 因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/) Powered by Discuz! X3.4