求助!我这个定时器T0时间怎么不对?
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar tt,numwei,numduan,temp,shi,ge,tt1,numwei1;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint z);
sbit duan=P2^6;
sbit wei=P2^7;
/*******初始化函数********/
void main()
{
tt=0;
/* tt1=0;*/
TMOD=0X01;
TH0=(65536-900)/256;
TL0=(65536-900)%256;
EA=1;
ET0=1;
TR0=1;
/* TMOD=0X10;
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
ET1=1;
TR1=1;*/
numwei=0x7f; //0111 1111
/* numwei1=0xbf; //1011 1111
/* temp=12;
shi=temp/10;
ge=temp%10; */
while(1);
}
void timer0() interrupt 1
{
TH0=(65536-900)/256;
TL0=(65536-900)%256;
tt++;
if(tt==2)
{
duan=1;
P1=table[1];
duan=0;
wei=1;
P1=numwei;
numwei=_cror_(numwei,1);
wei=0;
}
}
/*void timer1() interrupt 3
{
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
tt1++;
if(tt1==2)
{
duan=1;
P1=table[ge];
duan=0;
wei=1;
P1=numwei1;
numwei1=_cror_(numwei1,2);
wei=0;
tt1=0;
}
}*/
你应该用TMOD=0X11,而不是TMOD=0X10;然后再TMOD=0X01;,你试试行不行
谢谢你了,确实是的,第二次就把T0关掉了