Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 4.82 KB | None | 0 0
  1.         cblock      0x6B
  2.                 COUNT1          ;0x6B
  3.                 COUNT2          ;0x6C
  4.                 COUNT3          ;0x6D
  5.         endc
  6.  
  7. LINECOUNT   EQU     0xEF            ;lookup table line counter register
  8.  
  9. ;****************************************************************************************
  10. ;*                                          *
  11. ;*                     Restore Factory Defaults             *
  12. ;*                                          *
  13. ;****************************************************************************************
  14.  
  15. ;defaults table is located in the top section of this code
  16.  
  17. Restore     movlw       0x00            ;EEPROM start address
  18.         banksel     EEADR           ;bank 1
  19.         movwf       EEADR
  20.         movlw       0x05            ;table start line
  21.         movwf       LINECOUNT
  22.         movfw       LINECOUNT       ;move table line into W
  23.         call        Defaults        ;call defaults table
  24.         movwf       EEDATA          ;move table data into EEPROM Data Register
  25.         call        EEWrite         ;write data to EEPROM
  26.         call        EEVerify        ;verify write
  27.         movlw       0x04            ;was line 4 the last line fetched from table?
  28.         xorwf       LINECOUNT,W
  29.         btfsc       STATUS,Z
  30.         goto        $+19            ;yes, jump line counter to line 9
  31.         movlw       0x0A            ;no, was line 10 the last line fetched from table?
  32.         xorwf       LINECOUNT,W
  33.         btfsc       STATUS,Z
  34.         goto        $+12            ;yes, reset line counter to line 5
  35.         incf        LINECOUNT,F     ;no, increment table line counter
  36.         incf        EEADR,F         ;increment EEPROM read address
  37.         movlw       0x40            ;is address 0x40 next EEPROM write address?
  38.         xorwf       EEADR,W
  39.         btfsc       STATUS,Z
  40.         clrf        LINECOUNT       ;yes, reset table counter to 0
  41.         movlw       0x69            ;no, was address 0x68 last written EEPROM address?
  42.         xorwf       EEADR,W
  43.         btfss       STATUS,Z       
  44.         goto        $-22            ;no, continue restoring defaults
  45.         goto        $+7         ;yes, proceed to exit
  46.  
  47. ;-----------------------------------------------------------------------------------------------------------
  48.  
  49. ;line counter reset routines
  50.  
  51.         movlw       0x05            ;reset line counter to line 5
  52.         movwf       LINECOUNT
  53.         goto        $-12            ;continue restoring defaults
  54.         movlw       0x09            ;set table counter to line 9
  55.         movwf       LINECOUNT
  56.         goto        $-15
  57.  
  58. ;-----------------------------------------------------------------------------------------------------------
  59.  
  60. ;exit sequence
  61.  
  62.         banksel     0x00            ;bank 0
  63.         return                  ;defaults restored, exit
  64.  
  65. ;-----------------------------------------------------------------------------------------------------------
  66.  
  67. ;factory defaults values
  68.  
  69. Defaults    addwf       PCL,F
  70.         retlw       0x00            ;Channel Select Controller Number
  71.         retlw       0x01            ;Lead Boost Select Controller Number   
  72.         retlw       0x02            ;Effects Loop Select Controller Number
  73.         retlw       0xB0            ;Control Change MIDI Channel 1
  74.         retlw       0xC0            ;Program Change MIDI Channel 1
  75.         retlw       b'00010001'     ;Dry Clean (0x11)
  76.         retlw       b'00010101'     ;Wet Clean (0x15)
  77.         retlw       b'00010000'     ;Dry Rhythm (0x10)
  78.         retlw       b'00010100'     ;Wet Rhythm (0x14)
  79.         retlw       b'00010010'     ;Dry Lead (0x12)
  80.         retlw       b'00010110'     ;Wet Lead (0x16)
  81.  
  82. ;****************************************************************************************
  83. ;*                                          *
  84. ;*                EEPROM Functions                  *
  85. ;*                                          *
  86. ;****************************************************************************************
  87.  
  88. EEWrite     bcf     INTCON,GIE      ;disable all interrupts
  89.         bsf     EECON1,WREN     ;enable EEPROM write mode
  90.         movlw       0x55            ;write unlock codes (required sequence)
  91.         movwf       EECON2
  92.         movlw       0xAA
  93.         movwf       EECON2
  94.         bsf     EECON1,WR       ;initiate write to EEPROM
  95.         btfsc       EECON1,WR       ;is write complete?
  96.         goto        $-1         ;no, check again
  97.         bcf     EECON1,WREN     ;disable EEPROM write mode
  98.         banksel     PIR1            ;bank 0
  99.         bcf     PIR1,EEIF       ;clear EEPROM write interrupt flag
  100.         bsf     INTCON,GIE      ;enable all unmasked interrupts
  101.         banksel     0x80            ;bank 1
  102.         return
  103.  
  104. ;****************************************************************************************
  105.  
  106. EEVerify    bcf     INTCON,GIE      ;disable all interrupts
  107.         movfw       EEDATA          ;copy data to be verified into W
  108.         bsf     EECON1,RD       ;initiate EEPROM read
  109.         xorwf       EEDATA,W        ;compare EEPROM data to data in W
  110.         btfss       STATUS,Z        ;are they the same?
  111.         call        WriteErr        ;no, indicate write error
  112.         bsf     INTCON,GIE      ;enable all unmasked interrupts
  113.         return
  114.  
  115. ;****************************************************************************************
  116.  
  117. ;illuminate Learn LED for 1/2 second to indicate EEPROM Write Error condition
  118.  
  119. WriteErr    bcf     LRN_LED        
  120.         call        Delay_500mS
  121.         bsf     LRN_LED
  122.         return
  123.  
  124. ;****************************************************************************************
  125. ;*                                          *
  126. ;*                     Delay Loops                      *
  127. ;*                                          *
  128. ;****************************************************************************************
  129.  
  130. ;50mS Delay
  131.  
  132. Delay_50mS  movlw       0xFF
  133.         movwf       COUNT1
  134.         movwf       COUNT2
  135.  
  136.         decfsz      COUNT1,F
  137.         goto        $-1
  138.         decfsz      COUNT2,F
  139.         goto        $-3
  140.         return
  141.  
  142. ;****************************************************************************************
  143.  
  144. ;500mS Delay...run Delay_50mS 10 times
  145.  
  146. Delay_500mS movlw       0x0A
  147.         movwf       COUNT3
  148.         call        Delay_50mS
  149.         decfsz      COUNT3,F
  150.         goto        $-2
  151.         return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement