Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Midi input using portb rx port ...to many initializing factors !!

Status
Not open for further replies.

techristian

Member level 1
Joined
Apr 3, 2013
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Windsor, Ontario
Activity points
1,611
Midi input using portb rx port p16f1784...to many initializing factors !!

Here is my code. It should be simple enough. Get MIDI from the MIDI interface (optoisolator and 220ohm resistor) and display the MIDI information on my 7 segment LEDS. The problem is that there are so many things to set up before I even begin !! Do I have TOO MUCH in my initialization ?? I want to use RX of PORTB for input of MIDI serial data (2 stop bits and 8 bits @ 31,250 ) Is APFCON even needed in config ? I don't see anyone using it. This is running with a 20 mhz crystal, and I have a keyboard plugged into MIDI IN to supply the MIDI data. If I can't get the UART working , I'm tempted to BIT BANG this. That's how frustrating this is. I wrote RAW serial waves way back 30 years ago, but it is only a last resort. This should be accomplished using the USART. This may or may not be my latest code, but it doesn't matter. I have added and subtracted lines of code from this for the past month and I end up back in the same place...going in circles. TXSTA isn't configured here . I know it is supposed to be configured before SPBRG? . I also had BRGH set to 1 and SPBRG set to 27h at one point, but the 20 mhz ~ nicely divides evenly, so it really doesn't matter...I think?

Code:
#include <p16f1784.inc>


; CONFIG1
; __config 0x3FE2
 __CONFIG _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
; CONFIG2
; __config 0x3FFF
 __CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_ON


delay	equ	0x7e
BIGdelay equ 0x7f
NUMBER equ 0x7c ; if over 80h or greater next bank
temp equ 0x7d
NUMBERhi equ 0x7b
temp2 equ 0x7a




    org	0x0000
    goto    start

	org	0x004
	goto	dummyINT

start
movlw 	b'00000000'		;MOVE ZERO TO ACC "W"orking register
    movwf   NUMBER
    movwf   NUMBERhi
    movwf temp



banksel TRISA; make all outputs
movwf TRISC
movwf TRISD
movwf TRISE
movlw 	b'10000000'
movwf TRISA ;all outputs except bit 7
movlw   b'10001111'     ; RB7 is RX input
           movwf   TRISB	   ; RB0-3 i/p MIDI Ch.
BANKSEL APFCON1
movlw 	b'11111111'
movwf APFCON1
movlw 	b'00000001'
movwf APFCON2
BANKSEL SYNC
movwf SYNC
movlw 0x1
movwf CREN
movwf SPEN
banksel SPBRG

           
           movlw 0x9   ;baud 31250 for MIDI @20MHZ

           movwf   SPBRG
         
           movlw   b'10010000'     ; async rx 8 bit
           movwf   RCSTA

            clrw






        ;3600= 0E10H








    




    BANKSEL 0
goto firstZERO ;display MSB zero at beginning

loop NOP


 



rxdata         btfss   PIR1,RCIF   ; test for incoming data
               goto     $-1
               movf    RCREG,0
	      movwf NUMBER ;MIDI VALUE IS PASSED TO "NUMBER" FOR DISPLAY ON 7 SEGMENT LEDS

..............................................................DISPLAY BELOW

aftrHI    movf NUMBER,0
    movwf temp                     ;copy number to temp here
  
 movlw b'00001111' ;least signifigant digit mask
    andwf temp,0

    CALL hexTable
    movwf temp
    andwf b'00111111'
    movwf	PORTA ;DISPLAY LOW DIGIT

movlw b'01000000'
andwf temp,1
LSRF temp, 1
LSRF temp, 1
LSRF temp, 1
LSRF temp, 0

movwf	 PORTE

    movf NUMBER,0
    movwf temp
    movlw b'11110000' ;high bit mask
    andwf temp, 1
    LSRF temp, 1
    LSRF temp, 1
    LSRF temp, 1
    LSRF temp, 0 ;shift right 3 times store in W
    CALL hexTable
    movwf	PORTC





;loop forever
	goto	loop

    hexTable BRW
    RETLW   b'01110111' ;0
    RETLW   b'01000001' ;1
    RETLW	b'00111011' ;2
    RETLW	b'01101011' ;3
    RETLW	b'01001101' ;4
    RETLW	b'01101110' ;5
    RETLW	b'01111110' ;6
    RETLW	b'01000011' ;7
    RETLW	b'01111111' ;8
    RETLW	b'01001111' ;9
    RETLW	b'01011111' ;A
    RETLW	b'01111100' ;B
    RETLW	b'00110110' ;C
    RETLW	b'01111001' ;D
    RETLW	b'00111110' ;E
    RETLW	b'00011110' ;F


PAUSE movlw 0xA4
    MOVWF BIGdelay
D250	movlw	0xFE
	movwf	delay
l250	decfsz	delay,f
	goto	l250
DECFSZ BIGdelay,f
GOTO D250
	return
................................................HIdisplay (3RD DIGIT NOT NEEDED FOR MIDI only 2 hex digits needed)
HIdisplay INCF NUMBERhi,1
   firstZERO movf NUMBERhi,0
    movwf temp                     ;copy number to temp here
    movlw b'00001111' ;least signifigant digit mask
    andwf temp,0

CALL hexTable
    movwf	PORTD

goto	aftrHI


dummyINT retfie


              


	end
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top