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.

pic16f84 subroutine problem

Status
Not open for further replies.

aniket_lad

Newbie level 1
Joined
Feb 15, 2005
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,289
subroutine in pic16f84

hi!
i am using pic16f84 for robotics purpose
in the program below i hav used 3 subroutines for go straight,left and right turn.
but whenever i run the program, only the subroutine placed first in the program is executed and it ignores rest two.
i hav used port b to conrtol relays and port a is used to take input from sensors.
please help me.

here is the program i hav written

;*****DECLARATION OF MICROCONTROLLER *********

PROCESSOR 16F84
#include "p16f84.inc"


__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC


;*******declaration of variables*********

Cblock 0x0C
con
endc


;*******program structure****************


org 0X00
goto Main

org 0X04
goto Main

;***************main pogram************
Main
banksel TRISB
clrf TRISB
banksel TRISA
movlw 0xff
movwf TRISA
Loop
banksel PORTA
movf PORTA,0
movwf con
btfsc con,3
call Rturn
banksel PORTA
movf PORTA,0
movwf con
btfsc con,1
call Front
banksel PORTA
movf PORTA,0
movwf con
btfsc con,2
call Lturn
banksel PORTB
clrf PORTB
goto Loop

Front
movlw 0xa0
banksel PORTB
movwf PORTB
return

Lturn
movlw 0x60
banksel PORTB
movwf PORTB
return

Rturn movlw 0x90
banksel PORTB
movwf PORTB
return

end
[/url]\]
 

The only problem I can see (after reading your code) is this:

clrf PORTB
goto Loop

This code is always executed after any of your commands has been executed.

Maybe you should only execute this code when none of your subroutines has executed. You could do this by setting a flag whenever one of your subroutines has been executed and only clear PORTB when this flag ha not been set.

hope this helps and best regards
 

Also another important thing to consider is that PIC microcontroller program memory is arranged in page like...... you have to becareful in jumping from one subroutine to another because it might not reach it.... but if you are coding in C, this problem is eliminated... its the problem of the compiler already..... =)
 

Lepidoptera_ece said:
Also another important thing to consider is that PIC microcontroller program memory is arranged in page like...... you have to becareful in jumping from one subroutine to another because it might not reach it.... but if you are coding in C, this problem is eliminated... its the problem of the compiler already..... =)

16F84 does not use codebanks ...

Only PIC's with more than 2K flash are using codebanking but not the PIC18 series.

best regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top