Simple register move won't work (movf)

Author
PICME
Senior Member
  • Total Posts : 156
  • Reward points : 0
  • Joined: 2007/03/25 11:45:33
  • Location: Northern Indiana
  • Status: offline
2007/05/14 16:30:18 (permalink)
0

Simple register move won't work (movf)

 
I give up... H E L P!
 
I've spent 7 full days just trying to get microchips EEPROM demo code to work.  Like virtually all their other demo code, it DOESN'T!!!  I have read every related document 10 times and modified the code to initialize interrupts so the sleep instruction works. that was a hint from another forum that microchip forgot to mention.  Sorry BABBELING is a symptom brought on by BAD DOCUMENTATION.
 
Please look at these two attempts to simply move the contents of the location ‘DATA_EE_DATA’   to the SFR   ‘EEDAT’
 
I am working with PICkit2 and the 16F690 LPC Demo Board.  If I could understand why this simple movf doesn't work, half the battle would be over. 
 
NOTE: DATA_EE_DATA contains a hex number in the range of 0x11 to 0xFF
 
Clues for the Clueless Please!!!  Thanks!
 
If you have a snippit of demo code that WORKS and writes to internal EEPROM that would be great also!
 
 
BANKSEL EEDAT                  ; Supposedly the correct way to load the w register then save it to SFR EEDAT (doesn't work)
movf      DATA_EE_DATA, 0   ; 0 = save result to the WREG
movwf    EEDAT                  ; remains 0x00 after execution. 
 
 
BANKSEL EEDAT                   ; I accidentally coded this (movfw) and MPASM bought it, an invalid instruction!
                                        ; (EEDAT = 0 after execution)  Is or Was 'movfw' a valid (unlisted) instruction?
movfw    DATA_EE_DATA 
movwf    EEDAT  
 
 

 

#1

17 Replies Related Threads

    isa.guru
    Super Member
    • Total Posts : 1703
    • Reward points : 0
    • Joined: 2003/12/19 13:15:38
    • Location: America's finest city
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/14 16:44:53 (permalink)
    0
    Hi,
     
    First movfw is not an invalid but an excellent instruction (macro) as many others like
    clrc, setc, skpc, skpnc, skpz, skpnz, bc, bnc, bz, bnz, ..... and other. Those are macros built-in MPASM and I have been usinf them sinse the very beginnig I switched to mostly PICs (1994).
     
    Second: try not to use 0 or 1 but W and nothing. I never remebered which was 1 and which zero, and I do not care. Just write
     
    movfw DATA
    movwf EEDAT
     
    BUT !!!!, make sure both are in the same bank.
     
    I do not know the demos, never used one, but the reason I love uChip products is the very good quality of the hardware and datasheets.
     
    So just learn, ask, try and learn again.
     
    Regards

    7th dan instrumentation and controls
    #2
    stumichaels
    Super Member
    • Total Posts : 543
    • Reward points : 0
    • Joined: 2007/03/13 21:03:10
    • Location: Commack, NY
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/14 16:50:26 (permalink)
    0
    Hi isa.guru,
     
      Where can I find the list of the macros built into MPASM?  I search the manual and can't find them.
     
    Thanks,
    Stu
    post edited by stumichaels - 2007/05/14 16:51:40
    #3
    bob_barr
    Super Member
    • Total Posts : 5428
    • Reward points : 0
    • Joined: 2003/11/07 12:35:23
    • Location: Morgan Hill, CA
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/14 16:51:51 (permalink)
    0
    Are you sure that the 'EEDAT' SFR and the variable 'DATA_EE_DATA' are both in the same bank?
     
    I can't vouch for the EEPROM read and write routines in every datasheet but they do work in all of the ones that I've seen.
     
    The 'movfw' is a MPASM pseudo-instruction which generates a 'movf xxx, w' instruction. I never (deliberately, at least) use it since it's so easy to mix up 'movfw' and 'movwf'. If doing 'Find in Files' detects a 'movfw' anywhere in my code, I know that it's a mistake.
     

    While it's always good to learn from one's mistakes, it's much easier to learn from the mistakes of others.
    Please don't PM me with technical questions. I'll be quite happy to help (if I can) on the forums.
    #4
    bob_barr
    Super Member
    • Total Posts : 5428
    • Reward points : 0
    • Joined: 2003/11/07 12:35:23
    • Location: Morgan Hill, CA
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/14 16:55:11 (permalink)
    0
    Second: try not to use 0 or 1 but W and nothing. I never remebered which was 1 and which zero, and I do not care. Just write

    movfw DATA
    movwf EEDAT

    I'd suggest using:

        movf   DATA, w
    and
        movwf EEDAT

    'movwf and 'movfw' are just to easy to type incorrectly.

    While it's always good to learn from one's mistakes, it's much easier to learn from the mistakes of others.
    Please don't PM me with technical questions. I'll be quite happy to help (if I can) on the forums.
    #5
    isa.guru
    Super Member
    • Total Posts : 1703
    • Reward points : 0
    • Joined: 2003/12/19 13:15:38
    • Location: America's finest city
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/14 17:04:17 (permalink)
    0
    I am sure they are in the documentation, I think in MPLAB help as well. I will send you a link

    7th dan instrumentation and controls
    #6
    ric
    Super Member
    • Total Posts : 22101
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/14 17:04:34 (permalink)
    0
    ORIGINAL: stumichaels
    Where can I find the list of the macros built into MPASM?  I search the manual and can't find them.

    MPLAB online help.
     
    Ver 5.7 "Help", "MPASM assembler help", "Instruction sets", "14 bit core instruction set", "12-Bit/14-Bit Core Special Instruction Mnemonics"
     
    Ver 7.x "Help", "Topics...", "MPASM Assembler", "Reference", "Instruction Sets", "12-Bit/14-Bit Instruction Width Pseudo-Instructions"

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    stumichaels
    Super Member
    • Total Posts : 543
    • Reward points : 0
    • Joined: 2007/03/13 21:03:10
    • Location: Commack, NY
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/14 19:26:38 (permalink)
    0
    Ric,
       Thanks.  I didn't realize that they were for 12/14 bit processors.  I could have used them last year.  Now I'm using the 18F series; most of those macros are built-in instructions in the 18F.
     
    Regards,
    Stu
    #8
    dchisholm
    Super Member
    • Total Posts : 3805
    • Reward points : 0
    • Joined: 2003/12/14 15:30:12
    • Location: St Louis Mo
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/14 20:15:32 (permalink)
    0
    ORIGINAL: PICME

     I've spent 7 full days just trying to get microchips EEPROM demo code to work.  Like virtually all their other demo code, it DOESN'T!!! . . .
     
    If you have a snippit of demo code that WORKS and writes to internal EEPROM that would be great also! 
    Hello Doug

    In a Different Context I recently posted some code for accessing the EEPROM on a 16F690.  The order of instruction execution is directly from a current project - in fact, I observed the EEPROM store/retrieve routines work just this afternoon.  I did, however, change the variable names to make the post a little easier to read.

    I have often blatantly plagiarized Microchip's sample code directly into my projects with excellent results. 

    Dale
    #9
    PICME
    Senior Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2007/03/25 11:45:33
    • Location: Northern Indiana
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/14 20:19:44 (permalink)
    0
    Thanks for the responses!

    I just started using PICs about 6 weeks ago.  I believe they have tremendous potential once one has paid their ‘dues’ (hope it’s a short process). 

    I had seen macros mentioned but dismissed them as something that I could deal with in a few months.  I have been writing quite a bit of code to experiment with all the peripherals in the '690.  Everything was going along very nicely till I tried to write to the internal EEPROM.  Microchip’s demo failed to mention the need to enable a PIE2 Interrupt and check a PIR2 register.  Another group pointed that out.

    I have run into MANY problems getting the microchip demos to run on the '690.  I get the feeling they would like to abandon it (hope not).  I understand there is another demo board that uses the '917 and now ships with the '887 which has had most of its demo code and manual rewritten.  From what I can ascertain, everything works better with that setup.  I am going to buy it and the white serial monitor device in a week or so.

    Still I think the '690 is a cool chip for small footprint projects and I wish to continue learning how to exploit its riches.

    The two memory locations aren’t in the same bank, one is a SFR address (EEDAT) and the other is a GPR address (DATA_EE_DATA) in another bank.  The dufus who wrote this failed to realize they were in different banks.  I think I'm going to go fix this before I turn in so I don’t have nightmares!

    The macro thing about MOVFW will be something I will look up tomorrow.  I thought I had successfully used it before but wasn't certain.  It kinda’ goes hand in hand with it's counterpart MOVWF.

    Thanks to everyone, I'm sorry I didn't ask earlier!

    Doug
    post edited by PICME - 2007/05/14 20:29:30

    Doug Ferguson KB9MIC
    #10
    atferrari
    Super Member
    • Total Posts : 1379
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/15 02:22:56 (permalink)
    0
    I recall reading somewhere that those macros which come from the times of the 16C57 would be finally discontinued (could they do?) or users were being simply discouraged to use them in the future.
     
    From my part I decided not to use them long time ago and don't miss them in any way.
     
    That MOVFW, I didn't know it even existed. (!!!)

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #11
    PICME
    Senior Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2007/03/25 11:45:33
    • Location: Northern Indiana
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/15 13:49:46 (permalink)
    0
    Krazie Kode!!!
     
    Wow, what an initation ritual!  I found the problem but it makes absolutely no sence to me.  Please take a look and tell me why 1 BANKSEL instruction broke the code.  This is an slightly altered version of microchips internal EEPROM write demo code.  When I commented out the ofending line, the entire program worked perfect.  Look for the following line below
     
    ;#######################################################################
    ; BANKSEL EECON1 <===THIS BANKSEL PREVENTS EEPROM FROM WRITING *and* causes
    ; other BIT TESTS to fail farther down stream.     
    ;####################################################################### 

     
     
     
     
    WriteToEEProm:                       ; writes data to EEPROM from 00 to FF
     
     BANKSEL DATA_EE_ADDR   
     movfw  DATA_EE_ADDR              ; first pass is 0 then incremented before leaving this routine.
     BANKSEL EEADR  
     movwf  EEADR                           ; Data Memory Address to write
     
     BANKSEL DATA_EE_DATA 
     movfw DATA_EE_DATA                ; put live data in DATA_EE_DATA before calling this 'WriteToEEProm'.
     BANKSEL EEDAT 
     movwf  EEDAT                           ; Data Memory Value to write
     
     BANKSEL EECON1                           ; block3 this BANKSEL doesn't cause problems
     BCF  EECON1, EEPGD                     ; bit7 - 1= access program memory  0= access data memory
     BSF  EECON1, WREN                       ; bit2 - 1= Enable writes
     BCF  INTCON, GIE                          ; Disable Interrupts Globally
     
     BANKSEL EECON2                           ; block3 this BANKSEL doesn't cause problems
     MOVLW  0x55                                 ; was 55h
     MOVWF  EECON2                           ; Write 55h - NOTE: EECON2 is not a physical register.
     MOVLW  0xAA  ; was AAh
     MOVWF  EECON2                           ; Write AAh - NOTE: EECON2 is not a physical register.
     
    ;#######################################################################
    ; BANKSEL EECON1 <===THIS BANKSEL PREVENTS EEPROM FROM WRITING *and* causes
    ; other BIT TESTS to fail farther down stream.     
    ;####################################################################### 
     BSF  EECON1, WR                ; bit1 - '1' starts write cycle and is cleared to '0' when complete
     BANKSEL PIE2                     ; page1
     bsf PIE2, EEIE                     ; Enable EE write operation interrupt enable bit4.
                                             ; see page 28 of 16F690 data sheet.  this is NOT DOCUMENTED in
                                             ; the EEPROM section which starts on page 105.
     BANKSEL INTCON
     BSF  INTCON, GIE                   ; Enable Global Interrupts
     
    ;---------------------------------------------------------------------------------
    ;    I tested this after correcting the BANKSEL issue
    ;    and it still hangs up but may not be needed. needs
    ;    investigation.
    ;
    ;*** SLEEP was a PROBLEM **** 
    ; SLEEP                                   ; Wait for interrupt to signal write complete
    ; btfsc EECON1, WR                   ; Wait till bit is cleared, signaling write operation is complete
    ; goto  $-1
    ;---------------------------------------------------------------------------------

    ;###### W I S D O M ###################################################### 
     
    ; this BTFSS section is enabled and works perfectly in another EEPROM TEST DEMO I wrote
    ; here it HANGS EVERY TIME and I don't know why!
    ;
    ; the problem was the BANK SELECT FROM HELL above.  When I commented it out, this
    ; bit test worked just fine and the entire program ran perfectly.
     
     BANKSEL PIR2                       ; page1
     btfss PIR2, EEIF                    ; EEIF is automaticly set when write has completed.
                                              ; must check and clear this bit.  This IS briefly mentioned
                                               ; on page 105 see 10.1.1 near bottom.
          
     goto $-2                               ; wait till write cycle is complete and clears EEIF

    ;###################################################################### 

     bcf PIR2, EEIF                        ; write cycle is finished so clear this bit, done sleeping.
            
     BANKSEL PIE2
     bcf  PIE2, EEIE                       ; write completed and sleep terminated so disable EEPROM
                                               ; interrupts till next round
            
     BANKSEL EECON1                      ; page3   
     BCF  EECON1, WREN                 ; Disable writes, this helps prevent memory corruption
      
     bcf STATUS, C
     BANKSEL DATA_EE_ADDR
     incf DATA_EE_ADDR,F                ; EEPROM address pointer 16F690 is 0x00 to 0xFF
     btfsc STATUS, C
     goto Start                                ; EEPROM is FULL - Go start it all over again
            
     BANKSEL DATA_EE_ADDR
     movfw DATA_EE_ADDR
     BANKSEL EEADR 
     movwf EEADR                            ; set up for next data save
     
     
     bcf STATUS, C                          ; clear carry bit
     clrw
     clrf DATA_EE_DATA                     ; cleared - now ready to store new timming data
     
     BANKSEL PORTB                           ; hang here till bit clears
     btfsc PORTB,4                              ; if PORTB,4 is still high, wait for new falling edge (0x00)
     goto $-1   
     
     return                                         ; falling edge was detected, go back and capture next pulse
     
     

    Doug Ferguson KB9MIC
    #12
    bob_barr
    Super Member
    • Total Posts : 5428
    • Reward points : 0
    • Joined: 2003/11/07 12:35:23
    • Location: Morgan Hill, CA
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/15 15:13:55 (permalink)
    0
    The 'bsf EECON1, WR' instruction must immediately follow writing the 'magic sequence'. Even a 'nop' instruction will prevent the EEPROM from being written. (This is also the reason that the ICD2 cannot be used to single-step through the EEPROM write sequence. Intervening instructions being executed will disable the write enable.)

    While it's always good to learn from one's mistakes, it's much easier to learn from the mistakes of others.
    Please don't PM me with technical questions. I'll be quite happy to help (if I can) on the forums.
    #13
    PICME
    Senior Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2007/03/25 11:45:33
    • Location: Northern Indiana
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/15 17:51:57 (permalink)
    0
    Is there a place or document I could look at that might list general issues to watch out for regarding the 16F devices?.  I hope to avoid similar marathon troubleshooting sessions.  I'm thinking about having this one tatooed on my forehead :)

    Doug Ferguson KB9MIC
    #14
    ric
    Super Member
    • Total Posts : 22101
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/15 18:14:13 (permalink)
    0
    I don't think the datasheet could be any more explicit on pointing out that requirement....
     


    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #15
    PICME
    Senior Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2007/03/25 11:45:33
    • Location: Northern Indiana
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/15 20:27:52 (permalink)
    0
    Ric,

    Well everything is wide open to interpretation with microchips demos.  I my functional code was exactly as shown my error was I BANKSELECTED when I should have went for coffee.  BANKSELECTING is virtually always okay to do even if it's not needed.  Clearly microchip's agenda in writing demos is to not spare one extra word in explaining anything.  Most documentation is as concise as humanly possible leaving one with more questions than they originally had. 

    My secondary agenda to learning how to use these devices is to convince microchip it is to their advantage to produce more than the absolute minimum documentation and pay close attention to detail.  Most every demo I have encountered is written for the seasoned programmer.  microchip documentation ASUMES you already are familiar with programming with their tools, hardware and PICs, this methodology is more convenient for you seasoned microchip designers. 

    Demos should embody the full scope of the issue at hand to include mentioning anything that might be related to making the target demo work.  Things like linker issues, memory assignment issues, the __CONFIG line, peripheral interaction problems, etc...  Don't throw demos out there that cannot possibly work!!!  It will take some time to clean this up but in the end I promise to begin capitalizing the M in microchip and speaking in a much more favorable tone.  The flip side is people will quit sucking up because it is politically correct and be able to truly commend the company for supplying better than marginal information.  I have never seen a microchip document with a document revision history for updates and corrections.

    I come from an era (mid-seventies) when every data book you picked up was F U L L of rock solid reliable information.  I can tell you for a fact, I never once called a manufacturer for info about a chip, didn't need to it was ALWAYS right there in black and white,  complete and accurate in every respect.  I want this corporate attitude to change globally and I am willing to assist microchip and other corporations in making better choices!.  I've had it with the attitude of 'get it out the door, we'll fix it later', which may or may not partially happen.  

    MY ERROR in interpretation of the instructions is a DIRECT RESULT of having to dig all over many documents to try to form a functional picture of what is suppose to be happening.  Throw into the mix.. typos, omissions and blatantly dead code and you have a real mess for a new customer buying into microchip PIC systems.  I can't wait to learn it all and really start producing great code.  I already have my eye on microchips better tools and programmers but I am not beyond throwing the whole mess in the river and making another choice. 

    I received my programmer and PIC’s, etc around the first of April (roughly 6 weeks ago), before then I have never messed with PIC’s, only MPU's.  I've learned a great deal about these tools, hardware and PIC’s and can see where all you super users would think it's all so elementary, you know where all the 'mines' are laid.

    Sub-standard documentation creates a kind of paranoia in that one eventually comes to expect hidden problems and begins looking for them where there are none.  This then only makes bad situation worse.

    microchip has some GREAT products and tools and I look forward to becoming proficient with a good chunk of it all.  I guarantee you I will be a voice for change on the documentation issues,  that sir you can take to the bank.

    If you promise to keep it just between us, yes I have been known to make a mistake or thirty ;)  Thanks for everyone’s help, without it there would be no newbies.

    J DOUGLAS FERGUSON

     
     
    post edited by PICME - 2007/05/15 21:13:01

    Doug Ferguson KB9MIC
    #16
    K8LH
    Super Member
    • Total Posts : 1872
    • Reward points : 0
    • Joined: 2004/03/26 05:12:34
    • Location: Michigan, USA
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/16 04:08:39 (permalink)
    0
    Doug (grumpus maximus):

    The learning curve can look more like a learning mountain when you jump into microcontroller development. 

    You should be very proud of how you've managed to work through a mountain of documentation and use sophisticated new tools in just six weeks.  Hopefully you're humble enough to realize there's still alot to learn.

    You're intelligent and you're not afraid to learn and to work through problems.  If you can look at this as a wonderful and exciting new adventure and experience, you're gonna be a guru in no time (grin).

    Take care. Have fun.

    Mike
    post edited by K8LH - 2007/05/16 04:09:39
    #17
    PICME
    Senior Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2007/03/25 11:45:33
    • Location: Northern Indiana
    • Status: offline
    RE: Simple register move won't work (movf) 2007/05/16 06:34:42 (permalink)
    0
    Thanks for the sentiment Mike.  If you knew me you'd know I am adamant about not banging my own drum.  I only did that to make a point.  I liked your tag (grumpus maximus) it is right up there with another favorite that always gives me a chuckle when I think of it (whiner). 
     
    I hope everyone sees beyond the obvious, this is not about me.  It's about a deficiency that I feel needs attention.  In the end I would hope for some improvement, which would benefit everyone including microchip.
     
    I don't have my database up, have we worked?
     
    Doug KB9MIC
     

    Doug Ferguson KB9MIC
    #18
    Jump to:
    © 2018 APG vNext Commercial Version 4.5