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.

Interrupt

Status
Not open for further replies.

AtomSoft

Well-Known Member
Just got my Junebug today and playing with it.

I tried altering the LED demo code
Code:
; *** Junebug 18F1320 LED sequencer demo ***
; Flashes LEDs1 thru 6 from left to right forever
; DIP Switch (SW6) must have TUTOR on (SW6-1,2,3) all other switches off
list p=18F1320
include <p18F1320.inc>
CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF
LED macro x,y ; MACRO LED <PORTA>, <TRISA>
movlw x
movwf LATA ; LATA = x
movlw y
movwf TRISA ; TRISA = y
call Delay ; call the Delay subroutine
endm ; end macro
Count equ 0 ; delay loop counter
org 0 ; reset vector
;bsf ADCON1, 0 ; make RA0 digital
CLRF LATB ; Alternate method to clear output data latches
MOVLW b'00010001';0x08 ; Set RB0, RB1, RB4 as
MOVWF ADCON1 ; digital I/O pins
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
LED1 LED b'00000001', b'10111110' ; LED <PORTA>, <TRISA>
LED2 LED b'01000000', b'10111110' ; LED <PORTA>, <TRISA>
LED3 LED b'01000000', b'00111111' ; LED <PORTA>, <TRISA>
LED4 LED b'10000000', b'00111111' ; LED <PORTA>, <TRISA>
LED5 LED b'10000000', b'01111110' ; LED <PORTA>, <TRISA>
LED6 LED b'00000001', b'01111110' ; LED <PORTA>, <TRISA>
goto LED1 ; loop forever
Delay decfsz Count, f ; decrement Count and skip when zero
goto $-2 ; not zero? repeat
return
ISR
	bcf INTCON, 0 ; alternate
	bcf INTCON, 1 ; alternate
    LED b'10000001', b'01111110' ; LED <PORTA>, <TRISA>
	call Delay
	retfie
END

Basically what i tried to do is run the LEDs as usual until a interupt occurs. I know i must be mixing something here . I get no errors but like 30 warnings even with Junebug code alone. Also i always get a target halted:

Code:
PKWarn0006:  The local copy of program memory has been changed since the last program operation.  Should PICkit 2 program the target (fix) before proceeding?
Programming Target (3/13/2008  10:00:00 AM)
Erasing Target
Programming Program Memory (0x0 - 0x77)
Verifying Program Memory (0x0 - 0x77)
Programming Debug Executive (0x-1E40 - 0x1FFF)
Verifying Debug Executive (0x1E40 - 0x1FFF)
Programming Debug Vector
Verifying Debug Vector
Programming Configuration Memory
Verifying Configuration Memory
Running Target
Debug mode entered, DE Version = 16.0.4
PICkit 2 Ready

Target Halted

Code:
Warning[203] C:\MPLAB\JUNEBUG\MAIN.ASM 12 : Found opcode in column 1. (call)
Warning[205] C:\MPLAB\JUNEBUG\MAIN.ASM 38 : Found directive in column 1. (END)
Loaded C:\mplab\junebug\main.cod.
BUILD SUCCEEDED: Thu Mar 13 09:59:53 2008
 
Try indenting the code. You can't have opcodes in the first column.

So,
Code:
call something             ;illegal
     call something        ;legal

Mike.
 
Wow that cleaned all warnings:
Code:
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\mplab\junebug\main.err".
Clean: Deleted file "C:\mplab\junebug\main.cod".
Clean: Deleted file "C:\mplab\junebug\main.hex".
Clean: Deleted file "C:\mplab\junebug\main.lst".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p18F1320 "main.asm" /l"main.lst" /e"main.err"
Loaded C:\mplab\junebug\main.cod.
BUILD SUCCEEDED: Thu Mar 13 10:44:06 2008

Code:
; *** Junebug 18F1320 LED sequencer demo ***
; Flashes LEDs1 thru 6 from left to right forever
; DIP Switch (SW6) must have TUTOR on (SW6-1,2,3) all other switches off
	list p=18F1320
	include <p18F1320.inc>
	CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF
