Trying to learn Assembly


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2009
    Posts
    7

    Default Trying to learn Assembly

    I've been using PBP3 for awhile now, but I'm trying to learn simple Assembly routines.
    To start, it seemed wise to learn how to just configure a port for digital I/O, and set a few pins HI.
    My breadboard has a 16F1518 and I have great control of the pins using PBP3, ie, yes the outputs are all good.
    But I must be missing something when doing the same with Assembly.
    Page 106 of the 16F1518 manual shows how to configure ANSEL and TRIS for port A and placing their routine within a PBP3 program compiles without issue.

    asm

    BANKSEL PORTA ;
    CLRF PORTA ;Init PORTA
    BANKSEL LATA ;Data Latch
    BANKSEL ANSELA ;
    CLRF ANSELA ;digital I/O
    BANKSEL TRISA ;
    MOVLW B'11100001' ;Set RA<4:1> as outputs, the rest inputs
    MOVWF TRISA
    MOVLW B'00011110' ;Set RA<4:1> HI
    MOVWF PORTA


    endasm

    I added the last 2 lines, ie move literal to W and then move W to the file register hoping to see the pins A1-A4 go HI.
    But it didn't work. The problem must be with moving the config data to the port.

    Does anyone know what I am doing wrong here? I've been searching the web for ideas and it seems I'm doing things correctly by what I'm finding but this routine isn't working.
    Any help would be appreciated.

    Ed

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Trying to learn Assembly

    The problem must be with moving the config data to the port.


    Code:
     MOVLW B'00011110' ;Set RA<4:1> H
     BANKSEL LATA    
     MOVWF LATA
    Warning I'm not a teacher

  3. #3
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Trying to learn Assembly

    You did a BANKSEL TRISA and configured that register, then you loaded W and tried to shove it into PORTA register without resetting the Bank Select Register. TRISA is in BANK 1 while PORTA is in BANK 0. Without selecting BANK 0 with "BANKSEL PORTA" you simply wrote over your TRISA; TRISA & PORTA share the same Register address, though in different Banks.

    BANKSEL PORTA
    MOVLW B'00011110
    MOVWF PORTA

  4. #4
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Trying to learn Assembly

    Got to thinking after posting, I gave you an answer, but didn't share any knowledge.

    In the Data Sheet there is a section called 3.0 Memory Organization. On page 23, Table 3.3 shows where SFR are stored; both Bank# and Address#. You should be able to look at that Table and see PORTA located in BANK 0 at address 000Ch. Next row in BANK 1 you see TRISA at address 008Ch, but the same position within the BANK. Next you can see TRISA in the same position in BANK 2.

    Using BANKSEL is a shortcut that allows the Compiler to find the proper BANK for you. In the Instruction Summary, Section 24, Table 24-3 lists the Assembly Instructions applicable to this PIC. Towards the bottom under the heading Literal Operations is the command MOVLB. If you know TRISA is in BANK 1 you can:

    MOVLB 0x01

    Page 272 shows the expanded explanation of MOVLB.

    I hope this helps you better understand how the Banking system works (at least in the PIC family).

Similar Threads

  1. How/where to learn Assembly?
    By HankMcSpank in forum General
    Replies: 6
    Last Post: - 9th August 2011, 18:40
  2. How do you learn best?
    By T.Jackson in forum Off Topic
    Replies: 41
    Last Post: - 30th May 2008, 15:32
  3. How to learn assembely?
    By amindzo in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 26th May 2007, 22:23
  4. Who wants to learn...
    By Stoverus in forum Off Topic
    Replies: 1
    Last Post: - 21st October 2006, 08:08
  5. Trying to learn the tricks of the trade
    By Rhatidbwoy in forum mel PIC BASIC
    Replies: 1
    Last Post: - 16th October 2005, 20:41

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts