??? 04/04/09 22:14 Read: times |
#164335 - Give this a try... Responding to: ???'s previous message |
;Idea of how to send DMX-bytes at 250kBds and receive MIDI-bytes at ;31.25kBds at the same time. An AT89S52 is used at 24MHz clock speed. ;UART is running in Mode 1, which means that 1 start bit, 8 data bits ;and 1 stop bit is used. This is directly compatible with MIDI data ;transmission. DMX uses one additional stop bit, which is fabricated ;here by an additional delay. ;Timer 1 is used for the receiving clock, Timer 2 for the transmit clock. ;There are 128 DMX-bytes assumed to be sent as a string. These bytes ;are assumed to be sitting in indirect RAM of micro at addresses ;128...255. ;As up to about 80 MIDI-bytes might be received during the transmission ;of DMX-bytes, these MIDI-bytes are stored in RAM of micro at addresses ;32 up. ;The DMX transmission starts with a BREAK (>=88µsec), followed by a ;MARK (>=8µsec) and a START byte (=44µsec). Then, 128 DMX data bytes are ;transmitted. Between the individual DMX data bytes pauses are allowed, ;which can be used to poll the receive interrupt flag (RI). If set, the ;DMX transmission is halted and the received MIDI byte is saved in the ;RAM. Immediately afterwards the DMX transmission is continued. $NOMOD51 $INCLUDE (89s52.mcu) TEMP DATA 127 ORG 0 SJMP Start ORG 002BH Start: MOV AUXR,#00011001B ;AT89S52 specific status byte MOV SCON,#01010000B ;set UART to Mode 1 (1+8+1 bits) ORL TMOD,#00100000B ;set Timer 1 (Mode 2) MOV TH1,#254 ;31250 Bds at 24.000MHz MOV TL1,#254 ;= MIDI baud rate SETB TR1 ;start Timer 1 ANL T2CON,#11110000B ;set Timer 2 (16bit auto-reload) ORL T2CON,#00010000B ;Timer 2 for transmit clock MOV TH2,#255 ;initialize MOV TL2,#253 MOV RCAP2H,#255 ;250000 Bds at 24.000MHz MOV RCAP2L,#253 ;= DMX baud rate SETB TR2 ;start Timer 2 MOV R0,#128 ;Start address of DMX-bytes to ;be sent. MOV R1,#32 ;Start address of received MIDI- ;bytes. LCALL MIDI_receive ;Save MIDI-byte, if arrived. CLR TXD ;fabrication of BREAK MOV TEMP,#87 DJNZ TEMP,$ ;BREAK >= 88µsec SETB TXD ;fabrication of MARK MOV TEMP,#4 DJNZ TEMP,$ ;MARK >= 8µsec LCALL MIDI_receive ;Save MIDI-byte, if arrived. MOV SBUF,#0 ;send START-byte JNB TI,$ ;byte sent? CLR TI ;prepare UART for next sending MOV TEMP,#4 DJNZ TEMP,$ ;2 stop bits >= 8µsec LCALL MIDI_receive ;Save MIDI-byte, if arrived. DMX_send: MOV SBUF,@R0 ;send a DMX-byte waiting in RAM INC R0 ;prepare address of next DMX-byte JNB TI,$ ;byte sent? CLR TI ;prepare UART for next sending MOV TEMP,#3 DJNZ TEMP,$ ;2 stop bits >= 8µsec LCALL MIDI_receive ;Save MIDI-byte, if arrived. CJNE R0,#0,DMX_send ;all DMX-bytes sent? SJMP $ ;code snippet ends here MIDI_receive: JNB RI,End_call ;MIDI_byte received? CLR RI ;prepare UART for next receiving MOV @R1,SBUF ;store MIDI-byte in RAM INC R1 ;prepare address of next MIDI-byte End_call: RET END Kai |