Home > other >  How to use timer 0 timing at the same time, and timer 1 calculate the baud rate?
How to use timer 0 timing at the same time, and timer 1 calculate the baud rate?

Time:12-01

Based on ds18b20 hc05 via bluetooth module to send data, but at the same time use timer 0 timer, timer 1 to calculate a serial port interrupt the baud rate seems doesn't work, do you have a great god gives directions?

# include & lt; Reg52. H>
# include & lt; Intrins. H>
# include "DS18B20. H"
# include "eeprom52. H"

Uchar bluetoothdata=https://bbs.csdn.net/topics/0;
Uchar disdata [2]={0};

Void InitUART (void)
{
SCON=0 x50;
PCON=0 x80;
ES=1;
PS=1;

TMOD=0 x21;

TH0=0 XDB;
TL0=0 XFF;

TH1=0 xfa;
TL1=TH1;

TR0=1;
ET0=0;

TR1=1;

EA=1;
}

Void SendOneByte (unsigned char dat)
{
SBUF=dat;
while(! TI);
TI=0;
}

Int main (void)
{
InitUART ();
while(1);
}

Void timer0 () interrupt 1
{
Static int count;
Int wendu, I;
TH0=0 XDB;
TL0=0 XFF;
count++;
If (count==100)
{
Count=0;
Wendu=ReadTemp1 ();
Disdata [0]=100/10 wendu % + '0';
Disdata [1]=wendu % 10 + '0';
for(i=0; i<2; I++)
{
SendOneByte (disdata [I]);
}
}
}

Void UARTInterrupt () interrupt 4
{
If (RI)
{
RI=0;
bluetoothdata=https://bbs.csdn.net/topics/SBUF;
SendOneByte (bluetoothdata);
}
}
  • Related