PDA

View Full Version : INTCON and 16F628



Dariolo
- 14th April 2009, 12:43
I started to do some GSM controller project with the PIC, as a school project. But I constantly arises a problem that my pic "goes crazy". At end I think it's problem with the Interrupts. I had connected a LED on RB.0 that is a INT input, and when i set the RB.0, in the program, on 1 the PIC start to act crazy (LED's blink, and he send some partial informations trought the USART). I tried to not set RB.0 on 1 and everything works fine. So I tried to connect the LED on RB.4 (it's a INT input again) and the same problem occurs when i set it to 1. I tried to set the INTCON=0 (INTCON.3, INTCON.4=0) but the problem is still there.

Here is some example of the PBP code:



DEFINE OSC 8
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 12
CMCON = 7
INTCON=0
symbol LED1=PORTB.3
SYMBOL LED2=PORTB.4
SYMBOL SDA = porta.0
SYMBOL SCL = porta.1
DEFINE I2C_SDA PORTA.0
DEFINE I2C_SCL PORTA.1
adr VAR BYTE
ZNAK VAR BYTE [5]
OUTPUT LED2
OUTPUT LED1
adr=20

serial:

hserout ["SERIAL"]

hserin 3000, serial, [str ZNAK\5]
pause 100
HIGH LED1
PAUSE 1000
LOW LED1

I2CWRITE SDA, SCL, $A0, adr, [STR ZNAK\5]
PAUSE 10
HSERIN [WAIT ("OK")]

GOSUB LDE
PAUSE 500

HIGH LED2
PAUSE 2000
GOTO SERIAL
LDE:

HIGH LED2
HIGH LED1
PAUSE 1500
LOW LED2
PAUSE 1500
LOW LED1
HIGH LED2
PAUSE 1500
HIGH LED2
LOW LED1
PAUSE 1500
LOW LED2
RETURN

END


I hope someone can help me!

P.S. Sorry for my beeeeeddd english!!!!

Archangel
- 15th April 2009, 03:40
Floating ports and noisy power are 2 BIG reasons for PICs to go crazy. Set your tris registers and Ports in your code to a known state and tie unused pins to VSS or VDD through 10k resistors. Put a .01uf and a 10uf capacitor across the power lines as close to the pic as possible to short the noise there, even a ferrite bead in series with the B+ is helpful too.

mister_e
- 15th April 2009, 03:49
It can't be interrupt as you don't use any in your code.

As Joe said, check you hardware. Also make sure your config fuses are set for HS_OSC and LVP_OFF. Same goes for MCLR pin.

mister_e
- 15th April 2009, 03:54
If you're doing it on a breadboard, then things can go really bad. Some old breadboard can have such capacitance that may screw your OSC stability.

Keep wiring short and clean, ground the back plane (if any), and sprinkle few 0.1 uF+10uF tantalum all over will not hurt.