PIC 18F anomaly!

Discussion in 'Programmer's Corner' started by MaxHeadRoom, Jan 2, 2015.

  1. MaxHeadRoom

    Thread Starter Expert

    Jul 18, 2013
    Migrating to the 18Fx3K22 from the 18f2221 I thought would be easy, after 2 days frustration I found out why I could not set the I/O ports, I eventually did a web search and Voilà found it, may help someone else.
    clrf ANSELA
    clrf ANSELB
    clrf ANSELC
    clrf CM1CON0
    Did not work in the usual way, after replacing this with the movff instr. it works.
    clrf WREG
    movff WREG, ANSELA
    movff WREG, ANSELB
    movff WREG, ANSELC
    movff WREG, CM1CON0
    Found in the manual. (it helps to read it!)

    Note 1: Addresses F38h through F5Fh are
    also used by SFRs, but are not
    part of the Access RAM. Users
    must always use the complete
    address or load the proper BSR
    value to access these registers.
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    This bit me before a few years ago. It pays to read the datasheet each time you use a new part. In this case, they had "too many" special function registers to fit in access RAM. At a minimum, I peruse the SFR table and the port pin description table. This keeps me out of trouble, generally.