LED macro x,y ; MACRO LED <PORTA>, <TRISA>
	movlw x
	movwf LATA ; LATA = x
	movlw y
	movwf TRISA ; TRISA = y
	call Delay ; call the Delay subroutine
	endm ; end macro
Count equ 0 ; delay loop counter
	org 0 ; reset vector
	;bsf ADCON1, 0 ; make RA0 digital
	CLRF PORTB ; Initialize PORTB by clearing output data latches
	;CLRF LATB ; Alternate method to clear output data latches
	MOVLW 0x08 ;b'00010001' Set RB0, RB1, RB4 as
	MOVWF ADCON1 ; digital I/O pins
	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
LED1 LED b'00000001', b'10111110' ; LED <PORTA>, <TRISA>
LED2 LED b'01000000', b'10111110' ; LED <PORTA>, <TRISA>
LED3 LED b'01000000', b'00111111' ; LED <PORTA>, <TRISA>
LED4 LED b'10000000', b'00111111' ; LED <PORTA>, <TRISA>
LED5 LED b'10000000', b'01111110' ; LED <PORTA>, <TRISA>
LED6 LED b'00000001', b'01111110' ; LED <PORTA>, <TRISA>
	goto LED1 ; loop forever
Delay decfsz Count, f ; decrement Count and skip when zero
	goto $-2 ; not zero? repeat
	return
ISR
	bcf INTCON, 0 ; alternate
	bcf INTCON, 1 ; alternate
    LED b'10000001', b'01111110' ; LED <PORTA>, <TRISA>
	call Delay
	retfie
	END

interrupt doent work tho (trying RB0)
 
tried:
Code:
; *** Junebug 18F1320 LED sequencer demo ***
; Flashes LEDs1 thru 6 from left to right forever
; DIP Switch (SW6) must have TUTOR on (SW6-1,2,3) all other switches off
	list p=18F1320
	include <p18F1320.inc>
	CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF
LED macro x,y ; MACRO LED <PORTA>, <TRISA>
	movlw x
	movwf LATA ; LATA = x
	movlw y
	movwf TRISA ; TRISA = y
	call Delay ; call the Delay subroutine
	endm ; end macro
Count equ 0 ; delay loop counter
	org 0 ; reset vector
	;bsf ADCON1, 0 ; make RA0 digital
	;CLRF PORTB ; Initialize PORTB by clearing output data latches
	CLRF LATB ; Alternate method to clear output data latches
	MOVLW 0x08 ;b'00010001' Set RB0, RB1, RB4 as
	MOVWF ADCON1 ; digital I/O pins
	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
	[b]MOVLW b'11111000'
	MOVWF INTCON
	MOVLW b'11110101'
	MOVWF INTCON2
	MOVLW b'11011000'
	MOVWF INTCON3[/b]
LED1 LED b'00000001', b'10111110' ; LED <PORTA>, <TRISA>
LED2 LED b'01000000', b'10111110' ; LED <PORTA>, <TRISA>
LED3 LED b'01000000', b'00111111' ; LED <PORTA>, <TRISA>
LED4 LED b'10000000', b'00111111' ; LED <PORTA>, <TRISA>
LED5 LED b'10000000', b'01111110' ; LED <PORTA>, <TRISA>
LED6 LED b'00000001', b'01111110' ; LED <PORTA>, <TRISA>
	goto LED1 ; loop forever
Delay decfsz Count, f ; decrement Count and skip when zero
	goto $-2 ; not zero? repeat
	return
ISR
	MOVLW b'11111000'
	MOVWF INTCON
	BCF INTCON3, 0
	BCF INTCON3, 1
LED56 LED b'10000001', b'01111110' ; LED <PORTA>, <TRISA>
	call Delay
	retfie
	END
 
Last edited:
But how ? i know high priority interrupt vector is at 000008h and the low priority interrupt vector is at 000018h but how would i make in the asm?

going to try but any help would be nice:
Code:
; *** Junebug 18F1320 LED sequencer demo ***
; Flashes LEDs1 thru 6 from left to right forever
; DIP Switch (SW6) must have TUTOR on (SW6-1,2,3) all other switches off
	list p=18F1320
	include <p18F1320.inc>
	CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF
LED macro x,y ; MACRO LED <PORTA>, <TRISA>
	movlw x
	movwf LATA ; LATA = x
	movlw y
	movwf TRISA ; TRISA = y
	call Delay ; call the Delay subroutine
	endm ; end macro
Count equ 0 ; delay loop counter
	org 0x00 ; reset vector
	goto Main
	org 0x08 ;  ISR vector
	goto ISR

Main
	;bsf ADCON1, 0 ; make RA0 digital
	;CLRF PORTB ; Initialize PORTB by clearing output data latches
	CLRF LATB ; Alternate method to clear output data latches
	MOVLW 0x08 ;b'00010001' Set RB0, RB1, RB4 as
	MOVWF ADCON1 ; digital I/O pins
	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
	MOVLW b'11111000'
	MOVWF INTCON
	MOVLW b'11110101'
	MOVWF INTCON2
	MOVLW b'11011000'
	MOVWF INTCON3
LED1 LED b'00000001', b'10111110' ; LED <PORTA>, <TRISA>
LED2 LED b'01000000', b'10111110' ; LED <PORTA>, <TRISA>
LED3 LED b'01000000', b'00111111' ; LED <PORTA>, <TRISA>
LED4 LED b'10000000', b'00111111' ; LED <PORTA>, <TRISA>
LED5 LED b'10000000', b'01111110' ; LED <PORTA>, <TRISA>
LED6 LED b'00000001', b'01111110' ; LED <PORTA>, <TRISA>
	goto LED1 ; loop forever
Delay decfsz Count, f ; decrement Count and skip when zero
	goto $-2 ; not zero? repeat
	return
ISR
	MOVLW b'11111000'
	MOVWF INTCON
	MOVLW b'11110101'
	MOVWF INTCON2
	MOVLW b'11011000'
	MOVWF INTCON3
LED56 LED b'00000001', b'01111110' ; LED <PORTA>, <TRISA>
	call Delay
	call Delay
	call Delay
	retfie	
	END
 
Last edited:
Nigel Goodwin said:
How does it know where to jump when an interrupt is called?, shouldn't you use a specific interrupt vector?.
Precisely. There's no proper org to place the ISR (or a jump to it) at the interrupt vector. This program will crash (or at least do something unpredictable) on every interrupt.

It will also need a jump at org 0 to hop over the ISR vector to the beginning of main code.

I've cleaned it up a bit for easier reading
Code:
	list p=18F1320
	include <p18F1320.inc>
	CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

LED	macro	x,y		;MACRO LED <PORTA>, <TRISA>
	movlw	x
	movwf	LATA		;LATA = x
	movlw	y
	movwf	TRISA		;TRISA = y
	call	Delay		;call the Delay subroutine
	endm			;end macro

Count	equ	0		;delay loop counter

	org	0		;reset vector
;	bsf	ADCON1,0	;make RA0 digital
;	CLRF	PORTB		;Initialize PORTB by clearing output data latches
	CLRF	LATB		;Alternate method to clear output data latches
	MOVLW	0x08		;b'00010001' Set RB0, RB1, RB4 as
	MOVWF	ADCON1		;digital I/O pins
	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
	MOVLW	b'11111000'
	MOVWF	INTCON
	MOVLW	b'11110101'
	MOVWF	INTCON2
	MOVLW	b'11011000'
	MOVWF	INTCON3
LED1	LED	b'00000001',b'10111110'
LED2	LED	b'01000000',b'10111110'
LED3	LED	b'01000000',b'00111111'
LED4	LED	b'10000000',b'00111111'
LED5	LED	b'10000000',b'01111110'
LED6	LED	b'00000001',b'01111110'
	goto	LED1		;loop forever

Delay	decfsz	Count,f		;decrement Count and skip when zero
	goto	$-2		;not zero? repeat
	return

ISR	MOVLW	b'11111000'
	MOVWF	INTCON
	BCF	INTCON3, 0
	BCF	INTCON3, 1
LED56	LED	b'10000001',b'01111110'
	call	Delay
	retfie

	END
 
is this close at least?
Code:
	list p=18F1320
	include <p18F1320.inc>
	CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

