void Time_Init(unsigned char register_Position,unsigned char register_Mode,unsigned char use_Mode,
unsigned char THx,unsigned char TLx,
unsigned char interrupt_Enable,unsigned char interrupt_Grade)
{
TMOD=0x00;
TCON=0x00;
if(register_Position==1) //Time1
{
if(register_Mode==0){TMOD = TMOD||0x00;}
else if(register_Mode==1){TMOD = TMOD||0x04;}
if(use_Mode==0){TMOD = TMOD||0x00;TH0=THx;TL0=TLx;}
else if(use_Mode==1){TMOD = TMOD||0x01;TH0=THx;TL0=TLx;}
else if(use_Mode==2){TMOD = TMOD||0x02;TH0=THx;TL0=TLx;}
else if(use_Mode==3){TMOD = TMOD||0x03;TH0=THx;TL0=TLx;}
if(interrupt_Enable==0){ET1==0;}
else if(interrupt_Enable==1){ET1==1;}
TR1=1;
}
else if(register_Position==0) //Time0
{
if(register_Mode==0){TMOD = TMOD||0x00;}
else if(register_Mode==1){TMOD = TMOD||0x40;}
if(use_Mode==0){TMOD = TMOD||0x00;0x01;TH1=THx;TL1=TLx;}
else if(use_Mode==1){TMOD = TMOD||0x01;TH1=THx;TL1=TLx;}
else if(use_Mode==2){TMOD = TMOD||0x02;TH1=THx;TL1=TLx;}
else if(use_Mode==3){TMOD = TMOD||0x03;TH1=THx;TL1=TLx;}
if(interrupt_Enable==0){ET0==0;}
else if(interrupt_Enable==1){ET0==1;}
TR0=1;
}
else
{
TMOD=0x00;
}
EA=1;
}
/*
外部中断0:中断号为0;
定时器0:中断号为1;
外部中断1:中断号为2;
定时器1:中断号为3;
void Timex_Suspend() interrupt 3
{
}
*/
void main()
{
Time_Init(0,0,1,(65535-1000)/256,(65535-1000)%256,1,0);
//此函数结果TMOD=00000001 TCON=00110000
while(1)
{
P2=TMOD;
P1=TCON;
}
}
void Timex_Suspend() interrupt 1
{
P0=~P0;
P3=0x00;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
}
|