PIC 18F instructions

Discussion in 'Programmer's Corner' started by Dritech, Feb 10, 2012.

  1. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi all,

    Can someone tell me what is the difference between GOTO and BRA ??
    Is there a limit on how many times the GOTO instruction can be used??
    And the same for the CALL instruction, is there a limit on many times one can use it?

    Thanks in advance
     
  2. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    They vary on how far the branch can go.
    Look up the instruction set and it will explain in detail.

    So long as there is room for code you can use as many calls or goto's that you like.
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    There is instruction set documentation in the back of each Pic datasheet that explains how many Cycles each instruction takes.

    How many times can one use call? If you mean in recursion or chained calls then it is going to depend on both your stack size and program memory. If you mean just the number of call instructions you can use then it will depend on program memory. Of course a program of nothing but calls id not going to do too much. :)
     
    Dritech likes this.
  4. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi Spinnaker,

    I was going to use the call instruction every time i need to write to the LCD.
    The coding i am planning to use is as below:

    Code ( (Unknown Language)):
    1. Main coding
    2. ...
    3. ...
    4. call lcd1
    5. ...
    6. ...
    7. call lcd2
    8. ...
    9. ...
    10.  
    11. lcd1
    12. display: 'pump on'
    13. return
    14.  
    15. lcd2
    16. display: 'ump off'
    17. return
    Will it be structured/organized correctly if i use the above setup ?
     
  5. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    I'm far from an assembler expert. I have not dealt with it since way back in the days the 6502 was popular and assembler was all we had. Actually in those days it was machine language. We didn't have those fancy assemblers.

    I program in C now. But I see nothing wrong with doing it the way you want. Have you considered C? It is so much easier.
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    What you show is ok.
     
    Dritech likes this.
  7. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Since im a beginner in programming, i prefer starting using assembly.
     
  8. LDG

    New Member

    Feb 10, 2012
    4
    1
    ;Write to Display ******************Sub Routines ***************
    DatWr
    movwf PORTB ;put data on PORTB
    bsf PORTC,3 ;select data reg
    bcf PORTC,4 ;write mode
    call EPulse
    return

    CmdWr
    movwf PORTB ;put command on PORTB
    bcf PORTC,3 ;select command reg
    bcf PORTC,4 ;select write mode

    EPulse ;pulse Eanble on display
    bsf PORTC,5 ;enable pulse high
    call TPulse
    bcf PORTC,5 ;enable pulse low
    call TPulse
    return

    TPulse
    movlw H'FF'
    movwf 0x6E
    TP2
    movlw H'0F'
    movwf 0x6F
    Decp
    decfsz 0x6F,1
    goto Decp
    Decp2
    decfsz 0x6E,1
    goto TP2
    return
     
    Last edited: Feb 11, 2012
    Dritech likes this.
  9. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi LDG. Thanks for that :)
     
Loading...