help with MIDI for pic16f1789 ???

Status
Not open for further replies.
Code:
#include "p16F877A.inc"

; CONFIG
; __config 0x3FB2
 __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 
temp equ 0x25
temp2 equ 0x26

   
              org     00              
              goto    begin
 org     04
goto dummy ;interrupt
 
           




    org     30
begin
    banksel PORTA
        clrf    PORTA
        clrf    PORTB
        clrf    PORTC
        clrf    PORTD
    clrf    PORTE
    
    
       banksel ADCON1
      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
    


        
   
        
   
   ; Set up USART
   
           banksel TRISC
           movlw   b'10000000'     
           movwf   TRISC       
           movlw   0x27             ; 31250 baud for MIDI
           movwf   SPBRG
           movlw   b'00100100'     ; async tx 8 bit
           movwf   TXSTA
           banksel RCSTA
           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    ;turn off all segments
        movwf    PORTE
movlw b'00000000'
movwf    PORTA
movwf    PORTB

    
          
    

    goto start

start

         
  banksel PIR1
   getmidi btfss   PIR1,RCIF   ; test for incoming data
               goto     nextime ;continue on with other duties
               movf    RCREG,W
           movwf   rcvreg
nextime
banksel 0
movwf temp2
andlw 0x80 ;don't display status only MIDI NOTES
bz update
goto start
 update movf temp2,0 ; get new midi value
disp movwf NOTE

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 0x2          ; ----------------------------------
                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 0x2    ; ----------------------------------
                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
clrf  RCREG ; throw out any extra bytes



    goto start    ; no




    







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

    hexTable movwf temp2
MOVF temp2,0
bnz disp2
ZERO  RETLW   b'01011111' ;0
disp2 DECFSZ temp2,1
    goto   xONE
ONE  RETLW   b'00000101' ;1
xONE DECFSZ temp2,1
goto xTWO
TWO  RETLW   b'01111100' ;2
 xTWO  DECFSZ temp2,1
goto xTHREE
THREE  RETLW   b'00111101' ;3
 xTHREE DECFSZ temp2,1
goto xFOUR
FOUR RETLW   b'00100111' ;4


xFOUR DECFSZ temp2,1
goto xFIVE
     FIVE  RETLW   b'00111011' ;5
xFIVE DECFSZ temp2,1
goto xSIX
SIX  RETLW   b'01111011' ;6
 xSIX DECFSZ temp2,1
goto xSEVEN
SEVEN  RETLW   b'00010101' ;7


xSEVEN DECFSZ temp2,1
goto xEIGHT
EIGHT  RETLW   b'01111111' ;8
 xEIGHT DECFSZ temp2,1
goto xNINE
  NINE  RETLW   b'00110111' ;9
 xNINE DECFSZ temp2,1
goto xA
A  RETLW   b'01110111' ;a


xA DECFSZ temp2,1
goto xBEE
   BEE RETLW   b'01101011' ;b
xBEE DECFSZ temp2,1
goto xCEE
     CEE  RETLW   b'01011010' ;c
xCEE DECFSZ temp2,1
goto xDEE
  DEE  RETLW   b'01101101' ;d
xDEE DECFSZ temp2,1
goto xE
 E RETLW   b'01111010' ;e
xE RETLW   b'01110010' ;f
      


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

dummy retfie
    end
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.

Obviosly 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 ,LISTED BELOW , 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. i have been pulling my hair out literally for months trying to figure the proper Eusart setup just to get the above code sample to work on the 1789

Code:
#include "P16F1789.INC"

; CONFIG1
; __config 0xF9C2
 __CONFIG _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF   
; CONFIG2
; __config 0xDFFF
 __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF  & _LVP_OFF


rcvreg    equ  0x30
delay    equ    0x32
BIGdelay equ 0x33
NOTE equ 0x34 ; if over 80h or greater next bank
temp equ 0x35
temp2 equ 0x36

    
              org     0x0               ; reset vector
              goto    begin
 org     0x4
goto dummy

 
           




    org    0x30
begin
    banksel PORTA
        clrf    PORTA
        clrf    PORTB
        clrf    PORTC
        clrf    PORTD
    clrf    PORTE
    
    
  



   ; Set up USART
   banksel BAUD1CON
 movlw   b'00001000'
movwf BAUD1CON
BANKSEL PIE1
 movlw   b'00100000'
movwf PIE1
movlw b'11010000'  ;enable global and peripheral ints
movwf INTCON
           banksel SPBRG
           movlw   0x27             ; 31250 baud for MIDI
           movwf  SPBRG

;BANKSEL ANSELC
;CLRF PORTC ;Init PORTA
; LATC ;Data Latch
;CLRF LATC ;
;BANKSEL ANSELC ;
;CLRF ANSELC ;digital I/O
BANKSEL TRISC ;
MOVLW B'10000000'
MOVWF TRISC

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





    clrf    PORTA ; set all outputs to '00000000'
        clrf    PORTB
        clrf    PORTD

    movlw    0x03    ;turn off all segments
        movwf    PORTE
movlw b'00000000'
movwf    PORTA
movwf    PORTB



       BANKSEL APFCON1
  movlw   b'00000010'
movwf APFCON1
    banksel TX1STA
           movlw   b'00100100'     ; async tx 8 bit
           movwf   TX1STA
           banksel RC1STA
           movlw   b'10000000'     ; async rx 8 bit  SET SPEN
           movwf   RC1STA
    movlw   b'10010000'
 movwf   RC1STA ;SET cren
   clrw

    
          
    

    goto start
 
Status
Not open for further replies.