12F683 INDF register

Author
magic_man185
Starting Member
  • Total Posts : 52
  • Reward points : 0
  • Joined: 2009/04/24 14:14:20
  • Location: 0
  • Status: offline
2011/09/02 08:31:34 (permalink)
0

12F683 INDF register

I am trying to use the INDF register with FSR to receive 13 bytes over RS232 into a receiving buffer and then save those bytes to EEPROM. When I run my code, the send and receive works properly (I am using PicKit2 UART tool in Hex mode, it is weird that without the save routine my code works fine, with the save routine it puts the last two bytes on a separate RX: line in the UART tool, but I don't think that is an issue). The data is not getting saved to EEPROM properly. The data is shifted one byte later in the buffer (first byte is stored to 0x51 instead of 0x50) and the last byte wraps around to 0x50. From what I can tell my code is setup properly, but maybe I am missing something. Can anyone offer an insight?

My code is below, MODE = 0x50, I have 50-5C as the RX buffer.

 Process232 
btfss PROC232,RXCHAR ;character available in RX?
goto Process232
bcf T2CON, TMR2ON ;turn off timer2
bsf FLAGS2, CONFIGCOUNT ;tells routine that this it is the first byte
movlw 0x0D
movwf BYTECOUNT
movlw MODE
movwf PTR ;initialize pointer
movwf FSR
GetByte
call RX232
movwf INDF
call TX232
incf PTR, W ;increment memory point to point to ext rx byte location
movwf PTR ;setup indirect reference
movwf FSR
decfsz BYTECOUNT ;skip loop if all bytes are received
goto GetByte
movlw MODE
movwf PTR
movlw 0x0D
movwf BYTECOUNT
SaveByte
bcf INTCON, T0IE
bcf INTCON, GPIE
movf PTR, W
movwf FSR
movwf EEADDRESS
movf INDF, W
call WriteEE ;write byte to EEPROM
incf PTR, f ;increment memory pointer
decfsz BYTECOUNT
goto SaveByte
movlw 0x0D
movwf BYTECOUNT
movlw MODE
movwf PTR
bsf T2CON, TMR2ON ;turn on timer2
bsf INTCON, T0IE
bsf INTCON, GPIE
goto Process232


;******************************************************************
;******************************************************************
;
; TX232 - enter with character to be sent in W
;
TX232 btfsc PROC232,TXFLAG ;TX in progress?
goto TX232 ;yes, branch and wait
movwf TXVAR ;stuff character
movlw b'00001011' ;
movwf TXCNT ;set TX bit count
bsf PROC232,TXFLAG ;initiate TX
return ;

;******************************************************************
;
; RX232 - exit with received character in W
;
RX232 btfss PROC232,RXCHAR ;character available flag?
goto RX232 ;no, loop
movf RXVAR,W ;yes, get character
bcf PROC232,RXCHAR ;clear flag
return ;

            ;*************************************************************

WriteEE
    bsf     STATUS  , RP0
    movwf    EEDAT            ;move W to write register
    bcf    STATUS    , RP0
    movf    EEADDRESS, w        ;choose memory location
    bsf    STATUS    , RP0
    movwf    EEADR
    bsf        EECON1,WREN         ;Enable write
    bcf        INTCON, GIE         ;Disable INTs
    btfsc    INTCON, GIE         ;See AN576
    goto    $-2
    movlw     0x55                 ;Unlock write
    movwf     EECON2
    movlw     0xAA
    movwf     EECON2
    bsf     EECON1, WR             ;Start the write
WaitForEEWrite
    btfsc   EECON1, WR            ;wait for hardware to clear (done writing)
    goto    WaitForEEWrite
    bcf     STATUS    , RP0        ;Bank0
    bsf     INTCON, GIE         ;Enable INTS
    bcf        EECON1, WREN        ;Disable write
    return
            ;*************************************************************
post edited by magic_man185 - 2011/09/02 22:10:45
#1

3 Replies Related Threads

    kl27x
    Super Member
    • Total Posts : 232
    • Reward points : 0
    • Joined: 2006/09/20 13:51:48
    • Location: 0
    • Status: offline
    Re:12F683 INDF register 2011/09/06 14:50:28 (permalink)
    0
    What does "movlw MODE" do?
    #2
    wa1vgb
    Super Member
    • Total Posts : 978
    • Reward points : 0
    • Joined: 2011/07/08 12:10:39
    • Location: Which way to East Vassalboro
    • Status: offline
    Re:12F683 INDF register 2011/09/06 17:36:21 (permalink)
    0
    The program loops, so my guess is:

       The 1st character is noise on the RS232 line, then the desired data is shifted by one place in the buffer.  The program loops and the last character gets stored in the beginning of the buffer overwriting the 1st garbage character.

    The movlw loads the address of the buffer into a pointer.  The buffer is apparently called MODE.
    #3
    magic_man185
    Starting Member
    • Total Posts : 52
    • Reward points : 0
    • Joined: 2009/04/24 14:14:20
    • Location: 0
    • Status: offline
    Re:12F683 INDF register 2011/09/06 17:57:44 (permalink)
    0
    I actually have resolved this issue.  I was using the Pickit2 UART tool to test, with the chip installed in the programmer.  With the UART tool you have to power the chip, then hit connect.  The error was because between the time the power was applied and I hit connect, the pic Rx line was not held high, so when I hit connect the line going high was seen to the pic as the first byte.  Therefore when I transmitted it started with the second byte, and when my counter hit 0x0D, it circled back around to 0x50.
    #4
    Jump to:
    © 2017 APG vNext Commercial Version 4.5