Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 23rd June 2008, 04:17 AM   #1
Unhappy PIC 16F877 external Interrupt Problem!!!

Hi all,

i had figuring this thing since last week, but i still not manage to find out what is the cause of this problem.............i also using the button debouce to detect my button.

Below is the code:
ADCON1 = 7 '%10001000 'A4-7 analog RA3 +Vref RA2 -Vref
TRISA = %11111111
TRISB = %00000001
TRISC = %11100000
TRISD = %11100011
OPTION_REG.6 = 1 'RB0/INT edge triggered (rising edge)
OPTION_REG.7 = 1 'weak pull up disable.
INTCON = %10010000

'Button debouce routine

If PORTA.0 = 0 Then Goto press 'button debounce checking..
press:
Disable' disable all unmask interrup
While PORTA.0 = 1
delay = 20
WaitMs delay
Wend
While PORTA.0 = 0 And delay <> 0
delay = delay - 1
Wend
If delay <> 0 Then
Goto loop2
Else
Goto release
Endif

release:
Disable
While PORTA.0 = 0
delay = 20
WaitMs delay
Wend
While PORTA.0 = 1 And delay <> 0
delay = delay - 1
Wend
If delay <> 0 Then
Goto release
Else
Goto m1
Endif


m1:

High PORTC.5 'my solenoid output..
WaitMs 500

Enable 'enable all unmask interrupt


While PORTC.6 <> 0

dir1 = 1 'CW DOWN

High PORTC.0 'pulse port for m1
WaitMs 1
Low PORTC.0
WaitMs 1
'count1 = count1 + 1

Wend

On Interrupt "My ISR

If INTCON.INTF = 1 Then 'RB0 External interrupt flag bit=1 (external interrupt occured)

INTCON.INTF = 0
Goto init
'Goto loop
Endif
'INTCON = %10010000 'renable RB0 interrupt and all unmask interrupt.
Resume
__________________________________________________ __________________________

ok this is the problem i am facing now....

the RB0 interrupt automatically executed although the interrupt button is not press.....>.<"
so everytime the program come to enable it automatically go to interrupt service routine.Anyone know what is the cause of this?

Thanks for all your help and guidance.

Last edited by mesamune80; 23rd June 2008 at 04:19 AM.
mesamune80 is offline  
Old 23rd June 2008, 04:26 AM   #2
Default

Firstly, when you post code put [code] before it and [/code] after it so it keeps it's formatting.

As for your code, your interrupt routine does a jump to init. The label init doesn't appear to exist.

Mike.
Pommie is online now  
Old 23rd June 2008, 09:35 AM   #3
Default

Sorry ,for the counfusion.

the init routine is as below:

init:

Low PORTC.5 /solenoid OFF pull to GND go downwards
WaitMs 5

While PORTD.0 = 0

dir1 = 0
High PORTC.0
WaitMs 1
Low PORTC.0
WaitMs 1


Wend


For j = 0 To count2 Step 1

dir2 = 0
High PORTC.2
WaitUs 200 '800
Low PORTC.2
WaitUs 200 '800
Next j
count2 = 0


Goto loop
mesamune80 is offline  
Old 23rd June 2008, 09:38 AM   #4
Default

I guess you missed the bit about [code] and [/code].

Anyway, you cannot jump from an interrupt into your main code.

Mike.
Pommie is online now  
Old 23rd June 2008, 10:48 AM   #5
Default

what you mean is after interrupt then must go to resume? cannot skip this?
mesamune80 is offline  
Old 23rd June 2008, 11:39 AM   #6
Default

Quote:
Originally Posted by mesamune80 View Post
what you mean is after interrupt then must go to resume? cannot skip this?
Yes, so in your interrupt set a flag and test it in your main code.

Mike.
Pommie is online now  
Old 24th June 2008, 02:18 AM   #7
Default

ok i'll try than on and see how,i need this interrupt to stop whatever /whenever the code is doing...so that the code can go to initial state.is like a reset button actually.can i do that?
mesamune80 is offline  
Reply

Tags
external, interrupt, pic, problem

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
URGENT!! 16F877 & USART & Interrupt & Recieve Problem DaMieN Micro Controllers 0 18th September 2007 11:53 AM
RB0 External Interrupt Problem Suraj143 Micro Controllers 6 30th August 2007 07:26 AM
external interrupt neelam29 Micro Controllers 4 11th March 2006 02:50 PM
external interrupt address neelam29 Micro Controllers 4 25th February 2006 03:00 AM
External Interrupt not working - 16F877 usaf1 Micro Controllers 0 15th September 2003 01:17 AM



All times are GMT. The time now is 02:53 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker