#include <reg51.h>
//晶振11.0592MZH
//每次中斷誤測約為0.434微秒
unsinged char T = 0;
void InitTimer0(void)
{
TMOD = TMOD | 0x01;
TH0 = 0x0FC;
TL0 = 0x66;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void InitUART(void)
TMOD = TMOD | 0x20;
SCON = 0x50;
TH1 = 0xFD;
TL1 = TH1;
PCON = 0x00;
ES = 1;
TR1 = 1;
void SendOneByte(unsigned char c)
SBUF = c;
while(!TI);
TI = 0;
void main(void)
InitTimer0();
InitUART();
while(1);
void Timer0Interrupt(void) interrupt 1
if(T ==1000)
T = 0;
SendOneByte("k");//要傳送的資料
esle
T++;
void UARTInterrupt(void) interrupt 4
if(RI)
RI = 0;
//如果有接收資訊,在這加入。
else
#include <reg51.h>
//晶振11.0592MZH
//每次中斷誤測約為0.434微秒
unsinged char T = 0;
void InitTimer0(void)
{
TMOD = TMOD | 0x01;
TH0 = 0x0FC;
TL0 = 0x66;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void InitUART(void)
{
TMOD = TMOD | 0x20;
SCON = 0x50;
TH1 = 0xFD;
TL1 = TH1;
PCON = 0x00;
EA = 1;
ES = 1;
TR1 = 1;
}
void SendOneByte(unsigned char c)
{
SBUF = c;
while(!TI);
TI = 0;
}
void main(void)
{
InitTimer0();
InitUART();
while(1);
}
void Timer0Interrupt(void) interrupt 1
{
TH0 = 0x0FC;
TL0 = 0x66;
if(T ==1000)
{
T = 0;
SendOneByte("k");//要傳送的資料
}
esle
{
T++;
}
}
void UARTInterrupt(void) interrupt 4
{
if(RI)
{
RI = 0;
//如果有接收資訊,在這加入。
}
else
TI = 0;
}