Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

use call instruction inside a call in pic mcu?

Status
Not open for further replies.

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
hello
can i use call instruction inside a call function?
some code below. Plz see keypad scanning section inside ;;;;;;;;; box . ;;;;;;; is only here for higlighting but not in code.



processor 16f84
include <p16f84.inc> ; This includes PIC16F84 definitions for the MPASM assembler
__config _HS_OSC & _WDT_OFF & _PWRTE_ON

;set 8 words password files

C1 equ 21h
C2 equ 22h
C3 equ 23h
C4 equ 24h
C5 equ 25h
C6 equ 26h
C7 equ 27h
C8 equ 28h

;set timer files

K equ 29h
J equ 2Ah


main:

org 00h

;clear 8 word password files password files

clrf C1
clrf C2
clrf C3
clrf C4
clrf C5
clrf C6
clrf C7
clrf C8

;read eeprom 8 locations and put them in 8 word password files

;C1

banksel EEADR
movlw 0h
movwf EEADR
banksel EECON1
bsf EECON1 , RD
bcf STATUS , RP0
movf EEDATA , w
movwf C1

;C2

banksel EEADR
movlw 01h
movwf EEADR
banksel EECON1
bsf EECON1 , RD
bcf STATUS , RP0
movf EEDATA , w
movwf C2

;C3

banksel EEADR
movlw 02h
movwf EEADR
banksel EECON1
bsf EECON1 , RD
bcf STATUS , RP0
movf EEDATA , w
movwf C3

;C4
banksel EEADR
movlw 03h
movwf EEADR
banksel EECON1
bsf EECON1 , RD
bcf STATUS , RP0
movf EEDATA , w
movwf C4

;C5
banksel EEADR
movlw 04h
movwf EEADR
banksel EECON1
bsf EECON1 , RD
bcf STATUS , RP0
movf EEDATA , w
movwf C5

;C6
banksel EEADR
movlw 05h
movwf EEADR
banksel EECON1
bsf EECON1 , RD
bcf STATUS , RP0
movf EEDATA , w
movwf C6

;C7
banksel EEADR
movlw 06h
movwf EEADR
banksel EECON1
bsf EECON1 , RD
bcf STATUS , RP0
movf EEDATA , w
movwf C7

;C8

banksel EEADR
movlw 07h
movwf EEADR
banksel EECON1
bsf EECON1 , RD
bcf STATUS , RP0
movf EEDATA , w
movwf C8

;keypad port settings 3 x 3 PORTB 0 to PORTB 5 , PortB 6 to 7 has buzz and indicator of keypress.

banksel TRISB
movlw B'00111000'
movwf TRISB
banksel PORTB
movlw B'00000111'
movwf PORTB

;Output PORTA settings

banksel TRISA
movlw B'00000'
movwf TRISA

unlocking:

banksel PORTA
bsf PORTA , 0

sub1:

clrw
call keypad







;keypad scanning

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
keypad:
banksel PORTB
scan1:
bcf PORTB , 0
btfsc PORTB , 3
goto scan2
call debounce
btfsc PORTB , 3
goto scan2
bsf PORTB , 6
bsf PORTB , 7
movlw D'1'
wait1:
btfss PORTB , 3
goto wait1
bcf PORTB , 6
bcf PORTB , 7
call debounce
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
scan2:

goto keypad

;timer debounce

debounce:

movlw D'20'
movwf K
clrf J
delay1:
nop
decfsz J , f
goto delay1
delay2:
nop
decfsz J , f
goto delay2
decfsz K , f
goto delay1
return

fin:
goto fin

END
 

yes you can, but you need to be aware of the stack size for the pic, on the 16f84 it is an 8 level stack.
 

Pic84 has 8 levels of stack. After that 'stackoverflow' happens. Call instruction raises stack to next level.When function completes it igoes to lower level. As goto nstruction does not alter stack level so it is advised to use goto rather than call where possible. You only have to be carefull not to overflow the stack through whole of your programme execution.
 
Last edited:

So it is advised to use goto rather than call where possible.

I have to disagree GOTO's can lead to very untidy code. It is best to maintain control of the call, rather than using excesive GOTO commands. Also if you goto a routine,how do you know where to return to?
 
  • Like
Reactions: d@nny

    d@nny

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top