let me introduce myself

Thread Starter

techristian

Joined Aug 27, 2013
53
I'm fairly new to PIC CHIP programming..... but 30 years ago I designed a Commodore 64 Lead Synthesizer called Fastfingers. I have a MIDI interface partly working now, based on the PIC16F877A but I am having some problem with porting it over to the PIC16F1789 (i like the DAC in the 1789).

I also have a small problem with the 16F877A . It works for 30 seconds or so, displaying the MIDI NOTE NUMBERS as I hit the keyboard, but then stops. RESET WON'T BRING IT BACK. Only reprogramming with PICKIT3 will bring it back ???? I checked the power but it is SOLID 5V and I have the high frequency cap across the power for filtering. I don't have MCLR tied to anything though and so I will try that.

Dan

http://musicinit.com/fastfingers.php
 

MaxHeadRoom

Joined Jul 18, 2013
30,806
I found it usually pays to take the MCLR high, regardless how it is configured.
Are you programming in C or Assembler?
I got some experience with the 16F series but gravitated over to the 18F, a few nicer commands, especially if using Assembler.
Max.
 

Thread Starter

techristian

Joined Aug 27, 2013
53
I'm using Assembler (mpasm). I wrote my old 80's software in 6502 and Z80. I don't like working with the large C libraries. Someone has suggested that I use C as a shell and put my ML inside of it.

Anyway I use the same circuit with a ZIF socket for both the 16f1789 and 16f877a. The 16f1789 counter works fine forever and forever, but the 16f877A USART stuff stops after 20 seconds or so. I also tried clearing RCREG (incase it was getting plugged up) and clearing the overflow bit as well.

Thank you for a very fast response.

Dan
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
Is that the right way round (16f1789 counter works fine forever and forever, but the 16f877A USART stuff stops)?

Something of that time period sounds like it could be the WDT or a stack overflow / underflow. Does it happen 30 seconds from power on, or 30 seconds from the first midi note? That should give you an idea of where to look.
If the MCLR reset is enabled then pulling it to ground should always work to reset it. Unless you are saving something to EEPROM that stops it from working the next time.
Sometimes removing power from the Vdd pin is not enough to reset the chip if it can get power through any of it's other pins, and sometimes removing power from the whole board doesen't work if there are capacitors.
 

MaxHeadRoom

Joined Jul 18, 2013
30,806
There is a very useful USART app note on the PIC site if you have not already seen it.
I don't have the AN number here but it covers three of the basic PIC's up to the 18F and includes USART interrupted and non-interrupted USART routines.
Max.
 

Thread Starter

techristian

Joined Aug 27, 2013
53
Stack overflow? That sounds interesting...the kind of thing that happens when you never RETURN from a subroutine ....or jump outside without returning ..over and over. I'll look at the WDT too.

Dan
 

ErnieM

Joined Apr 24, 2011
8,415
Stack overflow? That sounds interesting...the kind of thing that happens when you never RETURN from a subroutine ....or jump outside without returning ..over and over. I'll look at the WDT too.

Dan
Depending on the PIC "over and over" can be as much as... eight.

The stack is in hardware and are small in PICs. You can properly call proper functions correctly, but just call too many and blow the stack.

(Many of these problems are eliminated if you switch from assembler to C. )
 

Thread Starter

techristian

Joined Aug 27, 2013
53
I read the Microchip specs again and used a 42K ohm resistor from MCLR to +5V. It works fine now. Not only that, but I can leave the pickit3 on all of the time now. This wasn't a problem with the 16f1789.

Next thing now..to figure out how to get this working on the 16F1789. The code below just DISPLAYS MIDI IN NOTES in Hexadecimal.
Rich (BB 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
Dan
 

Thread Starter

techristian

Joined Aug 27, 2013
53
One thing I don't miss on the 18F series as remembering to do those banksel !
Max.
There is also no BRW on the 16f877 but yes it is on the 16f1789 which makes the hextable look alot neater.

ADCON is a different animal on the 16f1789 as well.

Right now when I execute this it only tells my that RCREG = "04" (that's what the display shows)

I have tried using INTCON AND BAUDCON as well.

Dan
 

Thread Starter

techristian

Joined Aug 27, 2013
53
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.

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 , 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

Rich (BB 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
    
    
     ; banksel ADCON1
    ;MOVLW 6
       ;MOVWF ADCON1



   ; 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
 
Top