Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 30th September 2004, 06:41 PM   (permalink)
Default Problem about the Interrupt in PIC16F84A... pls pls~~ help!!

ORG 0X00 ; STARTING LOCATION
GOTO INITIAL

ORG 0x04 ; The interrupt vector
GOTO ISR
INITIAL: BSF STATUS,RP0 ; SELECT BANK 1
MOVLW 0X1F ;
MOVWF PORTA
MOVLW 0X03
MOVWF PORTB
BCF STATUS,RP0
CLRF PORTA
CLRF PORTB
CLRF INTCON
BSF INTCON,GIE
BSF INTCON,INTE ; Enable external INT-pin interrupts


ISR: CLRF PORTA
CLRF PORTB
BSF PORTB,5
CALL DELAY
BCF PORTB,5
BCF INTCON,INTF ; CLEAR THE INTERRUPT FLAG BIT
RETFIE ; RETURN FROM INTERRUPT


hey.... pls help me.. the problem is after interrupted, it got light up my LED at portb,5...... but then i not turn off the LED.... from the program above it should light up the LED then delay awhile then turn off the LED.... why ya??? it just light up the LED>..... and i need to turn off and on the power supply to reset it~~~~ why???
Gundam82 is offline  
Old 30th September 2004, 10:30 PM   (permalink)
Default Re: Problem about the Interrupt in PIC16F84A... pls pls~~ he

Quote:
Originally Posted by Gundam82
ORG 0X00 ; STARTING LOCATION
GOTO INITIAL

ORG 0x04 ; The interrupt vector
GOTO ISR
INITIAL: BSF STATUS,RP0 ; SELECT BANK 1
MOVLW 0X1F ;
MOVWF PORTA
MOVLW 0X03
MOVWF PORTB
You just selected bank1 and then you write to porta and portb wich are in bank 0, you need to use trisa and trisb.

Quote:
Originally Posted by Gundam82
BCF STATUS,RP0
CLRF PORTA
CLRF PORTB
CLRF INTCON
BSF INTCON,GIE
BSF INTCON,INTE ; Enable external INT-pin interrupts
Your main code just stops here! the pic will continue execution and run right into the isr below. you should put something here to keep the pic from going further, and endless loop for example like 'goto $'.

Quote:
Originally Posted by Gundam82
ISR: CLRF PORTA
CLRF PORTB
BSF PORTB,5
CALL DELAY
BCF PORTB,5
BCF INTCON,INTF ; CLEAR THE INTERRUPT FLAG BIT
RETFIE ; RETURN FROM INTERRUPT
Exo is offline  
Old 1st October 2004, 11:26 AM   (permalink)
Default

thanks for ur solution.. erm... the tris i tried before... i follow the datasheet format... set to bank 1 then assign the TRIS, when compile with MPLAB, it shows warning.. o.... is that an error o not?? but i using my this method... the program run prefectly also.. why ya???

erm... one more thing, act program after the main .. still got program one.... its not staight go to ISR subroutine.......!!! u can try to see my whole short program from the attachment there!!!!!! hope can give me suggetion...........and solution!!!! i want to know where is the problem..!!!! i want to learn more thing!!!!

;================================================= ================================
;=Program for the PIC16f84a second PIC in the five-axis multitasking robot =
;=Aim: to control the base motor, vaccum and gripper + interrupt function

================================================== ===============================
list p=pic16f84a
#include "p16f84a.inc"
__CONFIG _WDT_OFF & _PWRTE_ON & _XT_OSC & _CP_OFF

D EQU 0X0C
D1 EQU 0X0D
D2 EQU 0X0E
;------------------------------------------------------------------------------------
ORG 0X00 ; STARTING LOCATION
GOTO INITIAL

ORG 0x04
GOTO ISR ; Go to start of foreground ISR
INITIAL: BSF STATUS,RP0 ; SELECT BANK 1
MOVLW 0X1F
MOVWF PORTA
MOVLW 0X03 MOVWF PORTB
BCF STATUS,RP0
CLRF PORTA
CLRF PORTB
CLRF INTCON
BSF INTCON,GIE ; Enable all interrupts
BSF INTCON,INTE ; Enable external INT-pin interrupts

;------------------------------------------------------------------------------------
START:
BTFSC PORTA,0 ; TEST PIN 19
GOTO FORWARD ; GOTO FORWARD IF PIN 19 IS SET,ELSE SKIP
BCF PORTB,4 ; OFF FORWARD
;------------------------------------------------------------------------------------
BTFSC PORTA,1 ; TEST PIN 20
GOTO REVERSE ; GOTO REVERSE IF PIN 20 IS SET,ELSE SKIP
BCF PORTB,5 ; OFF REVERSE
;------------------------------------------------------------------------------------
BTFSC PORTA,2 ; TEST PIN 1
GOTO LEFT ; GOTO LEFT IF PIN 1 IS SET,ELSE SKIP
BCF PORTB,6 ; OFF LEFT AND FORWARD
BCF PORTB,4
;------------------------------------------------------------------------------------
BTFSC PORTA,3 ; TEST PIN 2
GOTO RIGHT ; GOTO RIGHT IF PIN 2 IS SET,ELSE SKIP
BCF PORTB,7 ; OFF RIGHT AND FORWARD
BCF PORTB,4
;------------------------------------------------------------------------------------
BTFSC PORTA,4 ; TEST PIN 3
GOTO VACCUM ; GOTO VACCUM IF PIN 3 IS SET,ELSE SKIP

