Hello.

Run into strange problem. I have button connected to PORTA.0 (pulled up to 5v via 10k resistor) and buzzer to PORTB.7 Below is the shortened code.

Code:
OSCCON=%01110101  'SET INTOSC TO 8MHZ
ANSEL=%00000000
ANSELH=%00000000 'disable ADC


TRISC=%00000000 'set PORTC as output all
TRISD=%00000000 'set PORTD as output all
TRISB=%00000000 'set PORTB as output all
TRISA=%00000001 'set PORTA 0 as input, others as output
TRISE=%00000000 'same here
BUZ var PORTB.7
BUTN var PORTA.0 



DEFINE OSC 8   'OSC SPEED
'turn off all digits


PORTA=0: PORTB=0: PORTC=0: PORTD=0 : PORTE=0 'turn off all outputs

CYCLER:
if BUTN=0 then
high BUZ
pause 100
low BUZ
pause 100
endif
goto CYCLER
A simple code, when you press the button and keep it pressed, buzzer should rapidly beep. But it does not exactly works. It makes 5 normal length beeps and then 5 silent - When looked with scope, feels like first PAUSE 100 statement is being skipped - only a small impulse appears on scope on buzzer pin. After these 5 silent (short) pulses, there will come trail of 5 normal length pulses and so on. The first thoughts might be that button is faulty. But I've removed it, soldered porta.0 pin directly to GND - no change. If I remove reading of BUTN, and just leave high buz pause 100 low buz pause 100 code, it all works just fine. So it might appear that PORTA is doing something. So I changed code to the following

Code:
CYCLER:
IF BUTN=0 then
high PORTB.7
TRISB.7=1
pause 100
TRISB.7=0
pause 100
goto CYCLER:
It works fine.

It may appear that problem is solved. But wait, fun just begins. Let's slightly modify the code and add flashing led, connected to say PORTB.4

Code:
CYCLER:
IF BUTN=0 then
high PORTB.7
TRISB.7=1
TRISB.4=1
pause 100
TRISB.7=0
TRISB.4=0
pause 100
goto CYCLER:
We run into same problem. Led flashes as it should, but buzzer is outputting 5 long and 5 short pulses in the loop. If I remove "IF BUTN=0" then buzzer works again fine.

I thought that this might be Pickit 3 interfering with ports and tried to unplug it - nothing helps.

Any ideas?