Problem with interrupts

Thread Starter

ecka333

Joined Oct 1, 2009
76
Hello, i have made audio amplifier, and now i want to make control circuit for amplifier with pic16f876a microcontroller. I first time tried to write program in assembly with interrups. Interrupts must control amplifier channel commutation and commutation between phones/speakers, but interrupts is not working. Maybe someone could help me with the program? Zip file wih shematics and code is attached.
 

Attachments

Thread Starter

ecka333

Joined Oct 1, 2009
76
Ok, i simplified the schematics. There is three switches, connected to RB4, RB5 and RB6 inputs. Inputs RB4-RB7 have pullup resistors to ground. I wrote simply program, to test, how interrupts are working. But problem is, that interrupts work not as i want. All three switches is normally open. When i powerup the microcontroller, all three leds flashes 2 times, as the program is written. But they must flash only then, when one of three switches is pressed. So i cant understand, what is causing interrupt? So, when leds flashes 2 times, they stop. Then i press one of these 3 switches. Leds turn on, but now they do non turn off. Seems like PIC freezes. Where is the problem?
Below is shematics and code:

http://hig9vq.bay.livefilestore.com...A9TsRoQEWCQoHfvJPx1lRgsBcPxp9/code.txt?psid=1
 

Attachments

Last edited by a moderator:

Markd77

Joined Sep 7, 2009
2,806
Sorry, didn't notice there were 2 lots of code.

Page 22 of datasheet:
Reading PORTB will end the mismatch condition and allow the bit to be cleared
Something like movf PORTB, W before clearing RBIF should do the trick.
 

Thread Starter

ecka333

Joined Oct 1, 2009
76
I resolved problem with interrupt, there was problem in the code. But now i again encountered one problem. Problem is with microcontroller, it is very unstable. When i powerup the microcontroller, it often goes to state, which is not programmed, sometime freezes. But if microcontroller works normally stright after power up, theh it works normally and further. So the problem arises in the moment of power-up. Maybe someone has faced with similar problem?
 

debjit625

Joined Apr 17, 2010
790
If your MCU have dual pins for VSS and VDD connect them properly (both),next the oscillator make sure that what type of oscillator you are using like HS or XT and config the MCU at programming time ,and also make the oscillator's connection very close to mcu's pins.

Good luck
 

Thread Starter

ecka333

Joined Oct 1, 2009
76
Thanks for answers, i found the problem, why microcontroller is "unstable". I Tried to change crystals, use other power supply, add capacitor to power supply rails. Nothing helped. Then I slightly changed program: in begining i cleared PORTA, PORTB and PORTC files, thats helped wonderfully - microcontroller started act as it should. Now everything is OK:).
 
Top