The serial data can be sent through the RS-232 via pc or through bluetooth module
source code:
#include<reg51.h>
sbit load=P0^1;
sbit led =P0^0;
void initserial();
//void sendserial();
unsigned char receiveserial();
unsigned char mydata;
void delay();
void main()
{
initserial();
while(1)
{
led = 0;
mydata=receiveserial();
//sendserial(mydata);
delay();
if(mydata=='0')
load=0;
else
load=1;
}
}
void initserial()
{
TMOD=0X21;
TL1=253;
TH1=253;
SCON=0X50;
TR1=1;
}
unsigned char receiveserial()
{
while(RI==0);
mydata=SBUF;
RI=0;
return mydata;
}
//void sendserial(unsigned char dat)
//{
//TI=0;
//SBUF = dat;
//while(TI==0);
//}
void delay()
{
TL0=0xFF;
TH0=0x67;
TR0=1;
TF0=0;
while(TF0==0);
}
No comments:
Post a Comment