porting over 16F877 USART to 16F1789 Eusart MIDI

Discussion in 'Embedded Systems and Microcontrollers' started by techristian, Sep 1, 2013.

  1. techristian

    Thread Starter New Member

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

    Well-Known Member

    Feb 14, 2010
    759
    116
    I suspect something like this might work;

    Code ( (Unknown Language)):
    1.  
    2. ;
    3. ;  BRG value for 31250 baud with Fosc = 16 MHz (BRGH=1/BRG16=1)
    4. ;
    5.         radix dec
    6. brgval  equ (16000000/31250/4)-1
    7. ;
    8. ;  setup EUSART module for asynchronous 31250/8/1/N
    9. ;
    10.         banksel SP1BRGL         ; bank 3                          |B3
    11.         movlw   low(brgval)     ; setup baud rate generator       |B3
    12.         movwf   SP1BRGL         ;                                 |B3
    13.         movlw   high(brgval)    ;                                 |B3
    14.         movwf   SP1BRGH         ;                                 |B3
    15.         movlw   1<<BRG16        ;                                 |B3
    16.         movwf   BAUD1CON        ; BRG16 = 1                       |B3
    17.         movlw   1<<TXEN|1<<BRGH ;                                 |B3
    18.         movwf   TX1STA          ; TXEN=1, BRGH=1, SYNC=0      |B3
    19.         movlw   1<<SPEN|1<<CREN ;                 |B3
    20.         movwf   RC1STA          ; SPEN=1, CREN=1          |B3
    21.  
    You also need to pay close attention to banking since all of the EUSART registers are located in bank 3 in these newer "enhanced mid-range" 14-bit core devices.

    Good luck on your project.

    Cheerful regards, Mike
     
    techristian likes this.
  3. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    Thanks Mike for the suggestion. I'm using a 20 mhz crystal, but I think your code will help as a starting point. I also learned from the errata sheet that BRA and BRW commands can't be used if I want to use interrupts. Those commands mess up the program counter during an interrupt.

    Thanks again

    Dan
     
    Last edited: Sep 2, 2013
  4. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Hi Dan,

    I was looking at your code and I was wondering what the incoming MIDI data looks like? I see you ignore any incoming byte with bit 7 set and I also noticed that you seem to throw away an incoming character within your 'update' code.

    Cheerful regards, Mike
     
  5. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    Hey Mike

    I'm just looking at MIDI NOTE numbers. I wrote some code last year for the Commodore 64 MIDI setting up an interrput 3125 times a second to poll the port of a Sentech/Passport type interface. It was good but not good enough. It would miss 3% to 5% of the notes and play wrong notes. The Passport and Sentech ports DON'T have a buffer. So I am designing my own...with either a buffer, or a MIDI interface that makes intelligent decisions. I don't like the 2 byte standard for MIDI.

    If you want to see what the output looks like, I posted a youtube video. I'm using no resistors for the LED segments but don't worry. They won't burn out. I had to turn up the contrast on the video and pull all of my curtains to record the video. It's not too impressive...unless you consider that I walked away from Machine Language programming over 30 years ago and just got back into it in 2011 . http://www.youtube.com/watch?v=leUeKmhmEqs

    BTW I use BRW command for the "hexTable" on the 16F1789 and that's something I will need to avoid so that I can use interrupts. That's why I mentioned it above.
    Dan
     
    Last edited: Sep 2, 2013
  6. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Hi Dan,

    That video matches the behavior I expected after studying your program. So, is the first byte of the two byte MIDI standard the "note"? And what is the second byte? Duration? How do you distinguish between the two? Is there a 'header' or 'separator' byte, or something like that? It looks like you're throwing away the second byte of the two byte sequence in your "update" code. Is that correct? Are you just making sure that you're delaying longer than one character time at 31250 baud (320 usecs) and less than two character times (640 usecs) in that code section?

    As far as using interrupts... can you use the BRW instruction within the ISR? If so, why not refresh the display in the ISR?

    Code ( (Unknown Language)):
    1.  
    2. ;
    3. ;  interrupt service routine (1-msec TMR2 interrupts)
    4. ;
    5.         org     0x004
    6. isrproc
    7.         movlb   0               ; bank 0                                  |B0
    8.         bcf     PIR1,TMR2IF     ; clear TMR2 interrupt flag               |B0
    9. ;
    10. ;  refresh display (refresh rate = 500 Hz)
    11. ;
    12.         clrf    PORTD           ; blank the display                       |B0
    13.         movlw   b'00000011'     ; bit mask for RE0 and RE1 bits           |B0
    14.         xorwf   PORTE,F         ; toggle active lo digit select bits      |B0
    15.         movf    NOTE,W          ; lo digit bits in b3..b0                 |B0
    16.         btfsc   PORTE,0         ; lo digit selected? yes, skip, else      |B0
    17.         swapf   NOTE,W          ; hi digit bits in b3..b0                 |B0
    18.         call    hexTable        ; get segment data                        |B0
    19.         movwf   PORTD           ; display new digit                       |B0
    20.         retfie                  ;                                         |B0
    21.  
    Code ( (Unknown Language)):
    1.  
    2. ;
    3. ;  number-to-segment data table for 7-segment displays
    4. ;
    5. hexTable
    6.         andlw   b'00001111'     ; lower nibble only                       |B0
    7.         brw                     ;     'pEGADBFC'                          |B0
    8.         retlw   b'01011111'     ; 0   '-E-ADBFC'
    9.         retlw   b'00000101'     ; 1   '-----B-C'
    10.         retlw   b'01111100'     ; 2   '-EGADB--'
    11.         retlw   b'00111101'     ; 3   '--GADB-C'
    12.         retlw   b'00100111'     ; 4   '--G--BFC'
    13.         retlw   b'00111011'     ; 5   '--GAD-FC'
    14.         retlw   b'01111011'     ; 6   '-EGAD-FC'
    15.         retlw   b'00010101'     ; 7   '---A-B-C'
    16.         retlw   b'01111111'     ; 8   '-EGADBFC'
    17.         retlw   b'00110111'     ; 9   '--GA-BFC'
    18.         retlw   b'01110111'     ; A   '-EGA-BFC'
    19.         retlw   b'01101011'     ; b   '-EG-D-FC'
    20.         retlw   b'01011010'     ; C   '-E-AD-F-'
    21.         retlw   b'01101101'     ; d   '-EG-DB-C'
    22.         retlw   b'01111010'     ; E   '-EGAD-F-'
    23.         retlw   b'01110010'     ; F   '-EGA--F-'
    24.  
     
    Last edited: Sep 2, 2013
  7. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    Down the road I will use the CLOCK based (44.1khz) interrupts for updating audio out to the DAC and for filtering ,glide etc. I'll need to read the errata sheet again to see if I'm allowed BRW within an interrupt.

    From my 1985 MIDI 1.0 Detailed Specification


    Dan
     
    Last edited: Sep 2, 2013
  8. techristian

    Thread Starter New Member

    Aug 27, 2013
    26
    2
    Code ( (Unknown Language)):
    1. radix dec
    2. brgval  equ (20000000/31250/16)-1
    Hi Mike

    First I tried your code exactly as you wrote it except I changed it to 20 mhz. No cigar. (why did you use /4 ? for the calculation? I'm using the HS oscillator.)

    Then I changed it to the listing above. This works exactly as the same thing I wrote before, but I do admit that your way of writing it is more elegant. After examining the Disassembly, I could see that the same values were placed into the registers.

    Anyway...the bottom line..... as soon as I plug in the live MIDI cable....this still writes "00" to my display and stops dead....When I start hitting keys it still shows 00 until I reset...The EUSART and NOT the program that is. If the program stopped dead one digit or the other OR NONE would display because I can't have 2 segments energized at the same time.

    I need to learn how to use the MPLABX debugger to follow this, but I suspect that the OVERFLOW bit is triggered and shutting down the EUSART.

    Thanks again for all of your help !

    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.  
    12.  
    13.  
    14. delay    equ    0x22
    15. BIGdelay equ 0x23
    16. NOTE equ 0x24 ; if over 80h or greater next bank
    17. temp equ 0x25
    18. temp2 equ 0x26
    19. LastNote equ 0x27
    20.  
    21.  
    22.  
    23.  
    24.  
    25.     org     30
    26. begin
    27.  
    28. banksel TRISA
    29.  
    30.           CLRF TRISA         ;all pins outputs
    31.       CLRF TRISB         ;all pins outputs
    32.           CLRF TRISD         ;all pins outputs
    33.     movlw b'00000000'
    34. banksel TRISD; make all outputs
    35. movwf TRISD
    36. movwf TRISE
    37.  
    38.            movlw   b'10000000'     ; RC7 is RX input
    39.            movwf   TRISC
    40.  
    41.  
    42.  
    43.  
    44.  ; Set up USART
    45. ;
    46. ;  BRG value for 31250 baud with Fosc = 16 MHz (BRGH=1/BRG16=1)
    47. ;
    48.         radix dec
    49. brgval  equ (20000000/31250/16)-1
    50. ;
    51. ;  setup EUSART module for asynchronous 31250/8/1/N
    52. ;
    53.         banksel SP1BRGL         ; bank 3                          |B3
    54.         movlw   low(brgval)     ; setup baud rate generator       |B3
    55.         movwf   SP1BRGL         ;                                 |B3
    56.         movlw   high(brgval)    ;                                 |B3
    57.         movwf   SP1BRGH         ;                                 |B3
    58.         movlw   1<<BRG16        ;                                 |B3
    59.         movwf   BAUD1CON        ; BRG16 = 1                       |B3
    60.         movlw   1<<TXEN|1<<BRGH ;                                 |B3
    61.         movwf   TX1STA          ; TXEN=1, BRGH=1, SYNC=0      |B3
    62.         movlw   1<<SPEN|1<<CREN ;                  |B3
    63.         movwf   RC1STA          ; SPEN=1, CREN=1
    64.  
    65.  ; BANKSEL LATC ;Data Latch
    66. ;CLRF LATC ;
    67. ;BANKSEL ANSELC ;
    68. ;CLRF ANSELC ;digital I/O
    69.  
    70.  
    71.  
    72.  
    73.  
    74.  
    75.  
    76.  
    77.     clrf    PORTA ; set all outputs to '0000 0000'
    78.         clrf    PORTB
    79.         clrf    PORTD
    80. clrf    PORTC
    81.     movlw    0x03    ;turn off all segments
    82.         movwf    PORTE
    83. movlw b'00000000'
    84. movwf    PORTA
    85. movwf    PORTB
    86.  
    87.  
    88.  
    89.  
    90.  
    91.    
    92. ;************************************************
    93. start
    94.  ; BANKSEL FERR
    95. ;CLRF    FERR ;CLEAR ERRORS
    96. ;banksel RCSTA
    97.       ;movlw   b'00010000'     ;clear overun error OERR by flipping CREN
    98.     ; movwf   RCSTA
    99.        ; movlw   b'10010000'     ; async rx 8 bit bit 6 for 8 or 9 bit
    100.          ;movwf   RCSTA
    101.  
    102.        
    103.   banksel PIR1
    104.    getmidi btfss   PIR1,RCIF   ; test for incoming data
    105. goto     nextime
    106.                movf    RCREG,W
    107.  
    108. MOVWF TXREG
    109. CLRF RCREG
    110.  
    111.  
    112. nextime
    113. banksel 0
    114. movwf PORTA  ; send Note to C64
    115. movwf temp2
    116.  
    117. andlw 0x80 ;don't display status
    118. bz update
    119. goto start
    120.  update movf temp2,0 ; get new midi value
    121.  
    122.  movwf NOTE
    123.  
    124. CALL DISPLAY
    125.  
    126.     goto start    ; no
    127.  
    128.  
    129.  
    130.  
    131.  
    132.  
    133.  
    134.  
    135.  
    136.  
    137.  
    138.  
    139. ;bit 7DOT bit 6E bit 5G BIT 4A BIT 3D BIT 2B BIT 1F BIT 0C
    140. org     0x130
    141. DISPLAY    movf NOTE,0
    142.     movwf temp                     ;copy number to temp here
    143.  
    144.  movlw b'00001111' ;least signifigant digit mask
    145.     andwf temp,0
    146.  
    147.     CALL hexTable
    148. movwf    PORTD ;DISPLAY LOW DIGIT
    149.  
    150. movlw     b'00000010'
    151. movwf    PORTE   ; turn on least signifigant digit
    152.                 movlw 0x5          ; ----------------------------------
    153.                 MOVWF BIGdelay  ;keep on for a while.. small PAUSE
    154.                 call D250
    155.  movlw     b'00000011'
    156. movwf    PORTE  ; turn off most signifigant digit
    157.                 movlw 0x2   ; ----------------------------------
    158.                 MOVWF BIGdelay
    159.                 call D250
    160.  
    161. movf NOTE,0
    162.  
    163. movlw b'11110000' ;high bit mask
    164. andwf temp, 1
    165.     LSRF temp, 1
    166.     LSRF temp, 1
    167.    LSRF temp, 1
    168.    LSRF temp, 0 ;shift right 3 times store in W
    169.  
    170.     CALL hexTable
    171. movwf    PORTD ;DISPLAY CHARACTER
    172.  
    173. movlw     b'00000001'
    174. movwf    PORTE  ; turn on most signifigant digit
    175.                 movlw 0x5    ; ----------------------------------
    176.                 MOVWF BIGdelay  ;keep on for a while.. small PAUSE
    177.                 call D250        ; ----------------------------------
    178.  
    179. movlw     b'00000011'
    180. movwf    PORTE  ; turn off most signifigant digit
    181.                 movlw 0x2    ; ----------------------------------
    182.                 MOVWF BIGdelay  ;keep on for a while.. small PAUSE
    183.                 call D250
    184. clrf  RCREG ; throw out any extra bytes
    185. RETURN
    186.  
    187.  
    188.     hexTable movwf temp2
    189. MOVF temp2,0
    190. bnz disp2
    191. ZERO  RETLW   b'01011111' ;0
    192. disp2 DECFSZ temp2,1
    193.     goto   xONE
    194. ONE  RETLW   b'00000101' ;1
    195. xONE DECFSZ temp2,1
    196. goto xTWO
    197. TWO  RETLW   b'01111100' ;2
    198.  xTWO  DECFSZ temp2,1
    199. goto xTHREE
    200. THREE  RETLW   b'00111101' ;3
    201.  xTHREE DECFSZ temp2,1
    202. goto xFOUR
    203. FOUR RETLW   b'00100111' ;4
    204.  
    205.  
    206. xFOUR DECFSZ temp2,1
    207. goto xFIVE
    208.      FIVE  RETLW   b'00111011' ;5
    209. xFIVE DECFSZ temp2,1
    210. goto xSIX
    211. SIX  RETLW   b'01111011' ;6
    212.  xSIX DECFSZ temp2,1
    213. goto xSEVEN
    214. SEVEN  RETLW   b'00010101' ;7
    215.  
    216.  
    217. xSEVEN DECFSZ temp2,1
    218. goto xEIGHT
    219. EIGHT  RETLW   b'01111111' ;8
    220.  xEIGHT DECFSZ temp2,1
    221. goto xNINE
    222.   NINE  RETLW   b'00110111' ;9
    223.  xNINE DECFSZ temp2,1
    224. goto xA
    225. A  RETLW   b'01110111' ;a
    226.  
    227.  
    228. xA DECFSZ temp2,1
    229. goto xBEE
    230.    BEE RETLW   b'01101011' ;b
    231. xBEE DECFSZ temp2,1
    232. goto xCEE
    233.      CEE  RETLW   b'01011010' ;c
    234. xCEE DECFSZ temp2,1
    235. goto xDEE
    236.   DEE  RETLW   b'01101101' ;d
    237. xDEE DECFSZ temp2,1
    238. goto xE
    239.  E RETLW   b'01111010' ;e
    240. xE RETLW   b'01110010' ;f
    241.  
    242.  
    243.  
    244.  
    245.  
    246. ;bit 7DOT bit 6E bit 5G BIT 4A BIT 3D BIT 2B BIT 1F BIT 0C
    247.  
    248.  
    249. PAUSE movlw 0xff
    250.     MOVWF BIGdelay
    251. D250    movlw    0x80
    252.     movwf    delay
    253. l250    decfsz    delay,f
    254.     goto    l250
    255. DECFSZ BIGdelay,f
    256. GOTO D250
    257.     return
    258.  
    259.  
    260.  
    261.  
    262.     end
    263.  
    264.  
    265.  
    266.  
    Dan
     
    Last edited: Sep 3, 2013
Loading...