;------------------------------------------------------------------------------------
BTFSC PORTB,1 ; TEST PIN 8
GOTO GRIPPER ; GOTO GRIPPER IF PIN 8 IS SET,ELSE SKIP


GOTO START
;------------------------------------------------------------------------------------
FORWARD: BSF PORTB,4 ; ON FORWARD
GOTO START ; GO BACK

REVERSE: BSF PORTB,5
GOTO START

LEFT: BSF PORTB,6
BSF PORTB,4
GOTO START

RIGHT: BSF PORTB,7
BSF PORTB,4
GOTO START

VACCUM: COMF PORTB,3
GOTO START
GRIPPER: BSF PORTB,2

GOTO START ; GO BACK

;-------------------------------------------------ISR-------------------------------
ISR: CLRF PORTA
CLRF PORTB
BSF PORTB,5
CALL DELAY
BCF PORTB,5
BCF INTCON,INTF ; CLEAR THE TMR0 INTERRUPT FLAG BIT
RETFIE ; RETURN FROM INTERRUPT

;----------------------------------------DELAY-SUBROUTINE------------------------------------------------
DELAY: MOVLW B'00000001'
MOVWF D
DELAY2: MOVLW B'00001100'
MOVWF D1
DELAY3: DECFSZ D1,F
GOTO DELAY3
DECFSZ D,F
GOTO DELAY2
RETURN

END
Gundam82 is offline  
Old 1st October 2004, 03:36 PM   (permalink)
Default

i assembled your pgm.
there was a problem with this line"VACCUM: COMF PORTB,3 "
the problem is the assembler is expecting a( 0 or a 1) designating where the result is to be stored..
COMF f , d
if d is a 0 then the result is stored in W
if d is a 1 then the result is stored back in f..
williB is offline  
Old 1st October 2004, 03:56 PM   (permalink)
Default

thanks for ur correction.............. other than my program....... do u think that the interrupt can work perfectly???? wat i want to do is when the system is interrupted, all the port will set to zero to turn off all the motor it will turn on the motor at portb,5 for awhile (delay) then turn off the motor at potrb,5 ... after that.... i will standby to wait my signal send~~~


I tried this ... but after interrupted.. the motor at portb,5 just turn on.. forever..... at least i reset the supply...... WHY YA?????? wat i sure is the inteuuprt probelm~` but i dunno where~~~~ pls pls pls...... (@_@)
Gundam82 is offline  
Old 1st October 2004, 04:33 PM   (permalink)
Default

the TRIS registers control the ports A&B as input or output ..as Exo said you must set them ...
williB is offline  
Old 1st October 2004, 04:42 PM   (permalink)
Default

from the manual... for port A

BCF STATUS, RP0 ;
CLRF PORTA ; Initialize PORTA by clearing output data latches
BSF STATUS, RP0 ; Select Bank 1
MOVLW 0x0F ; Value used to initialize data direction
MOVWF TRISA ; Set RA<3:0> as inputs ; RA4 as output TRISA<7:5> are always read as ’0’.

from the manual for port B...

BCF STATUS, RP0
CLRF PORTB ; Initialize PORTB by clearing output data latches
BSF STATUS, RP0 ; Select Bank 1
MOVLW 0xCF ; Value used to initialize data direction
MOVWF TRISB ; Set RB<3:0> as inputs RB<5:4> as outputs RB<7:6> as inputs

i can help if ya tell me what ya want to do with port A & B ..
williB is offline  
Old 1st October 2004, 07:48 PM   (permalink)
Default

Quote:
Originally Posted by williB
the TRIS registers control the ports A&B as input or output ..as Exo said you must set them ...
He already was doing, just using the wrong word - both TRISx and PORTx are exactly the same address, it's the bank switching command that determines which register is written to. So his code was actually perfectly valid, if somewhat silly? - it obviously makes far more sense to use the correct word to avoid confusion.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 1st October 2004, 10:46 PM   (permalink)
Default

Gundam82, how did you connect the RB0/INT pin?
If it is left floating it might spontaniously trigger the interrupt over and over again, wich will result in the led staying on...

You should also add context saving to your isr, but in this case i don't think that's the problem.
Exo is offline  
Old 2nd October 2004, 05:14 AM   (permalink)
Default

Thanks everyone.............. EXO.... i connect my interrupt pin series with resistor to ground.... to pull UP..... here i attach my connection...... erm.. hope someone can help me...... about the interrupt?? is that possiblre i need to clear the interrupt flag o waT?? aii~~~~ headahce~~ just a small problemm... make me like this~~~~~ HELP
Attached Images
File Type: jpg untitled1_141.jpg (13.6 KB, 190 views)
Gundam82 is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 04:18 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker