PDA

View Full Version : Interrupt handling on 16F628A



Mugelpower
- 21st January 2008, 21:24
Hi you all!

made a very small PBP programm that should work with external interrupts on RB.0.

Ha! won´t work of course otherwise I won´t post this thread.

Should send a pulse out on RB.7 (blink an LED) every time on rising edge at RB.0 , that means when a pulse gets in.
Later on when the interrupt works a byte value should be loaded serially into the pic to calculate and cause a delay before the "blink" pulse. I got the serial communication working between two PICs . The value loading doesn´t need to be in sync with the input pulse but the start of the blink hat to. Damned!

'************************************************* *******************************************
' 16F628A 4 Mhz crystal
' damn program should blink an LED every time a pulse goes into RB.0
' later a value should be serial loaded and set a delay before the blink pulse
'************************************************* *******************************************

'
' DEFINITIONS


DEFINE OSC 4
CMCON=%00000111
inputData var word ' variable to receive data into
pulseWidthVar var word



' START OF MAIN PROGRAM
'
CMCON = 7 ' RA0-RA3 are digital I/O
TRISA = 0 ' PORT A is output
TRISB = 1 ' RB0 is Input others output


on interrupt goto ISr
OPTION_REG = %01000000 'when RB.0 goes high the interrupt should work
INTCON = %10010000

main:
portb.7 = 0

serin2 portB.0,16468, [inputData] 'for the future to load a value
pulseWidthVar = inputData

goto main

disable

ISR:

pulsout portb.7, 2000 'blink LED 0.02 sec one time when RB.0 goes high
INTCON = %10010000
RESUME 'resume main program
Enable 'Enable interrupts

END ' End of program


Whats wrong with my interrupt?

Thanks in Advance. You helped me quite a lot before!

Darrel Taylor
- 21st January 2008, 23:20
You should be more selective in the things you change.

OPTION_REG = %01000000 'when RB.0 goes high the interrupt should work
Apparently, the idea in that statement was to set INTEDG so that the interrupt would trigger on the Rising edge.

Rising edge is the default, so it didn't need to be changed. But in the process, you've changed everything else in the OPTION register.

The WDT prescaler is assigned to TMR0, and the WDT will now timeout in only 18 ms.
Settings for TMR0 are changed too.
PORTB Pull-ups are enabled, which is probably your main problem.

When you want to change INTEDG, just change it

OPTION_REG.6 = 1

But then, like I said, it's already the default.<hr>
Same thing applies to your use of INTCON.

When using ON INTERRUPT, PBP controls the GIE bit (INTCON.7).
Changing it yourself can cause problems.

And change each bit individually, so that it doesn't interfere with other things.

INTCON.1 = 0 ; Clear External Interrupt Flag
INTCON.4 = 1 ; Enable External Interrupt

-- or --

INTF VAR INTCON.1
INTE VAR INTCON.4

INTF = 0 ; Clear External Interrupt Flag
INTE = 1 ; Enable External Interrupt

hth,