Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

WHY....why is not working???

Status
Not open for further replies.

striker2509

New Member
Hi again, I'm trying to work with interrupts for the first time. Im having trouble with it. My input signals are in RB4-RB7. Everytime one of these ports change. It must turn a LED on, this is only to know how the interrupt works and if it's doing what i want. But neither of both, i read through the program over and over again, and find nothing (must be my novice programmer eye). Maybe you can help me with this dark tunnel...Thanks
 

Attachments

  • interrup.txt
    1.7 KB · Views: 201
i am not an expert ..
dont you have to save W and Status , somewhere at the beginning of your ISR..

Code:
			ORG 0x00
			GOTO MAINLOOP
			ORG	0x04
			BSF		PORTC,0
			MOVFW	PORTB
			BCF		INTCON, RBIF
			RETFIE
	
CONFIG		BSF 	STATUS, 5			;cambio al banco 1
			BSF 	INTCON, RBIE
			BSF		INTCON, GIE
			MOVLW	B'11110000'
			MOVWF	TRISB				;RB4 - RB7 son entradas
			CLRF	TRISC				;RC0 - RC7 como salidas
			BCF		STATUS, 5			;retorno al banco cero

MAINLOOP
			BSF		PORTC,1			;set all bits on
			nop						;the nop's make up the time taken by the goto
			nop						;giving a square wave output
			call	Delay			;this waits for a while!
			BCF		PORTC,1
			call	Delay
			BCF		PORTC,0
			goto	MAINLOOP			;go back and do it again

Delay		movlw	d'250'		;delay 250 ms (4 MHz clock)
			movwf	count1
d1			movlw	0xC7
			movwf	counta
			movlw	0x01
			movwf	countb
Delay_0
			decfsz	counta, f
			goto	$+2
			decfsz	countb, f
			goto	Delay_0
			decfsz	count1	,f
			goto	d1
			retlw	0x00
 
Your program is confusing. Why not set PORTC to all high or all low and then do the opposite in the interrupt routine?

Anyway, this line:
Code:
BSF		PORTC,1			;set all bits on
...is not doing what your comment suggests. You are only setting one bit, not all of them.

Code:
CONFIG	BSF 	STATUS, 5			;cambio al banco 1
			BSF 	INTCON, RBIE
			BSF		INTCON, GIE
			MOVLW	B'11110000'
			MOVWF	TRISB				;RB4 - RB7 son entradas
			CLRF	TRISC				;RC0 - RC7 como salidas
			BCF		STATUS, 5			;retorno al banco cero
It would be better to turn on interrupts as the last thing, not the first. And do it from bank 0, not bank 1. (INTCON is available in all banks.) If the interrupt happens before you return to bank 0 then your interrupt routine is not in the bank that it thinks it is in. Also, your interrupt routine should save the STATUS register and set the bank to 0 on entry and then restore STATUS on exit so that the bank is what it was before entry. You should also save and restore W.

If you wanted to get away with the bare minimum for testing then do it this way:
Code:
CONFIG	BSF 	STATUS, 5			;cambio al banco 1
			MOVLW	B'11110000'
			MOVWF	TRISB				;RB4 - RB7 son entradas
			CLRF	TRISC				;RC0 - RC7 como salidas
			BCF		STATUS, 5			;retorno al banco cero
			BSF		INTCON, RBIE
			BSF		INTCON, GIE
			; Since you don't do any other bank switching in your code
			; setting the interrupts from bank 0 guarantees that you will
			; be in bank 0 when the interrupt occurs.

Also, a big mistake you made is that your CONFIG routine never executes, because you start execution at MAINLOOP:
Code:
			ORG 0x00
			GOTO MAINLOOP
It should be this:
Code:
			ORG 0x00
			GOTO CONFIG

And then, one last thing...Make sure you have pullup resistors on your inputs to prevent floating.

Mike
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top