Jump to content


Photo

Pic12f675 Interrupt Problem


3 replies to this topic

#1 Ian Stedman

Ian Stedman

    Newbrie

  • Members
  • 2 posts

Posted 05 June 2011 - 02:36 PM

I have been using Boostbasic 6.97 to create a simple program, to respond to the interrupt on I/O pin change for a PIC12F675.
Have had little luck getting it to work but delving through the assembler, the reason was clear. At the interrupt vector (0rg 0x04) my interrupt code was not present, it was nowhere within the assembler file.

The external input comes from GPIO4 which is an input pin. GPIO 0/1 are LED outputs.

Am I doing something stupid, here is the code?

''''''''''''''''''''''''''''''''''''''''''''''
' EdgeDetect.bas
'					   
' Author: Ian Stedman
' Date: 22nd May 2011
'
' Target Device: PIC12F675A
'
''''''''''''''''''''''''''''''''''''''''''''''
' Simple software to edge detect using interruopts
' Flash an LED when edge detected. 
'
' interface type: 4bit(low nibble)
' use busy signal: use time delays
'

#pragma DATA _CONFIG, _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
#pragma CLOCK_FREQ 4000000 
' Clock frequency of 4 MHz
' Internal frequency is Fosc/4 or 1 MHz.



Sub Interrupt()

	'intcon.gie=0 
	intcon = intcon & 0x7F ' disable all interrupts
	'if intcon.gpif =1 then
	
	 gpio.0 = 0  ' Turn on LED	
	 'intcon.gpif=0 
	 ' clear interrupt?
	 intcon = intcon & 0xFE
	'endif
	'intcon.gie=1 ' re-enable interrupts 
End Sub

Sub main()
	Dim countval As Integer 'Timer count value
	Dim iopin As Byte

	' Low level hardware setup.
	tmr1h = 0 ' Clear timer 1
	tmr1l = 0
	ansel = 0 ' Disable analogue inputs
	cmcon = 7 ' Set GPIO pins as digital
	trisio = 0x30 ' Set I/O port 0-2 as outputs. GPIO4/5 as input (counter enable)
	gpio = 0x01 ' Turn off LEDs
	t1con = 0x71  'Enable timer1, 1:8 prescaler, use T1G input pin
	option_reg = 0x7  'Timer 0, 1:256 prescaler.
	'intcon.gie = 1 
	intcon = intcon | 0x88 ' Enable interrupts on I/O port change
	
	
	
	Do while 1 

		Call delay_ms(10)
		gpio.0 = 1 ' Turn LED off
		
	Loop
End Sub ' End main()


#2 Reynard

Reynard

    Maniac

  • EstablishedMember
  • PipPipPipPip
  • 659 posts
  • Gender:Male
  • Location:Scotland
  • Interests:Archery - target and field

Posted 06 June 2011 - 01:13 PM

Hi Ian,

I don't use Boostbasic but have you tried not capitalizing the interrupt function name ? It may want all lower case and not what the manual indicates.

Cheers

Reynard

#3 IanM

IanM

    Enthusiast

  • EstablishedMember
  • PipPip
  • 161 posts
  • Gender:Male
  • Location:UK

Posted 07 June 2011 - 10:08 AM

I don't use Boostbasic but have you tried not capitalizing the interrupt function name ? It may want all lower case and not what the manual indicates.

*CONFIRMED*
See the example: %ProgramFiles%\SourceBoost\Samples\Basic\interrupt.pic16.bas

There is a documentation error and NONE of the program entry points should have capitalised initial letters, so its: main(), interrupt() and interrupt_low(), NOT: Main(), Interrupt() and Interrupt_low().

This is fairly logical as these are handled by the linker which is common to alll the Boost languages and C/C++ require case sensitivity and use all lower case entry point names.

To see *exactly* what is happening, open the .casm file for your project after a successful link and you will see the code generated for each part of your source file. Your original file generates no code for Interrupt() as nothing calls it!


Edited by IanM, 07 June 2011 - 10:13 AM.


#4 Ian Stedman

Ian Stedman

    Newbrie

  • Members
  • 2 posts

Posted 07 June 2011 - 06:51 PM

Thanks for your help guys.

As stated, using interrupt() rather than Interrupt() and the assembly code is generated. I just knew it would be something stupid.

Now I can see if the code works.

Many thanks,

Ian



Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users