title: Implementing Lookup Table in PIC16F1782
body: <p>I'm Using PIC16F1782 and trying to implement a retlw lookup table. I've written this code relating to <strong>microchip AN556 (Implementing a Table Read)</strong> But is doesn't work. I've simulated this code using <strong>MPLAB X IDE v3.05</strong> and found that <strong>MOVLW HIGH IF_TABLE</strong> puts 0x80 to the WREG that seems to be wrong. Then PC would get a wrong value and when I call IF_TABLE, the program goes to a wrong place. I would appreciate it if you could help me.</p>
  
  <pre><code>ORG 0H
  GOTO MAIN
  ;simple ISR for TIMER0 OverFlow
  ORG 0004H
  BTFSS INTCON,2
  RETFIE
  MOVLW 0X01
  XORWF PORTA,F
  BCF INTCON,2
  RETFIE
  
  
  MAIN
  ;OSCON,DACCON and portA configurations
  BANKSEL OSCCON
  MOVLW B'11110000'
  MOVWF OSCCON
  BANKSEL DACCON0
  MOVLW B'10110000'
  MOVWF DACCON0
  BANKSEL OPTION_REG
  MOVLW B'10000001'
  MOVWF OPTION_REG
  BANKSEL INTCON
  MOVLW B'10100000'
  MOVWF INTCON
  BANKSEL TRISA
  BANKSEL PORTA ;
  CLRF PORTA ;Init PORTA
  BANKSEL LATA ;Data Latch
  CLRF LATA ;
  BANKSEL ANSELA ;
  CLRF ANSELA ;digital I/O
  BANKSEL TRISA ;
  MOVLW B'00000000'
  MOVWF TRISA
  BANKSEL PORTA
  BSF PORTA,0
  
  CLRF 0X27
  CLRF 0X28
  ;the problem is in RPT loop
  RPT:
  
  MOVF 0X27,W
  MOVWF 0X28
  MOVLW LOW IF_TABLE
  
  ADDWF 0X28,F
  
  MOVLW HIGH IF_TABLE
  BTFSC STATUS,C
  ADDLW 1
  
  MOVWF PCLATH
  
  MOVF 0X28,W
  
  CALL IF_TABLE
  
  BANKSEL DACCON1
  MOVWF DACCON1
  
  INCF 0X27,F
  
  GOTO RPT
  
  
  IF_TABLE:
  
  MOVWF PCL
  RETLW D'126'
  RETLW D'128'
  RETLW D'131'
  RETLW D'136'
  .
  .
  .
  END
  </code></pre>