Question

The Program Cannot Operate at STC89C52RC

By ling1995 ·
I bought STC89C52RC from Kynix ( http://www.kynix.com ) . I am using bluetooth module to communicate and develop Learning board. The board can work as well as the MCU. Burning also is successful. When I anolog simulation using KEIL,the smartphone can get the word “success”. When I change the RXD to be MCU’s RTXD and TXD to be MCU’s RXD, however, there are no any data when simulating. Why?
The program is given below:
#include "reg52.h"
#include "intrins.h"

unsigned char SenData,Flag;

char code str1[]="Success";
char code str2[]="Error";

void send_str();
void InitUART(void);
void send_str2();
void delayms(unsigned char ms);
void send_char(unsigned char txd);

void InitUART(void)
{
/*******************set the serial port **********************/
SCON=0x50;                        // the working way set to be way1.
TMOD=0x20;                        //the working way of counter set to be way2
PCON =0x80;                        //Baud rate double
TH1=0xFA;                                //Counter initial value is set, the attention is 9600 baud rate
TL1=TH1;
ES=1;                                                //Open to receive interrupt
EA=1;                                                /Open the total interruption
TR1=1;                                        //Open counter
/******************interruption set**********************/
}
void main()  //main function
{        
InitUART();
while(1){ 
if(Flag==1)
{
ES = 0;
delayms(50);
//----------------------This is to deal with the received data
if(SenData==97)//97 is the character a的ascii
{
delayms(10);//delaying to shake
send_str();//send data
}
else
{
delayms(10);
send_str2();
}
Flag=0;//After the data processing will mark position 0, said there was no new data to be processed
}
ES = 1;
}
}

void ser_int()interrupt 4//receive character
{  

if(RI==1)//RI receive the signal of interruption
{ 
SenData = SBUF ;
RI=0;//clear signal
Flag =1;//Logo position 1 said new data comes in
}
else
TI = 0;
}


void send_str()//Sends a string
{
unsigned char i=0;
while(str1!='\0')
{
SBUF =str1;
while(!TI);//waiting for data sending
TI=0;//Clear data transmission
i++;//Under a string
}
}

void send_str2()//send string
{
unsigned char i=0;
while(str2!='\0')
{
SBUF =str2;
while(!TI);//waiting for data sending
TI=0;//Clear data transmission
i++;//Under a string
}
}


void delayms( unsigned char ms)//Delay subroutine
{
unsigned char i;
while(ms--)
{
for(i=0;i<120;i++);
}
}

Thanks.
0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Hardware Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums