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.

i got MIDI going ...BUT I want it to work for pic16f1789

Status
Not open for further replies.

techristian

Member level 1
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,612
I got MIDI (youtube link below) BUT the PIC is a very frustrating device to program. The language changes from CHIP to chip EVEN IN THE SAME 16Fxxxx family !!


Anyway the code below runs on the 16f877A (notice the KLUDGY HexTable routine that I wrote for the 16f877A . NO BRW for this puppy !)
The code below WILL NOT work on the 16F1789 (The chip I want to program because of it's DAC !!)The 16f1789 has a few more configuration registers and things which we tried earlier. I will list a bit of additional code for the 16f1789 at the bottom.



https://www.youtube.com/watch?v=leUeKmhmEqs

Code:
    #include "P16F877A.INC"

; CONFIG
; __config 0xFF32
 __CONFIG _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF




rcvreg    equ       0x20
delay    equ    0x22
BIGdelay equ 0x23
NOTE equ 0x24 ; if over 80h or greater next bank
temp equ 0x25
temp2 equ 0x26

    
              org     00               ; reset vector
              goto    begin
 org     04
goto dummy
;-----------------------------------------------------------------------------
rxdata         btfss   PIR1,RCIF   ; test for incoming data
               goto     $-1
               movf    RCREG,W
           movwf   rcvreg

return

          



 
;initialize
    org     30
begin    bcf     STATUS,RP0      ;page 0
        clrf    PORTA
        clrf    PORTB
        clrf    PORTC
        clrf    PORTD
    clrf    PORTE
   
   
       bsf STATUS,RP0
      MOVLW 6            
          MOVWF ADCON1        ;set port A as digital
          CLRF TRISA         ;all pins outputs
      CLRF TRISB         ;all pins outputs
          CLRF TRISD         ;all pins outputs  
    movlw b'00000000'
banksel TRISD; make all outputs
movwf TRISD
movwf TRISE
   


        bcf STATUS,RP0          ; return to page 0
  
       
  
   ; Set up USART
  
           bsf     STATUS,RP0      ; goto page 1
           movlw   b'10000000'     ; RC7 is RX input
           movwf   TRISC       ; RC0-3 i/p MIDI Ch.
           movlw   0x27             ; 31250 baud for MIDI
           movwf   SPBRG
           movlw   b'01100100'     ; async tx 9 bit
           movwf   TXSTA
           bcf STATUS,RP0
           movlw   b'10010000'     ; async rx 8 bit
           movwf   RCSTA
  
            clrw


    clrf    PORTA ; set all outputs to '0000 0000'
        clrf    PORTB       
        clrf    PORTD
clrf    PORTC
    movlw    0x03    ; 0000 0000 must be 4?
        movwf    PORTE
movwf    PORTA
movwf    PORTB
movwf    PORTC
      movf PORTC,W ; read midich. switches
         
   

    goto start


start

    call rxdata
movwf temp2
andlw 0x80 ;don't display status
bz update
goto start
 update movf temp2,0 ; get new midi value
disp movwf NOTE

 CALL DISPLAY

    goto start    ; no


DISPLAY    movf NOTE,0
    movwf temp                     ;copy number to temp here

 movlw b'00001111' ;least signifigant digit mask
    andwf temp,0

    CALL hexTable
movwf    PORTD ;DISPLAY LOW DIGIT

movlw     b'00000010'
movwf    PORTE   ; turn on least signifigant digit
                movlw 0x5          ; ----------------------------------
                MOVWF BIGdelay  ;keep on for a while.. small PAUSE
                call D250
 movlw     b'00000011'
movwf    PORTE  ; turn off most signifigant digit
                movlw 0x1   ; ----------------------------------
                MOVWF BIGdelay  ;keep on for a while.. small PAUSE
                call D250

movf NOTE,0

movlw b'11110000' ;high bit mask
andwf temp, 1
    RRF temp, 1
    RRF temp, 1
   RRF temp, 1
    RRF temp, 0 ;shift right 3 times store in W

    CALL hexTable
movwf    PORTD ;DISPLAY CHARACTER

movlw     b'00000001'
movwf    PORTE  ; turn on most signifigant digit
                movlw 0x5    ; ----------------------------------
                MOVWF BIGdelay  ;keep on for a while.. small PAUSE
                call D250        ; ----------------------------------
clrf RCREG
movlw     b'00000011'
movwf    PORTE  ; turn off most signifigant digit
                movlw 0x1    ; ----------------------------------
                MOVWF BIGdelay  ;keep on for a while.. small PAUSE
                call D250
RETURN

;bit 7DOT bit 6E bit 5G BIT 4A BIT 3D BIT 2B BIT 1F BIT 0C

    hexTable movwf temp2
MOVF temp2,0
bnz disp2
goto ZERO
disp2 DECFSZ temp2,1
    goto   xONE
goto   ONE
xONE DECFSZ temp2,1
goto xTWO
goto TWO
 xTWO  DECFSZ temp2,1
goto xTHREE
goto THREE
 xTHREE DECFSZ temp2,1
goto xFOUR
goto FOUR
xFOUR DECFSZ temp2,1
goto xFIVE
goto FIVE
xFIVE DECFSZ temp2,1
goto xSIX
goto SIX
 xSIX DECFSZ temp2,1
goto xSEVEN
goto SEVEN
xSEVEN DECFSZ temp2,1
goto xEIGHT
goto EIGHT
 xEIGHT DECFSZ temp2,1
goto xNINE
goto NINE
 xNINE DECFSZ temp2,1
goto xA
goto A
xA DECFSZ temp2,1
goto xBEE
goto BEE
xBEE DECFSZ temp2,1
goto xCEE
goto CEE
xCEE DECFSZ temp2,1
goto xDEE
goto DEE
xDEE DECFSZ temp2,1
goto xE
goto E
xE goto EF
      ZERO  RETLW   b'01011111' ;0
     ONE  RETLW   b'00000101' ;1
      TWO  RETLW   b'01111100' ;2
      THREE  RETLW   b'00111101' ;3
      FOUR RETLW   b'00100111' ;4
      FIVE  RETLW   b'00111011' ;5
     SIX  RETLW   b'01111011' ;6
    SEVEN  RETLW   b'00010101' ;7
      EIGHT  RETLW   b'01111111' ;8
      NINE  RETLW   b'00110111' ;9
      A  RETLW   b'01110111' ;a
      BEE RETLW   b'01101011' ;b
      CEE  RETLW   b'01011010' ;c
      DEE  RETLW   b'01101101' ;d
       E RETLW   b'01111010' ;e
       EF RETLW   b'01110010' ;f

PAUSE movlw 0xff
    MOVWF BIGdelay
D250    movlw    0xff
    movwf    delay
l250    decfsz    delay,f
    goto    l250
DECFSZ BIGdelay,f
GOTO D250
    return

dummy retfie
    end

----------SOME CODE BELOW MAY BE NEEDED 4 16F1789------------------
BANKSEL        LATC                             ;Data Latch
CLRF               LATC                             ;
BANKSEL        ANSELC                       ; default input is in Analog mode
CLRF              ANSELC                        ; switch todigital I/O
BANKSEL INTCON
movlw b'11000000'  ;enable global and peripheral ints
movwf INTCON
banksel PIE1
movlw b'00100000' ;enable RX   interrupts
movwf PIE1

BANKSEL APFCON1
movlw 0x00
movwf APFCON1 ; set port A mode I/O digital
BANKSEL APFCON2
movwf APFCON2


ADCON1 IS A DIFFERENT ANIMAL ON 16F1789
 

1) The language does not change from chip to chip, the registers do. Microchip supplies libraries that contain the register mapping so you don't have to worry about it, as long as you include the proper libraries.
2) What do you mean it "will not work"? Could you be more specific?
3) What is BRW?
 