LED	macro	x,y	     	;MACRO LED <PORTA>, <TRISA>
	movlw	x
	movwf	LATA		;LATA = x
	movlw	y
	movwf	TRISA		;TRISA = y
	call	Delay		;call the Delay subroutine
	endm		    	;end macro
Count	equ	0	    	;delay loop counter
	org 0x00            ; reset vector
	goto Main
	org 0x08            ;  ISR vector
	goto ISR
Main
;	bsf	ADCON1,0	    ;make RA0 digital
;	CLRF	PORTB		;Initialize PORTB by clearing output data latches
	CLRF	LATB		;Alternate method to clear output data latches
	MOVLW	0x08		;b'00010001' Set RB0, RB1, RB4 as
	MOVWF	ADCON1		;digital I/O pins
	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
	MOVLW	b'11111000'
	MOVWF	INTCON
	MOVLW	b'11110101'
	MOVWF	INTCON2
	MOVLW	b'11011000'
	MOVWF	INTCON3
LED1	LED	b'00000001',b'10111110'
LED2	LED	b'01000000',b'10111110'
LED3	LED	b'01000000',b'00111111'
LED4	LED	b'10000000',b'00111111'
LED5	LED	b'10000000',b'01111110'
LED6	LED	b'00000001',b'01111110'
	goto	LED1		;loop forever

Delay	decfsz	Count,f	;decrement Count and skip when zero
	goto	$-2	     	;not zero? repeat
	return

ISR	
	MOVLW	b'11111000'
	MOVWF	INTCON
	MOVLW	b'11110101'
	MOVWF	INTCON2
	MOVLW	b'11011000'
	MOVWF	INTCON3
LED62	LED	b'00000001',b'01111110'
	call	Delay
	retfie
	END
 
Can someone please help me out here. Have been reading the data sheet and i just dont understand why this wont work. Its like its alive it works sometime but with RB2 and then just crashes and i have to reprogram it like with the normal junebug code just to get it to start over.
Code:
	list p=18F1320
	include <p18F1320.inc>
	CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

LED	macro	x,y	     	;MACRO LED <PORTA>, <TRISA>
	movlw	x
	movwf	LATA		;LATA = x
	movlw	y
	movwf	TRISA		;TRISA = y
	call	Delay		;call the Delay subroutine
	endm		    	;end macro
Count	equ	0	    	;delay loop counter
	org 0x00            ; reset vector
	goto Main
	org 0x08            ;  ISR Low vector
	goto ISR
	org 0x18            ;  ISR Low vector
	goto ISR
Main
;	bsf	ADCON1,0	    ;make RA0 digital
	CLRF	PORTB		;Initialize PORTB by clearing output data latches
	CLRF	LATB		;Alternate method to clear output data latches
	MOVLW	0x08		;b'00010001' Set RB0, RB1, RB4 as
	MOVWF	ADCON1		;digital I/O pins
	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
	MOVLW	b'11111000' ;b'11011000'
	MOVWF	INTCON
	MOVLW   b'01110000' ;b'11110101'
	MOVWF	INTCON2
	MOVLW	b'00011000' ;b'00001000'
	MOVWF	INTCON3
LED1	LED	b'00000001',b'10111110'
LED2	LED	b'01000000',b'10111110'
LED3	LED	b'01000000',b'00111111'
LED4	LED	b'10000000',b'00111111'
LED5	LED	b'10000000',b'01111110'
LED6	LED	b'00000001',b'01111110'
	goto	LED1		;loop forever

Delay	decfsz	Count,f	;decrement Count and skip when zero
	goto	$-2	     	;not zero? repeat
	return

ISR		call Delay
	LED	b'00000001',b'01111110'
	call	Delay
	call	Delay
	call	Delay
	MOVLW	b'11111000' ;b'11011000'
	MOVWF	INTCON
	MOVLW   b'01110000' ;b'11110101'
	MOVWF	INTCON2
	MOVLW	b'00011000' ;b'00001000'
	MOVWF	INTCON3
	retfie
	END
 
Got it to work with RB2 no problem now
Code:
	list p=18F1320
	include <p18F1320.inc>
	CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

