2

2 つのマイクロ コントローラー間の通信用のコードを作成しました。コントローラ 1 はコントローラ 2 に番号を送信し、送信の 8 ビット モードに入ります。番号が一致すると、コントローラ 2 も 8 ビット モードになります。コードはエラーや警告なしでコンパイルされていますが、それでも Proteus で出力が得られません。私はコードを投稿しています:

void resetTimer16();


void main()
{
unsigned char i;

i=0;

SCON=0x80;     // 9bit data mode 

TMOD=0x10; // 16bit timer mode

resetTimer16();

TR1=1;

while(1)
{
    if(i==0)
        SBUF=1; // send slave 1 id
    else
        {
            TMOD=0x20;      // move into 8 bit mode

            TH1=-12; // considering a baud rate of 2400 to achieve

            SBUF='U';

            TR1=1;
        }

    while(TI==0)
    {
        if(TF1==1)
        {
            if(i==0)
                resetTimer16();

            TF1=0;
        }
    }

    TI=0;

    i++;        

    if(i==2)
        break;
}

while(1);
 }


void resetTimer16()
{
TH1=0xff;
TL1=0xf4;
} 

コントローラー2(受信機コントローラー)

sbit rs=P2^4;
sbit en=P2^5;

void resetTimer16();
void sendDataLCD(unsigned char dataa);
void sendCommandLCD(unsigned char );
void delay();

void main()
{
unsigned char i,dataa;

i=0;
dataa=0;

SCON=0x90; // enabled receiving and 9bit mode

TMOD=0x20;

            sendCommandLCD(0x38);
        sendCommandLCD(0x0E);
        sendCommandLCD(0x01);
        sendCommandLCD(0x02);

resetTimer16();

while(1)
{
    while(RI==0)
    {
        if(TF1==1)
        {
            if(i==0)
                resetTimer16();

            dataa=1;
            TF1=0;
        }
    }
    RI=0;

    dataa=SBUF;

    if(dataa==1)
    {
        i=1;

        TMOD=0x10; // move into 8bit mode

        TH1=-12;

        TR1=1;
    }

    while(RI==0);

    RI=0;

    dataa=SBUF;


    if(dataa>0) // for testing purpose controler 1 is not sending data =0
    {   
        sendDataLCD(dataa);
    }

}
}

void resetTimer16()
{
TH1=0xff;
TL1=0xf4;
}

 void sendDataLCD(unsigned char dataa)
{
P1=dataa;

rs=1;

en=1;
delay();
en=0;
 }

void sendCommandLCD(unsigned char cmd)
 {
P1=cmd;

rs=0;

en=1;
delay();
en=0;
 }

void delay()
{
unsigned char i,j;

for(i=0;i<255;i++)
    for(j=0;j<255;j++)
    {}
}

問題を理解しようとしましたが失敗したため、ここで専門家に助けを求めています。よろしくお願いいたします。

よろしく

4

1 に答える 1