??? 09/16/07 09:03 Read: times |
#144661 - RS-485 code Responding to: ???'s previous message |
Hi all
Just deciding using RS-485 fullduplex with mode 3 serial port(multiprocessor) The AT89S52 or DS89C450 as slave processor $INCLUDE (reg_c51.INC) echo BIT 20H; echo enable bit TxOK BIT 21H; software flag org 000h ljmp begin org 23h ljmp serial_IT /** * FUNCTION_PURPOSE: This file set up uart in mode 3 (9 bits uart) with * timer 1 in baud rate generator mode. * FUNCTION_INPUTS: void * FUNCTION_OUTPUTS: void */ org 0100h begin: MOV SCON, #0F0h; /* uart in mode 3 (9 bit), REN=1 */ MOV SADDR,#03h; /* local address */ MOV SADEN,#0FFh; /* address mask */ ORL TMOD, #20h; /* Timer 1 in mode 2 */ MOV TH1, #0FDh; /* 9600 Bds at 11.059MHz */ MOV TL1, #0FDh; /* 9600 Bds at 11.059MHz */ SETB ES; /* Enable serial interrupt*/ SETB EA; /* Enable global interrupt */ SETB TR1; /* Timer 1 run */ loop: JNB echo,$; /* wait data to echo */ CLR echo ; /* disable echo */ SETB TB8; /* address mode */ SETB TxOK; /* set software flag */ MOV SBUF,#01h; /* send master adress */ JB TxOK,$; /* wait the stop bit transmition */ CLR TB8; /* data mode */ SETB TxOK; /* set software flag */ MOV SBUF,A; /* send data */ JB TxOK,$; /* wait the stop bit transmition */ LJMP loop ;/** ; * FUNCTION_PURPOSE: serial interrupt, echo receive data to master ; * FUNCTION_INPUTS: P3.0(RXD) serial input ; * FUNCTION_OUTPUTS: none ; */ serial_IT: JNB TI,END_Test_TI; /* if reception occur */ CLR TI; /* clear transmition flag for next transmition */ CLR TxOK; /* clear software transmition flag */ END_Test_TI: JNB RI,END_Test_RI; /* test if it is a reception */ CLR RI; /* clear reception flag for next reception */ JNB RB8,address_mode CLR SM2; /* go into data mode */ LJMP END_Test_RB8 address_mode: MOV A,SBUF; /* Read receive data */ SETB SM2; /* return into address mode after receive data */ SETB echo END_Test_RB8: END_Test_RI: RETI end from Atmel uart application note Is the code above for fullduplex slave? Thank's JBJ |