1) The language does not change from chip to chip, the registers do. Microchip supplies libraries that contain the register mapping so you don't have to worry about it, as long as you include the proper libraries.
2) What do you mean it "will not work"? Could you be more specific?
3) What is BRW?

1) First off, I'm working in assembler. Yes there are differences.

2) It won't work because USART setup is more complicated on the 16f1789. There are more registers to set up. ADCON1 ,for an example, when looking at the spec sheets ,is a totally different animal on the 2 microprocessors.

3) MPASM would not allow use of the BRW command for the 16f877. This command BRANCHES to the address offset by the value in "W". I works well for tables.

Dan
 

Ok.

I just realized that this is NOT the same as the 16F1784-85-86-87 that will make a difference for sure. I have been working those previously and wrongly assumed that the 16F1789 was from the same family. This will help in debugging....but I won't post "solved" until I get it working.

Dan
 

The above code example works well on the 16F877A. I'm just hoping that someone will give me a few pointers on getting the same code to work with the 16F1789. I also discovered that one of my keyboards sends out ZERO for Note Off Volume, so I will need to filter that out as well for a clear display.

Obviously my code works. It is just a matter of setting up the USART or as in the case of the 16F1789 the EUSART. The setup is the tricky part for the 16F1789. Here is my setup code , so far, for the 16F1789. What do I need here and what can I throw out ? What am I missing? I would rather work with the 16F1789

Dan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top