Home > other >  Stc89c52 serial port to send questions, quick tortured mad, for the great spirit guide
Stc89c52 serial port to send questions, quick tortured mad, for the great spirit guide

Time:09-17

Program aims to a serial port to transmit abcde - string, use a timer 2 do baud rate generator, the source code is as follows:
# include
# define uchar unsigned char
# define uint unsigned int
SFR T2MOD=0 xc9;

Bit aaaaaaaaa=1, BBBBBBBBB=1, CCCCCCCC=1, DDDDDDDDDD=1, eeeeeeeeeeee=1, FFFFFFFF=1, GGGGGGGG=1, HHHHHHHH=1, iiiiiii=1, JJJJJJJJJJ=1, KKKKKKKKKKK=1;
//bit a=1, b=1, c=1, d=1, e=1, f=1, g=1, h=1, I=1, j=1, k=1;

Void send_words (STR) uchar * {
While (* STR!='\ 0') {
SBUF=* STR;
str++;
while(! TI);
TI=0;
}
}
Void main ()
{
SCON=0 x50;
PCON=0 x00;
T2MOD=0 x01;
T2CON=0 x30;
TH2=RCAP2H=0 XFF;//9600 baud rate, 11.0592 Mhz crystal vibration
TL2=RCAP2L=0 XDC;
TR2=ES=1;
EA=1;
While (1) {
Send_words (" abcd - ");
}
}


Source defined in the bit variable is not used, but I don't know why will affect the program is running, the first and second lines bit variable is 11, there are two problems:

Question 1, if the commented line 1 a variable defined by 2 lines a variable definition, the program runs the results are as follows: serial port will first receive an a character at a time, after about 3 seconds to output a heap of abcd -, the first a and abcd - together, that is the first time only one output a, BCD - no,

Question 2, line 2 if commented a variable definitions left line 1 a variable definition, the program runs the results are as follows: a serial port only received an a character is no reaction,
So it was very strange, don't define variables of English letters length and programs also have relationship?

After the two lines of bit variables are commented out, it looks like normal, very don't understand, how these variables affect the serial port
  • Related