MIKROPROCESORY i MIKROKONTROLERY Przykład oprogramowania protokołu komunikacyjnego dla łącza równoległego pomiędzy procesorem master i wieloma procesorami slave Założenia projektu (widziane od strony slave ) szyny adresów i danych: 8 linii portu P0 sygnały odbierane: INT0 = address strobe, INT1=data strobe, R/W=kierunek przesyłu danych, sygnał wysyłany: ACK potwierdzenie odbioru/ wysłania bajtu adres (numer) procesora slave 5-cio bitowy, uzupełniony dodatkowymi informacjami na MSB (most significant bits), które zapowiadają jeden z czterech typów dialogu: czytanie krótkie, czytanie długie, pisanie krótkie i długie. Czytanie i pisanie długie wymaga zawsze odebrania dodatkowego byte adresowego (jako pierwszego bajtu danych adresowanego do wybranego już slave ) Poniżej pokazane są czasowe przebiegi i relacje sygnałów na liniach adresów/danych oraz na liniach sterujących, pobrane z analizatora stanów logicznych
==================================================================== DEFINITIONS ================================================================= STACK DATA 0E0H FLAGS DATA 22H S B R bits (S=1 set) (B=1 data for board, =0 chan) SETF BIT 22H.7 BFLAG BIT 22H.6 SYGNA DATA 23H FIRST BIT 23H.0 MASK DATA 2DH M_CH0 BIT 2DH.0 M_CH1 BIT 2DH.1 M_CH2 BIT 2DH.2 M_CH3 BIT 2DH.3 M_CH4 BIT 2DH.4 M_CH5 BIT 2DH.5 M_CH6 BIT 2DH.6 M_CH7 BIT 2DH.7
STAT_B DATA 2FH BUSY BIT 2FH.6 BUFCIO DATA 030H 2-BYTE bufin for read command CCODE DATA 031H B_ID DATA 040H board reads it from hardware position QUECH DATA 041H circulating bit ACTIVE DATA 042H bits set for actually powered channels CHAON DATA 043H channels waiting for ON CNB DATA 044H byte count - serial transport HANDY DATA 045H CH2RD DATA 046H Channel to report LASTON DATA 047H counts ticks before next channel is on NSETCH DATA 048H new settings for this channel - as integer 0-7 BSETCH DATA 049H " "... as bit position CZESTO DATA 04AH controls asking freq CLRBFS DATA 04BH channels recently OFF, buffers to be cleared BUFF DATA 050H for input +0 first word readin at DS - usually contains chan address in 765 +1 NBYTE +2 CCODE (for channel controler) +3 - +15 (+F) VREQH, VREQL, CT0H,CTOL,CT1H,CT1L,CT2H,CT2L,CT3H,CT3L,RCODE,ENDCODE ECOD DATA 05EH ENDCODE BUF0 DATA 060H channel brings measurements,for ch0 BUF1 DATA 070H for ch 1 BUF2 DATA 080H for ch 2 BUF3 DATA 090H for ch 3 BUF4 DATA 0A0H for ch 4 BUF5 DATA 0B0H for ch 5 BUF6 DATA 0C0H for ch 6 BUF7 DATA 0D0H for ch 7 R_W BIT P1.5 set = we reading what crate says BS BIT P2.5 IRQ BIT P2.6 ACK BIT P2.7 AST BIT P3.2 DST BIT P3.3 CSEG ORG 00H ------------------------------------------------------------------------------ AJMP start ----------------------------------------INTERRUPT SERVICES--------------- ORG 03H INT0 (IE0) ADRESS STROBE (AS) service AJMP asint ------------------------------------------------------------------------------ ORG 00BH TIMER0 interrupt service
AJMP tnul ------------------------------------------------------------------------------ ORG 013H INT1 (IE1) DATA STROBE service AJMP dsint ------------------------------------------------------------------------------ ORG 01BH TIMER1 interrupt service AJMP tone ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ ORG 70H ------------------------------------------------------------------------------ PARTS OF INTERRUPT SERVICES AND SUBROUTINES ------------------------------------------------------------------------------ asint: AS - for me? PUSH ACC SETB RS0 registers from bank1 CLR RS1 too much care? CLR EX1 to be quiet if AS not for this board CLR FIRST marks the beginning of the DATA chain CLR BS clock it in A,P0 brings S B R flags and BADDR SETB BS FLAGS,A ANL A,#1FH get board address part XRL A,B_ID compare with my ID JNZ asrtn NO CLR ACK YES A,FLAGS interpret flags ANL A,#0C0H S B only SETB EX1 enable following DATA STROBES JNB AST,$ SETB ACK protocol CJNE A,#00H,nomch R0,#BUFF monitor channel SJMP asrtn nomch: CJNE A,#40H,nomb R1,#STAT_B monitor board SJMP asrtn nomb: CJNE A,#80H,nostch R0,#BUFF set channel SETB BUSY nostch: SJMP CJNE asrtn A,#0C0H,asrtn R0,#MASK set board
asrtn: POP PSW ---------------------------------------------------------------------------- dsint: PUSH ACC PUSH B SETB RS0 Bank 1 CLR RS1 CLR BS JB R_W,sets ---crate controler READS data, ergo here writing to P0 P0,@R1 CLR ACK INC R1 JNB DST,$ SETB BS P0,#0FFH ready to read SJMP dsrtn sets: we are reading what CrateControl says @R0,P0 CLR ACK JB FIRST,dscdn prepare further reading JB BFLAG,dscdn or if board command already satisfied SETB FIRST to skip it later A,@R0 first data byte has chan address in 765 bits ANL A,#0F0H SWAP A RR A B,#10H MUL AB ADD A,#BUF0 R1,A for subsequent reading of given chan dscdn: INC R0 SETB BS JNB DST,$ dsrtn: SETB ACK POP PSW POP B ------------------------------------------------------------------ tnul: PUSH ACC SETB 0AH
A,LASTON JZ tn1 DEC LASTON tn1: TH0,#00H TL0,#00H POP PSW ------------------------------------------------------------------ tone: PUSH ACC A,CZESTO JZ ton1 DEC CZESTO ton1: POP PSW =================================================================== ======================================================INITIAL PART== start: zero: CLR SP,#STACK R0,#050H A @R0,A INC R0 clear buffers CJNE R0,#STACK+1,zero STAT_B,A clear board status P1,#00H funny port input A,P1 ANL A,#01FH B_ID,A 5-bit board identifier P0,#0FFH ready for input SETB EA interrupts allowed SETB EX0 from external 0 (always ON for AddressStrobe) SETB ET0 from TIMER0 SETB ET1 TIMER1 SETB ES serial port Tu miejsce na główny program... END