新人求指导!同时使用两个定时器,要如何设置
时间:10-02
整理:3721RD
点击:
同时使用两个定时器,要如何设置,我这样那里不对
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint time1,time2;
uchar a,b;
void yan(uint i)
{
uint j,k;
for(j=0;j<148;j++)
for(k=0;k<i;k++);
}
void Time0_Init() //定是200us
{
TMOD=0x12;
TH0=0x47;
TL0=0x47;
IE=0x82;
TR0=1;
}
void Time0_Int() interrupt 1
{
time1++;
if(time1==456)
{
time1=0;
a++;
if(a==100) a=0;
}
}
void Time1_Init() //定是200us
{
TMOD=0x12;
TH1=0xB7;
TL1=0xFF;
IE=0x88;
TR1=1;
}
void Time1_Int() interrupt 3
{
time2++;
TH1=0xB7;
TL1=0xFF;
if(time2==100)
{
time2=0;
b++;
if(b==100) b=0;
}
}
void main()
{
Time0_Init();
Time1_Init();
while(1)
{
P2=6;
P0=table[a/10];
yan(2);
P2=7;
P0=table[a%10];
yan(2);
P2=0;
P0=table[b/10];
yan(2);
P2=1;
P0=table[b%10];
yan(2);
}
}
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint time1,time2;
uchar a,b;
void yan(uint i)
{
uint j,k;
for(j=0;j<148;j++)
for(k=0;k<i;k++);
}
void Time0_Init() //定是200us
{
TMOD=0x12;
TH0=0x47;
TL0=0x47;
IE=0x82;
TR0=1;
}
void Time0_Int() interrupt 1
{
time1++;
if(time1==456)
{
time1=0;
a++;
if(a==100) a=0;
}
}
void Time1_Init() //定是200us
{
TMOD=0x12;
TH1=0xB7;
TL1=0xFF;
IE=0x88;
TR1=1;
}
void Time1_Int() interrupt 3
{
time2++;
TH1=0xB7;
TL1=0xFF;
if(time2==100)
{
time2=0;
b++;
if(b==100) b=0;
}
}
void main()
{
Time0_Init();
Time1_Init();
while(1)
{
P2=6;
P0=table[a/10];
yan(2);
P2=7;
P0=table[a%10];
yan(2);
P2=0;
P0=table[b/10];
yan(2);
P2=1;
P0=table[b%10];
yan(2);
}
}
定时器1的初值改成了20ms,