关于定时器的简单联系


 #include  
#include
sbit beep=P2^3;
sbit led1=P1^0;
#define uint unsigned int
#define uchar unsigned char
uint  num,count;
uchar m=0xfe , val=0,flag=0;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uint code table1[]={1000,100,50,20,10,5,2,1};
void delay(unsigned int x)
{
 unsigned int i,j;
 for(i=x;i>0;i--)
  for(j=110;j>0;j--);
}
void display(uchar bai,uchar shi,uchar ge)
{
 P0=0xfe;
 wela=1;
 wela=0;
 P0=table[bai];
 dula=1;
 dula=0;
 delay(5);

 P0=0xfd;
 wela=1;
 wela=0;
 P0=table[shi];
 dula=1;
 dula=0;
 delay(5);

 P0=0xfb;
 wela=1;
 wela=0;
 P0=table[ge];
 dula=1;
 dula=0;
 delay(5);
  }

void main()
{
 EA=1;
 TMOD=0x11;
 ET1=1;
 TH1=(65535-50000)/256;
 TL1=(65535-50000)%256;
 
 ET0=1;
 TH0=(65535-1000)/256;
 TL0=(65535-1000)%256;
 TR1=1;
// TR0=1;
 while(1);

}
void time1() interrupt 3
{
 TH1=(65535-50000)/256;
 TL1=(65535-50000)%256;
 num++;
 if(num==40)
 {
  num=0;
 
  beep=0;
  
   
    TR0=1;

 }


}
void time0() interrupt 1
{

 TH0=(65535-1000)/256;
 TL0=(65535-1000)%256;
 count++;
 if(count==table1[val])
 {
  val=val+1;
  count=0 ;
  beep=1;
  flag=1;
  if(val==8)
   val=0;
 
  TR1=1;
  TR0=0;


 }

  }

 

你可能感兴趣的:(c51)