tags:

views:

10

answers:

0

The strings` length is less than 30 but Variable. I use the following code, but the SComAssistant only can receive two Character.

=================================================================

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit lcden=P2^3;
sbit lcdrs=P2^4;
sbit lcdrw=P2^0;
uchar table[30]; 
uchar i, j, flag; 
uchar num;

void delay(uint z)
{
    uint x,y;
    for(x=z;x>0;x--)
        for(y=110;y>0;y--);
}
//串口初始化 
void serial_init() 
{ 
    TMOD = 0x20; 
    TH1 = 0xfd;     //9600赫兹 
    TL1 = 0xfd; 
    TR1 = 1;    //开启时间中断 
    SCON = 0x50;//方式2 
    SM2 = 1;    //可以向cpu请求中断 
    EA = 1;     //开总中断 
    ES = 1;     //开串口中断    
} 
void putchar( uchar ch )//发送数据 
{ 
    SBUF = ch; 
    while( !TI ); 
    TI = 0; 
} 
void main() 
{ 
    init(); 
    serial_init(); 
    while(1) 
    {    
        delay(20); 
        while(flag == 1) {
            while( table[j]!= '\0' ) 
            { 
                putchar( table[j] ); 
                j++; 
                delay(10); 
            } 
            flag = 0; 
        }
    } 
} 
void Serial() interrupt 4 
{ 
    if(RI == 0) return; 
    if(RI==1)
    {
        RI=0;
        ES=0;
        table[i] = SBUF; 
        i++; 

        delay(10); 
        ES=1;
        flag = 1; 
        delay(10); 
    }

}