標(biāo)題: 51單片機單燈計數(shù)1S [打印本頁]

作者: qq1357002447    時間: 2016-10-17 11:34
標(biāo)題: 51單片機單燈計數(shù)1S
單燈程序

include <reg51.h>       //51系列單片機頭文件
#define uint unsigned int //
#define uchar unsigned char
sbit led1=P1^0;
void delay1s()                       //1s延時函數(shù)-定時器5ms,循環(huán)200次
{   
   uchar i;                                                 //設(shè)置為字符型變量
  //TMOD=0x00;    //T0為工作方式0--M1M0=00
   for(i=0;i<0x14;i++)              //循環(huán)200次
   {
    TH0=(8192-5000)/32;              //延時50ms的初值—6318H
    TL0=(8192-5000)%32;      
    TR0=1;                                              //啟動T1
     while(!TF0);                                     //TF1由0變?yōu)?,定時時間到
     TF0=0;                                             //50ms定時時間到,將TF1清零
   }
}  

void main()
{ TMOD=0x00;
  while(1)
{ led1=~led1;
  delay1s();
  }
  }





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