LED	macro	x,y	     	;MACRO LED <PORTA>, <TRISA>
	movlw	x
	movwf	LATA		;LATA = x
	movlw	y
	movwf	TRISA		;TRISA = y
	call	Delay		;call the Delay subroutine
	endm		    	;end macro
Count	equ	0	    	;delay loop counter
	org 0x00            ; reset vector
	goto Main
	org 0x08            ;  ISR Low vector
	goto ISR
	org 0x18            ;  ISR Low vector
	goto ISR
Main
;	bsf	ADCON1,0	    ;make RA0 digital
	CLRF	PORTB		;Initialize PORTB by clearing output data latches
	CLRF	LATB		;Alternate method to clear output data latches
	MOVLW	0x08		;b'00010001' Set RB0, RB1, RB4 as
	MOVWF	ADCON1		;digital I/O pins
	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
	MOVLW	b'11111000' ;b'11011000'
	MOVWF	INTCON
	MOVLW   b'01110000' ;b'11110101'
	MOVWF	INTCON2
	MOVLW	b'00011000' ;b'00001000'
	MOVWF	INTCON3
LED1	LED	b'00000001',b'10111110'
LED2	LED	b'01000000',b'10111110'
LED3	LED	b'01000000',b'00111111'
LED4	LED	b'10000000',b'00111111'
LED5	LED	b'10000000',b'01111110'
LED6	LED	b'00000001',b'01111110'
	goto	LED1		;loop forever

Delay	decfsz	Count,f	;decrement Count and skip when zero
	goto	$-2	     	;not zero? repeat
	return

ISR	BCF INTCON3, 0
	BCF INTCON3, 1
	BCF INTCON, 0
	BCF INTCON, 1
	BCF INTCON, 2
	call Delay
	LED	b'00000001',b'01111110'
	call	Delay
	call	Delay
	call	Delay
	retfie
	END
 
Ok got it done heres what was wrong:
1. Wronge ADCON1 setting supposed to be 0x10 for RB0/AN4
2. Was editing portb while in use in the interrupt which is a no no so just cleared needed bits.
3. Wrong INTCONx Settings.

went through data sheet real real real real slow just to find that out lol :D

Code:
	list p=18F1320
	include <p18F1320.inc>
	CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

LED	macro	x,y	     	;MACRO LED <PORTA>, <TRISA>
	movlw	x
	movwf	LATA		;LATA = x
	movlw	y
	movwf	TRISA		;TRISA = y
	call	Delay		;call the Delay subroutine
	endm		    	;end macro
Count	equ	0	    	;delay loop counter
	org 0x00            ; reset vector
	goto Main
	org 0x08            ;  ISR Low vector
	goto ISR
	org 0x18            ;  ISR Low vector
	goto ISR
Main
;	bsf	ADCON1,0	    ;make RA0 digital
	CLRF	PORTB		;Initialize PORTB by clearing output data latches
	CLRF	LATB		;Alternate method to clear output data latches
	[b]MOVLW	0x10        ;b'00010001'	; Set RB0
	MOVWF	ADCON1		;digital I/O pin[/b]
	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[b]
	MOVLW	b'11111000' ;b'11011000'
	MOVWF	INTCON
	MOVLW   b'01110000' ;b'11110101'
	MOVWF	INTCON2
	MOVLW	b'00011000' ;b'00001000'
	MOVWF	INTCON3[/b]
LED1	LED	b'00000001',b'10111110'
LED2	LED	b'01000000',b'10111110'
LED3	LED	b'01000000',b'00111111'
LED4	LED	b'10000000',b'00111111'
LED5	LED	b'10000000',b'01111110'
LED6	LED	b'00000001',b'01111110'
	goto	LED1		;loop forever

Delay	decfsz	Count,f	;decrement Count and skip when zero
	goto	$-2	     	;not zero? repeat
	return

ISR	[b]BCF INTCON3, 0
	BCF INTCON3, 1
	BCF INTCON, 0
	BCF INTCON, 1
	BCF INTCON, 2[/b]
	call Delay
	LED	b'00000001',b'01111110'
	call	Delay
	call	Delay
	call	Delay
	retfie
	END
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top