標(biāo)題: 單片機(jī)延時(shí)程序代碼 [打印本頁(yè)]

作者: liuqq    時(shí)間: 2015-5-22 01:14
標(biāo)題: 單片機(jī)延時(shí)程序代碼


#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit L1=P1^1;


void delay()
{
        uint x,y;
        for(x=100;x>0;x--)
        for(y=600;y>0;y--);


}
void delay();
void main()
{
    while(1)
    {
     L1=0;
          delay();
          L1=1;
          delay();
    }
}

//剛開(kāi)始宏定義搞錯(cuò)了,編譯不成功。哎寫(xiě)暈了。好了,今天任務(wù)完成。,寫(xiě)完了,做別的事去



作者: 電子愛(ài)好者life    時(shí)間: 2015-5-22 11:40
在main函數(shù)前寫(xiě)一個(gè)void delay();是在做函數(shù)聲明嗎?你的延時(shí)函數(shù)已經(jīng)寫(xiě)在主函數(shù)前了,就不用聲明了
作者: chuskyfree    時(shí)間: 2015-5-22 14:27
while(1)里可以直接取反L1=~L1;delay();




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1