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.

PIC 16F877 external Interrupt Problem!!!

Status
Not open for further replies.

mesamune80

New Member
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:

Pommie

Well-Known Member
Most Helpful Member
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.
 

mesamune80

New Member
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
 

Pommie

Well-Known Member
Most Helpful Member
I guess you missed the bit about
Code:
 and [/co[I][/I]de].:rolleyes:

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

Mike.
 

mesamune80

New Member
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?
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top