# Problem with PIC Code of Path Learning Car

#### hunzaboy

Joined May 4, 2010
3
Hello there!

I need help regarding my project. I have designed the Hardware completely. I am designing a path learning car.

However i am having trouble with the code. I am using PIC16F877 mc. the code is attached.

MY PROBLEMS: When i am trying to send an interrupt to pin RB0 then no pulse is detected. which means no interrupt. I want to know the problem. Can anyone help me?

Rich (BB code):
        list      p=16f877            ; list directive to define processor
#include <p16f877.inc>        ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_ON & _LVP_ON & _DEBUG_OFF & _CPD_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

;***** VARIABLE DEFINITIONS

CHECK EQU 0X20
TEMP EQU 0X21
A1 EQU 0X022
B1 EQU 0X023
C1 EQU 0X024

;**********************************************************************
ORG     0x000             ; processor reset vector
clrf    PCLATH            ; ensure page bits are cleared
GOTO    MAIN              ; go to beginning of program

ORG     0x004             ; interrupt vector location
MOVF CHECK,0
XORLW D'1'
MOVWF CHECK

MOVLW b'10000000'
MOVWF PORTD
; clearing in software
BCF INTCON,1;
RETFIE

MAIN

MOVLW B'10100101';
MOVWF TEMP;
MOVLW D'1';
MOVWF CHECK;

;;;;;;;;;;;;;;;PORTS
BANKSEL TRISC
MOVLW B'00000000'
MOVWF TRISC

BANKSEL TRISB

MOVLW B'11111111'
MOVWF TRISB

BANKSEL INTCON

;;;On Interrupts
BCF INTCON,1;
BSF INTCON,4;
BSF INTCON, 6;
BSF INTCON, 7;
BSF INTCON, 3;
;; stop the car

LOOP
;;;;;;;;;;;;;;;;;;;;;;
MOVF CHECK,0
XORLW D'1'
BTFSS STATUS,Z;
GOTO LOOP1

;; START CAR ( any pin on port C)
MOVLW B'11111111'
MOVWF PORTC;
;    CALL DELAY1

GOTO LOOP

LOOP1

MOVF CHECK,0
XORLW D'1'
BTFSC STATUS,Z;
GOTO LOOP

BANKSEL PORTC
MOVLW B'00000000'
MOVWF PORTC;
GOTO LOOP1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

END

#### BMorse

Joined Sep 26, 2009
2,675
post the circuit also, so we know how you have things wired up and connected, since I see you have Low voltage Programming enabled and all......depending on how you have this connected in the circuit, the pic may not even start up at all....

B. Morse

#### hunzaboy

Joined May 4, 2010
3
post the circuit also, so we know how you have things wired up and connected, since I see you have Low voltage Programming enabled and all......depending on how you have this connected in the circuit, the pic may not even start up at all....

B. Morse
No the PIC has started. Because the code which is burnt default by myself works fine. But when i give interrupt then its not working.
However my code works properly in PROTEUS but not working on Hardware..

#### BMorse

Joined Sep 26, 2009
2,675
No the PIC has started. Because the code which is burnt default by myself works fine. But when i give interrupt then its not working.
However my code works properly in PROTEUS but not working on Hardware..

How did you determine the PIC starts fine? Do you have another routine that test something to determine that? Simulating circuits to me is like making a lot of assumptions ( that are usually wrong).... better to have built the circuit on a breadboard than to simulate it....

B. Morse

#### hunzaboy

Joined May 4, 2010
3
How did you determine the PIC starts fine? Do you have another routine that test something to determine that? Simulating circuits to me is like making a lot of assumptions ( that are usually wrong).... better to have built the circuit on a breadboard than to simulate it....

B. Morse
Yeah i have worked on breadboard. The PIC is working fine on the HARDWARE. i have check it with other sample codes. And also in the given code the initial output of "binary 1s" is coming.

#### MMcLaren

Joined Feb 14, 2010
845
Can you use actual bit names in operands (for INTCON for example) or perhaps add a comment or two? We shouldn't have to do this for you since you're the one asking for help.

If you are using interrupts then your interrupt handler is deficient...

Regards, Mike