let me introduce myself

Discussion in 'Embedded Systems and Microcontrollers' started by techristian, Aug 27, 2013.

  1. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    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
     
  2. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,553
    2,375
    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.
     
  3. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    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: Aug 27, 2013
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
    techristian likes this.
  5. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,553
    2,375
    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.
     
    techristian likes this.
  6. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    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
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    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. )
     
  8. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    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.
    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include "p16F877A.inc"
    4.  
    5. ; CONFIG
    6. ; __config 0x3FB2
    7.  __CONFIG _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
    8.  
    9.  
    10.  
    11.  
    12.  
    13. rcvreg    equ       0x20
    14. delay    equ    0x22
    15. BIGdelay equ 0x23
    16. NOTE equ 0x24
    17. temp equ 0x25
    18. temp2 equ 0x26
    19.  
    20.    
    21.               org     00              
    22.               goto    begin
    23.  org     04
    24. goto dummy ;interrupt
    25.  
    26.            
    27.  
    28.  
    29.  
    30.  
    31.     org     30
    32. begin
    33.     banksel PORTA
    34.         clrf    PORTA
    35.         clrf    PORTB
    36.         clrf    PORTC
    37.         clrf    PORTD
    38.     clrf    PORTE
    39.    
    40.    
    41.        banksel ADCON1
    42.       MOVLW 6            
    43.           MOVWF ADCON1        ;set port A as digital
    44.           CLRF TRISA         ;all pins outputs
    45.       CLRF TRISB         ;all pins outputs
    46.           CLRF TRISD         ;all pins outputs  
    47.     movlw b'00000000'
    48. banksel TRISD; make all outputs
    49. movwf TRISD
    50. movwf TRISE
    51.    
    52.  
    53.  
    54.        
    55.    
    56.        
    57.    
    58.    ; Set up USART
    59.    
    60.            banksel TRISC
    61.            movlw   b'10000000'    
    62.            movwf   TRISC      
    63.            movlw   0x27             ; 31250 baud for MIDI
    64.            movwf   SPBRG
    65.            movlw   b'00100100'     ; async tx 8 bit
    66.            movwf   TXSTA
    67.            banksel RCSTA
    68.            movlw   b'10010000'     ; async rx 8 bit
    69.            movwf   RCSTA
    70.    clrw
    71.        
    72.  
    73.  
    74.     clrf    PORTA ; set all outputs to '0000 0000'
    75.         clrf    PORTB        
    76.         clrf    PORTD
    77. clrf    PORTC
    78.     movlw    0x03    ;turn off all segments
    79.         movwf    PORTE
    80. movlw b'00000000'
    81. movwf    PORTA
    82. movwf    PORTB
    83.  
    84.    
    85.          
    86.    
    87.  
    88.     goto start
    89.  
    90. start
    91.  
    92.          
    93.   banksel PIR1
    94.    getmidi btfss   PIR1,RCIF   ; test for incoming data
    95.                goto     nextime ;continue on with other duties
    96.                movf    RCREG,W
    97.            movwf   rcvreg
    98. nextime
    99. banksel 0
    100. movwf temp2
    101. andlw 0x80 ;don't display status only MIDI NOTES
    102. bz update
    103. goto start
    104.  update movf temp2,0 ; get new midi value
    105. disp movwf NOTE
    106.  
    107. DISPLAY    movf NOTE,0
    108.     movwf temp                     ;copy number to temp here
    109.  
    110.  movlw b'00001111' ;least signifigant digit mask
    111.     andwf temp,0
    112.  
    113.     CALL hexTable
    114. movwf    PORTD ;DISPLAY LOW DIGIT
    115.  
    116. movlw     b'00000010'
    117. movwf    PORTE   ; turn on least signifigant digit
    118.                 movlw 0x2          ; ----------------------------------
    119.                 MOVWF BIGdelay  ;keep on for a while.. small PAUSE
    120.                 call D250
    121.  movlw     b'00000011'
    122. movwf    PORTE  ; turn off most signifigant digit
    123.                 movlw 0x1   ; ----------------------------------
    124.                 MOVWF BIGdelay  ;keep on for a while.. small PAUSE
    125.                 call D250
    126.  
    127. movf NOTE,0
    128.  
    129. movlw b'11110000' ;high bit mask
    130. andwf temp, 1
    131.     RRF temp, 1
    132.     RRF temp, 1
    133.    RRF temp, 1
    134.     RRF temp, 0 ;shift right 3 times store in W
    135.  
    136.     CALL hexTable
    137. movwf    PORTD ;DISPLAY CHARACTER
    138.  
    139. movlw     b'00000001'
    140. movwf    PORTE  ; turn on most signifigant digit
    141.                 movlw 0x2    ; ----------------------------------
    142.                 MOVWF BIGdelay  ;keep on for a while.. small PAUSE
    143.                 call D250        ; ----------------------------------
    144.  
    145. movlw     b'00000011'
    146. movwf    PORTE  ; turn off most signifigant digit
    147.                 movlw 0x1    ; ----------------------------------
    148.                 MOVWF BIGdelay  ;keep on for a while.. small PAUSE
    149.                 call D250
    150. clrf  RCREG ; throw out any extra bytes
    151.  
    152.  
    153.  
    154.     goto start    ; no
    155.  
    156.  
    157.  
    158.  
    159.    
    160.  
    161.  
    162.  
    163.  
    164.  
    165.  
    166.  
    167. ;bit 7DOT bit 6E bit 5G BIT 4A BIT 3D BIT 2B BIT 1F BIT 0C
    168.  
    169.     hexTable movwf temp2
    170. MOVF temp2,0
    171. bnz disp2
    172. ZERO  RETLW   b'01011111' ;0
    173. disp2 DECFSZ temp2,1
    174.     goto   xONE
    175. ONE  RETLW   b'00000101' ;1
    176. xONE DECFSZ temp2,1
    177. goto xTWO
    178. TWO  RETLW   b'01111100' ;2
    179.  xTWO  DECFSZ temp2,1
    180. goto xTHREE
    181. THREE  RETLW   b'00111101' ;3
    182.  xTHREE DECFSZ temp2,1
    183. goto xFOUR
    184. FOUR RETLW   b'00100111' ;4
    185.  
    186.  
    187. xFOUR DECFSZ temp2,1
    188. goto xFIVE
    189.      FIVE  RETLW   b'00111011' ;5
    190. xFIVE DECFSZ temp2,1
    191. goto xSIX
    192. SIX  RETLW   b'01111011' ;6
    193.  xSIX DECFSZ temp2,1
    194. goto xSEVEN
    195. SEVEN  RETLW   b'00010101' ;7
    196.  
    197.  
    198. xSEVEN DECFSZ temp2,1
    199. goto xEIGHT
    200. EIGHT  RETLW   b'01111111' ;8
    201.  xEIGHT DECFSZ temp2,1
    202. goto xNINE
    203.   NINE  RETLW   b'00110111' ;9
    204.  xNINE DECFSZ temp2,1
    205. goto xA
    206. A  RETLW   b'01110111' ;a
    207.  
    208.  
    209. xA DECFSZ temp2,1
    210. goto xBEE
    211.    BEE RETLW   b'01101011' ;b
    212. xBEE DECFSZ temp2,1
    213. goto xCEE
    214.      CEE  RETLW   b'01011010' ;c
    215. xCEE DECFSZ temp2,1
    216. goto xDEE
    217.   DEE  RETLW   b'01101101' ;d
    218. xDEE DECFSZ temp2,1
    219. goto xE
    220.  E RETLW   b'01111010' ;e
    221. xE RETLW   b'01110010' ;f
    222.      
    223.  
    224.  
    225. PAUSE movlw 0xff
    226.     MOVWF BIGdelay
    227. D250    movlw    0x80
    228.     movwf    delay
    229. l250    decfsz    delay,f
    230.     goto    l250
    231. DECFSZ BIGdelay,f
    232. GOTO D250
    233.     return
    234.  
    235. dummy retfie
    236.     end
    237.  
    Dan
     
  9. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,553
    2,375
    One thing I don't miss on the 18F series as remembering to do those banksel !
    Max.
     
  10. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    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
     
  11. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    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

    Code ( (Unknown Language)):
    1. #include "P16F1789.INC"
    2.  
    3. ; CONFIG1
    4. ; __config 0xF9C2
    5.  __CONFIG _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF  
    6. ; CONFIG2
    7. ; __config 0xDFFF
    8.  __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF  & _LVP_OFF
    9.  
    10.  
    11. rcvreg    equ  0x30
    12. delay    equ    0x32
    13. BIGdelay equ 0x33
    14. NOTE equ 0x34 ; if over 80h or greater next bank
    15. temp equ 0x35
    16. temp2 equ 0x36
    17.  
    18.    
    19.               org     0x0               ; reset vector
    20.               goto    begin
    21.  org     0x4
    22. goto dummy
    23.  
    24.  
    25.            
    26.  
    27.  
    28.  
    29.  
    30.     org    0x30
    31. begin
    32.     banksel PORTA
    33.         clrf    PORTA
    34.         clrf    PORTB
    35.         clrf    PORTC
    36.         clrf    PORTD
    37.     clrf    PORTE
    38.    
    39.    
    40.      ; banksel ADCON1
    41.     ;MOVLW 6
    42.        ;MOVWF ADCON1
    43.  
    44.  
    45.  
    46.    ; Set up USART
    47.    banksel BAUD1CON
    48.  movlw   b'00001000'
    49. movwf BAUD1CON
    50. BANKSEL PIE1
    51.  movlw   b'00100000'
    52. movwf PIE1
    53. movlw b'11010000'  ;enable global and peripheral ints
    54. movwf INTCON
    55.            banksel SPBRG
    56.            movlw   0x27             ; 31250 baud for MIDI
    57.            movwf  SPBRG
    58.  
    59. ;BANKSEL ANSELC
    60. ;CLRF PORTC ;Init PORTA
    61. ; LATC ;Data Latch
    62. ;CLRF LATC ;
    63. ;BANKSEL ANSELC ;
    64. ;CLRF ANSELC ;digital I/O
    65. BANKSEL TRISC ;
    66. MOVLW B'10000000'
    67. MOVWF TRISC
    68.  
    69. CLRF TRISA         ;all pins outputs
    70.       CLRF TRISB         ;all pins outputs
    71.           CLRF TRISD         ;all pins outputs
    72.     movlw b'00000000'
    73. banksel TRISD; make all outputs
    74. movwf TRISD
    75. movwf TRISE
    76.  
    77.  
    78.  
    79.  
    80.  
    81.     clrf    PORTA ; set all outputs to '00000000'
    82.         clrf    PORTB
    83.         clrf    PORTD
    84.  
    85.     movlw    0x03    ;turn off all segments
    86.         movwf    PORTE
    87. movlw b'00000000'
    88. movwf    PORTA
    89. movwf    PORTB
    90.  
    91.  
    92.  
    93.        BANKSEL APFCON1
    94.   movlw   b'00000010'
    95. movwf APFCON1
    96.     banksel TX1STA
    97.            movlw   b'00100100'     ; async tx 8 bit
    98.            movwf   TX1STA
    99.            banksel RC1STA
    100.            movlw   b'10000000'     ; async rx 8 bit  SET SPEN
    101.            movwf   RC1STA
    102.     movlw   b'10010000'
    103.  movwf   RC1STA ;SET cren
    104.    clrw
    105.  
    106.    
    107.          
    108.    
    109.  
    110.     goto start
     
Loading...