PIC 18F4520 Indirect Addressing

Author
ELITE
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2011/07/26 11:50:10
  • Location: 0
  • Status: offline
2011/07/26 12:29:16 (permalink)
0

PIC 18F4520 Indirect Addressing

Dear Members

 If someone could help students on this task. The buffer size of 5 bytes filled with 0xFF. In the first location after the end of the buffer register 0x00. Enter the buffer 3,6,12,24. Exit the program loop when it comes to data entered into the buffer, 0x00. I wrote half of the code.This is a PIC 18F4520. I would be grateful if you would be able to help me or give me some advice in regard to solving this task.Thanks and once again I would be grateful if you assist me in this task
post edited by ELITE - 2011/08/22 05:09:35
#1

13 Replies Related Threads

    dan1138
    Super Member
    • Total Posts : 2604
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re:Help with PIC 18F4520 with the task? 2011/07/26 16:07:30 (permalink)
    0
    ELITE

    Dear Members

    If someone could help students on this task. The buffer size of 5 bytes filled with 0xFF.
     
    In the first location after the end of the buffer register 0x00. Enter the buffer 3,6,12,24.
     
    Exit the program loop when it comes to data entered into the buffer, 0x00.
     
    I wrote half of the code. This is a PIC 18F4520.
     
    I would be grateful if you would be able to help me or give me some advice in regard to solving this task.
     
    Thanks and once again I would be grateful if you assist me in this task
         main: 
        LFSR    FSR0, buffer
        movlw   c_buffer_length
        movwf   Loop_counter
        clrf    WREG
       
    main_loop0:
        movlw   0xFF
        movwf   POSTINC0
        decfsz  Loop_counter
        bra     main_loop0
        movlw   0x00


    You have asked for an unreasonable amount of assistance.
     
    What you posted is note even close to on tenth of the code you need.
      
    When you have leaned enough about using the tools perhaps you can be helped.
      
    The next time you post code, post a complete program that can be built using MPLAB 8.73a or later.
      
    There are many examples of complete programs posted in this forum for many of the PIC processors.
      
    There are examples of templates of complete programs in the MPLAB IDE installation directory.
      
    Find these things read them and at least try to show you can learn.
    post edited by dan1138 - 2011/07/26 16:10:58
    #2
    ELITE
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/07/26 11:50:10
    • Location: 0
    • Status: offline
    Re:Help with PIC 18F4520 with the task? 2011/07/26 16:35:56 (permalink)
    0
    Thank you for your criticism and advice. Ali I forgot to say that 3,6,12,24 in the buffer should be written without using Loop_counter. And another thing, since I new to this forum, would you be able to tell me where to find similar solutions in this forum I would be grateful  because the little way around on this forum. I think this can be accomplished using the instructions CPFSGT,CPFSLT or CPFSEQ but I do not know how to do it.
    post edited by ELITE - 2011/07/26 16:49:51
    #3
    dan1138
    Super Member
    • Total Posts : 2604
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re:Help with PIC 18F4520 with the task? 2011/07/26 17:39:30 (permalink)
    0
    The examples you need to find are scattered throughout the messages posted here.
     
    The ones that are easy to find tend to be less helpful.
     
    Part of the process of you learning is to learn to use this forum effectively.
     
    Things you have learned so far today are:
     
    1 - Posting a message.
    2 - Reading a reply.
    3 - Posting a follow up message. 
      
    Some things you still need to learn: 
     
    1 - Reading messages in other threads.
    2 - Searching for messages with key words you are interested in.
    3 - Posting CODE in the correct format, (hint use SPACES not TAB in code).
    #4
    ELITE
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/07/26 11:50:10
    • Location: 0
    • Status: offline
    Re:Help with PIC 18F4520 with the task? 2011/07/29 02:28:36 (permalink)
    0
    I searched online as you told me but I managed to find a solution. I apologize if I'm boring but I really do not know where to find answers for my assignment. I know that's not the point that we do a task than it should, that I do. Would someone be able to me at least some guidance in the form of links where he could find a solution to my task.

    thanks
    #5
    Ian.M
    Super Member
    • Total Posts : 13079
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: online
    Re:Help with PIC 18F4520 with the task? 2011/07/29 04:09:24 (permalink)
    0
    No. the point of a student assignment is that you solve it yourself, or if it is a group one, with the students in your group!  No one here is likely to give you links to a worked solution as no one wants future colleagues or employees who cant  think for themselves.

    Your fragment of code:
         main:
             LFSR    FSR0, buffer
             movlw   c_buffer_length
             movwf   Loop_counter
             clrf    WREG
             
         main_loop0:
             movlw   0xFF
             movwf   POSTINC0

             decfsz  Loop_counter
             bra     main_loop0
             movlw   0x00
    looks reasonable for filling the buffer with 0xFF.  You then need to add a 0x00 at the end of the buffer.  Hint: look at the instruction hilighted in green, think how to use it to always add 0x00 after the last 0xFF


    You then need to reset the buffer pointer again (original hilighted in red)

    I ASSUME that your instructor is not looking for the simplistic solution of simply loading W with each new value as an immediate constant and copying it to the buffer without a loop. If I am wrong that is the simplest method, otherwise write another loop that tests the buffer contents at the current location (no increment). If zero, it exits the loop, otherwise it reads the next new value from a table in program memory, increments the table pointer and copies the value read to the buffer (with postincrement).






    #6
    ELITE
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/07/26 11:50:10
    • Location: 0
    • Status: offline
    Re:Help with PIC 18F4520 with the task? 2011/07/29 05:58:12 (permalink)
    0
    Thanks for all the advice I understand but do not know how to write code.  
           
    #7
    Ian.M
    Super Member
    • Total Posts : 13079
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: online
    Re:Help with PIC 18F4520 with the task? 2011/07/29 06:32:35 (permalink)
    0
    Well you had better learn how to write code.

     Do you have any experience programming in any other microprocessor or microcontroller assembly language? If so, then spending some time with the PIC18C family reference manual's instruction set section should be enough to get you going.

    If you don't, but have experience with just about any procedural programming language (not object oriented ones), there is a good introductory tutorial for the PIC12 and PIC16 which will help you get used to the architecture and to MPASM.  Moving on to the more advanced PIC18 is then just a matter of studying the reference manual for the differences.  Unfortunately I am not aware of any *GOOD* PIC18 assembler tutorials.

    If you have no previous programming experience then you had better get some rapidly!  Even a reasonable level of confidence writing programs in BASIC would be enough to prepare you for the tutorials.

    If you cant tell us what programming experience you have and are unwilling to get some and this assignment is a core part of your course, you had better practice saying "Would you like fries with that?" as you certainly wont be employable as an engineer, technician or programmer! LoL

    If you TRY to write code and post it here, you will get a lot of help with any problems you will have, and we will do our best to direct you to helpful tutorials and to the most relevant and important parts of the datasheets and manuals but if you wont make the effort, I wont be the only one telling you to go and flip burgers.
    #8
    ELITE
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/07/26 11:50:10
    • Location: 0
    • Status: offline
    Re:Help with PIC 18F4520 with the task? 2011/08/04 11:57:08 (permalink)
    0
    Here I wrote in my quest for the care what you think if I did a good job.    
    Main
         lfsr FSR0,buffer
         movlw c_buffer_length
         movwf loop_counter
         clrf WREG
    Main_loop0
         movlw 0xFF
         movwf POSTINC0
         decfsz loop_counter
         bra Main_loop0
         movlw 0x00
         movff WREG,buffer_end
    Main_loop1
         movf 3
         rlncf
         rlncf
         rlncf
         movf INDF0,W
         bra Main_loop1
    Main_loop2
         movlw     high     buffer_end
         cpfseq     FSR0H
         bra          main_loop2
         movlw     low     buffer_end
         cpfseq     FSR0L
         bra        Main_loop2

    I do not know how to write an instruction to rotate the f register. I tried in various ways, so I said let's write the code and what to be. I am grateful for criticism and advice in advance.
    post edited by ELITE - 2011/08/04 12:03:17
    #9
    ELITE
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/07/26 11:50:10
    • Location: 0
    • Status: offline
    Re:Help with PIC 18F4520 with the task? 2011/08/12 05:51:28 (permalink)
    0
    Do I wrote code. What is your of thinking.
    #10
    Ian.M
    Super Member
    • Total Posts : 13079
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: online
    Re:Help with PIC 18F4520 with the task? 2011/08/12 07:03:02 (permalink)
    0
    Why is there a requirement to rotate a mystical 'f' register?  The PIC has many SFRs and GPRs, and the one addressed will be modified if the instruction destination is F.  If the destination is W the result is put in the W register instead.

    Here is a quick summary of the PIC18 rotate instructions:
    • RLCF <addr>, <dest>{, <access>} - 9 bit rotate left (towards MSB) through Carry flag.
    • RRCF <addr>, <dest>{, <access>} - 9 bit rotate right (towards LSB) through Carry flag.
    • RLNCF <addr>, <dest>{, <access>} - 8 bit rotate left (towards MSB). Carry flag not used.
    • RRNCF <addr>, <dest>{, <access>} - 8 bit rotate right (towards LSB). Carry flag not used.
    e.g.
    rrncf LATB, F     ; Rotate number being output on Port B so all bits shift down one place
                      ; and the old LSB becomes the new MSB.

    If you add comments to your code saying what each section is supposed to do, (NOT what each individual line does! wink) you will probably get more help.  Most of us react to a large blob of uncommented code with no explanation with "Oh, how sad - but I'm not volunteering to plow through it.  Next Please!"  Also read "How to ask questions the smart way" to maximize your chances of getting a useful answer quickly and save your time and ours. [8)]
    post edited by Ian.M - 2011/08/12 07:04:34
    #11
    ELITE
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/07/26 11:50:10
    • Location: 0
    • Status: offline
    Re:Help with PIC 18F4520 with the task? 2011/08/12 13:13:41 (permalink)
    0
    Once again the advice and assistance. But I do not know how to rotate the contents of register f. I know that you can always talk to me to be proper to write my question. I apologize for that, but at the moment was important for me to pass the exercise.
    #12
    Ian.M
    Super Member
    • Total Posts : 13079
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: online
    Re:Help with PIC 18F4520 with the task? 2011/08/12 13:59:36 (permalink)
    0
    LATB *IS* a file register.   If your file register is a user variable called f then use rrncf f, F wink
    #13
    ELITE
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/07/26 11:50:10
    • Location: 0
    • Status: offline
    Re:Help with PIC 18F4520 with the task? 2011/08/20 15:21:05 (permalink)
    0
    I think I found how to enroll in a buffer 3,6,12,24. Here are solutions:

        movlw     3
        rlncf     WREG
        rlncf     WREG
        rlncf     WREG
        movwf     POSTINC0

    I am interested in whether the following instructions:

        movff     WREG,buffer_end

    This means that the content WREG transcribed (copied) to the buffer_ end and that means in my quest to rewrite 0x00 (copied) to the buffer_ end

    #14
    Jump to:
    © 2017 APG vNext Commercial Version 4.5