標題: 51單片機計時程序與仿真電路圖程序 [打印本頁]

作者: abba    時間: 2020-11-26 15:22
標題: 51單片機計時程序與仿真電路圖程序

#include<reg51.h>
unsigned char  seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
//共陽極斷碼表
unsigned char num=0,count=0;
sbit K0=P3^2;
sbit K1=P3^3;
int i=0;
void dis_play();
void intittimer();

void main()
{
   intittimer();
   while(1)
   {
      dis_play();
   }
}

void intittimer()
{
  TMOD=0x01;            
  TH0=(65536-50000)/256;  //50ms=50000us  
  TL0=(65536-50000)%256;
  ET0=1;                 
  EA=1;
  TR0=0;
  IT0=1;
  EX0=1;
  IT1=1;
  EX1=1;                  
}

void dis_play()
{  
  if(num==100)
  {
    num=0;
  }
  P2=seg[num/10];
  P1=seg[num%10];
}
void a() interrupt 0
{
   TR0=~TR0;
   num=num;
}
void b()interrupt 2
{
  TR0=0;
  num=0;
}

void timer_isr()  interrupt 1
{
  TH0=(65536-50000)/256;  //50ms=50000us  256=2^8  初值>>8
  TL0=(65536-50000)%256;
  count++;
  if(count==20)
  {
     num++;
     count=0;
  }
}

秒表.zip (36.84 KB, 下載次數(shù): 10)






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