??? 08/24/04 18:26 Read: times |
#76355 - MIDI messages handling |
Hello!
I'm trying to implement a very basic MIDI repeater using a circular buffer for the incoming bytes. Somehow the buffer implementation or the way I handle the serial interrupts is wrong, because the program never transmitts anything. I have spend few hours to debug the program, but still cannot figure out what is wrong. I will be very gratefull if you can spare few minutes and give a clue where is the problem: #INCLUDE "8051EQU.INC" ;include predefined constants BUFFER .equ 40H BUFFER_SIZE .equ 12 ;************************************************************************** ; ; RESET ;reset routine .ORG 0H ;locate routine at 00H AJMP START ;jump to START ; ;************************************************************************** ; ; INTERRUPTS ;place interrupt routines at appropriate ; ;memory locations .ORG 03H ;external interrupt 0 RETI ; .ORG 0BH ;timer 0 interrupt RETI ; .ORG 13H ;external interrupt 1 RETI ; .ORG 1BH ;timer 1 interrupt RETI ; .ORG 23H ;serial port interrupt JB RI,SERIN ;JUMP TO RECEIVE INRUP JB TI,SEROUT ; ;******************************************************; .ORG 030H ;locate beginning of rest of program ; ;******************************************************; INITIALIZE: ;set up control registers MOV PCON,#00H MOV TMOD,#020H ;Set Timer 1 for Mode 2, Auto Reload MOV TCON,#040H ;Turn timer 1 on MOV PSW ,#00H ; Set Bank 0 ??? MOV SCON,#050H ;set serial port to 8 bit UART MOV TH1 ,#0FEH ;Reload value for timer 1 for 31.25k baud (24MHz xtal) MOV P3 ,#003H ;Enable Serial Port Transmit and Receive SETB ES ; Enable Serial Interrupt SETB PS ; Set Serial Interrupt Priority to High RET ;******************************************************; ; SERIAL INPUT INTERRUPT ROUTINE ; SERIN: PUSH ACC PUSH PSW ; receive MOV A, SBUF ; store byte in A CLR RI ; Clear receive flag MOV @R0,A ; BUFFER[R0++] = A INC R0 CJNE R0,#BUFFER+BUFFER_SIZE,ISR_EXIT ; if(RO == BUFFER+BUFFER_SIZE) MOV R0,#BUFFER ; RO == BUFFER ISR_EXIT: POP PSW POP ACC RETI ;************************************************************************** ; ; SERIAL OUTPUT ROUTINE ; SEROUT: ; CLR TI ;CLEAR TRANSMIT INRUP RETI ;JUST EXIT ROUTINE ;************************************************************************** ; ; MAIN START: ;main program (on power up, program starts at this point) MOV SP,#02FH ;Set Stack Pointer = 2FH ACALL INITIALIZE ;set up control registers MOV R0,#BUFFER MOV R1,#BUFFER CLR RI ; Clear Receive Flag CLR TI ; Clear Transmit Flag SETB EA ; Global Interrupt Enable MAIN_LOOP: CLR C MOV A, R0 SUBB A, R1 JNZ SEND_BYTE ; CJNE A, R1, SEND_BYTE SJMP MAIN_LOOP SEND_BYTE: MOV A, @R1 ; A = BUFFER[R1++] INC R1 CLR TI MOV SBUF,A ; move outgoing value from A to SBUF JNB TI, $ ; Wait till done transmitting CJNE R1,#BUFFER+BUFFER_SIZE,MAIN_LOOP ; if(R1 == BUFFER+BUFFER_SIZE) MOV R1,#BUFFER ; R1 == BUFFER SJMP MAIN_LOOP .END The CPU is a 24MHz 8051 clone. Any input will be apreciated. Thanks! |
Topic | Author | Date |
MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI | 01/01/70 00:00 | |
RE: MIDI | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling | 01/01/70 00:00 | |
RE: MIDI messages handling![]() | 01/01/70 00:00 |