Jump to content
Ian Stedman

Pic12f675 Interrupt Problem

Recommended Posts

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()

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×