定時器控制數碼管2011.1.24

//1.利用定時器、計數器T1產生定時時鐘,由P1口控制8個發光二極管,使8個指示燈依次一次一次閃動,閃動頻率爲10次/秒,循環
//2.用定時器以間隔500ms在6位數碼管依次顯示0,1,2,3,。。。C,D,E,F,重複
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
sbit DULA=P2^6;
sbit WELA=P2^7;
uchar num=0;
uchar temp=0xfe;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
//void display1();
void display2();

void main()
{
     TH1=(65536-50000)/256;
     TL1=(65535-50000)%256;
     EA=1;
     ET1=1;
     TMOD=0X10;
     TR1=1;

  //   display1();

display2();
}


void timer1() interrupt 3              //將該函數寫簡單更能提高系統機能
{

     TH1=(65536-50000)/256;
     TL1=(65535-50000)%256;

     num++;

}
/*
void display1()
{
     while(1)
     {
          if(num==2000)
          {
             num=0;
             P1=temp;
             temp=_crol_(temp,1);

          }
     }


}
*/

void display2()            //unchar 不能寫在WELA=0後
{     uchar n;                 

      WELA=1;
      P0=0XC0;
      WELA=0;
     
     
      while(1)
      {
           for(n=0;n<16;)
           {
               if(num==10)
               {  
                  num=0;
                  DULA=1;
                  P0=table[n]; 
                  DULA=0;
                  n++;
                } 
           }
      }


}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章