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.

JuneBug PIC18F1320 Interrupt Example

Status
Not open for further replies.

rnorman3

New Member
I'm new to PIC programming and found it's hard to find simple skeleton examples of how to program MCU's. I managed to piece this entire example (attached) together from the datasheet for the PIC18F1320. The code attached has a very simple example of how to get an interrupt working and some notes that might be helpful for someone starting out like me. It's built for a Junebug programmer. If any experts out there have some comments on how to improve it please do. Especially the ISR (interrupt service routine), where I tried to build an if/then style statement (if light is on turn off, if off turn on) using assembly, I think there's a better/shorter way than what I have, but can't think of it right now...

Good luck!
RN
 

Attachments

  • main.asm
    5.1 KB · Views: 462
Well done, it's not easy doing things straight from the data sheet.

As far as your ISR goes, there is a much simpler way to achieve what you have done,
Code:
HighInt
;*** high priority interrupt code goes here ***  
		btfss	INTCON,INT0IF	;Check if it was INT0
		bra	Exit_int
		movlw	1
		xorwf	LATA,F
Exit_int	retfie	FAST

You could even remove the BRA as it's straight after it and make it,
Code:
;High priority interrupt vector

		ORG	0x0008
		btfss	INTCON,INT0IF	;Check if it was INT0
		bra	Exit_int
		movlw	1
		xorwf	LATA,F
Exit_int	retfie	FAST

Actually, as you only have one interrupt enabled there is no need to check which one and so,
Code:
;High priority interrupt vector

		ORG	0x0008
		movlw	1
		xorwf	LATA,F
		retfie	FAST
would suffice.

HTH

Mike.
 
THanks for the feedback!!

The XOR is a good point, I'm not familiar with all the asm instructions yet...thanks for the feedback!!

rn
 
Status
Not open for further replies.

Latest threads

Back
Top