Search This Blog

Sunday, January 24, 2010

16F88 - A Pernicious Feature

    I really hope this helps someone.  I had been working happily with a 16F84A for a while and was getting pretty confident.  I ordered a 16F88 and began to wade my way through all the additional configuration settings.  I was anxious to take advantage of all the freed up pins with the internal oscillator and MCLR pin.  I just couldn't get it to work.  I dropped back to just turning on an led.  That actually worked.  But nothing else would even make a flicker.  The code was compiled with gputils and loaded with picp and a PicStart Plus.  After slowly adding bits to the basic "turn on the led" code and looking at the generated and written hex files, I made an interesting discovery.  I had been setting up the first few lines of the program like this:

;******************************************************************************
;  RESET VECTOR                                                               *
;******************************************************************************
      ORG     0x000             ; processor reset vector
      nop
      goto    main              ; go to beginning of program

;******************************************************************************
;  INTERRUPT VECTOR                                                           *
;******************************************************************************
      ORG     0x004             ; interrupt vector location
        ; standard interupt code here

If I put 3 nops in the reset code in addition to the goto, my programs ran!  I'm still not sure what is going on here.  The generated and written hex code look correct.  The practical conclusion:  Make sure that your ORGs line up with the lines of code you have.  I shudder to think what will happen if I want to force a new page for a section of code to keep it from spanning two pages...  We'll cross that bridge when we get to it.  Hopefully, my bootloader code and accompanying PC code will not have the same issue.  I hope it is just an odd issue with either the compiler or the programming software.  It is also odd that I don't see this with the 16F84A.

No comments:

Post a Comment