|
#include <reg52.h>
#define PLV 11059200UL
#define BAND_9600 9600UL
sbit LED = P1^5;
#define uchar unsigned char
uchar Data[]="a";
uchar *p;
bit flag = 0;
void sendData()
{
p=Data;
while(*p != '\0')
{
SBUF = *p;
while(!TI);
TI=0;
p++;
}
}
void sendInt(int i)
{
SBUF = i/256;
while(!TI);
TI=0;
SBUF = i%256;
while(!TI);
TI=0;
}
void main()
{
unsigned int i = 0x3522;
int b = 455;
TMOD &=0x0f;
TMOD |=0x20;
SCON =0x50;
//band =x/ 16 () band = x/32
//x= plv/12/(256-yh1)
//so:
TH1=256- PLV/(12*BAND_9600*16*2);
TL1=256-PLV/(12*BAND_9600*16*2);
//PCON |=0x80;
ES=1;
TR1=1;
// REN=1;//SCONÖвÙ×÷¹ýÁË¡£¡£¡£
EA=1;
sendInt(b);
while(1)
{
if(flag) {sendData();flag=0;}
}
}
void uart(void) interrupt 4
{unsigned char buff;
if(RI)
{
flag = 1;
buff = SBUF;
if (buff == 0x00)
LED=1;
else if(buff == 0xaa)
LED=0;
RI=0;
}
}
|
評(píng)分
-
查看全部評(píng)分
|