PDA

View Full Version : Interrupt question



stone
- 25th January 2005, 22:03
(first interrupt program attempt - thanks)

I am trying to sense an interrupt signal on portb0 and then read portb1 and portb2 as inputs.

Is this possible?

This is a rotary encoder that is put thru a flipflop and I have used both outputs thru diodes as my interrupt trigger.

It was working, but not correctly. I'm not sure if my board is noisy or if the program is not working correctly.

I would like to know if intcon is set properly and if I need to set the register to make high priority interrupts.

I'm a little confued about the datasheet, it doesn't seem to specifically talk about using portb<0-2>. And how does the pic know to watch for an interrupt on portb0?

Thanks. /code below

INCLUDE "modedefs.bas"
DEFINE LOADER_USED 1
DEFINE OSC 40
value var byte
cw var portB.1
ccw var portB.2
INTCON = %01001000
TRISB.1 = 1
TRISB.2 = 1

value=0
begin:
on interrupt goto myint
GOTO begin

'Interrupt handler
Disable
myint:

value = value + cw - ccw

serout2 portc.6, 16468, [dec3 value,13,10]
INTCON.1 = 0
resume
Enable

END

btw - is there a way to reset the printing using serout2 to the home position?

stone
- 25th January 2005, 22:07
above, I'm using a pic 18F452 with the 40mhz clock

mister_e
- 25th January 2005, 23:11
try this one


INCLUDE "modedefs.bas"
DEFINE LOADER_USED 1
DEFINE OSC 40

TRISB.0 = 1
TRISB.1 = 1
TRISB.2 = 1
TRISB.3 = 0
TRISC.6 = 0

PORTC.6 = 1
DelayLoop var word
value var byte
cw var portB.1
ccw var portB.2
MainLoopStatuLED var PORTB.3

INTCON = %10010000 'Enable all unmasked interrupt, Enable RB0/INT0 Interrupt

on interrupt goto myint
value=0

begin:
' Main Loop will blink a led every 0.5 secondes
Toggle MainLoopStatusLED
For delayloop = 1 to 50000
Pauseus 10 ' using Pauseus to avoid interrupt latency
Next
GOTO begin


'Interrupt handler
Disable
myint:
value = value + cw - ccw
serout2 portc.6, 16468, [dec3 value,13,10]
INTCON.1 = 0
resume
Enable



btw - is there a way to reset the printing using serout2 to the home position?

Are you using a serial LCD???

Try serout2 portc.6, 16468, [254,1,dec3 value,13,10]

Make sure your MCLR pin (PIN1) is attach to 5V with a pull-up resistor. 0.1uF + 47 uF can be installed to your supply line, close to the pic, to avoid nois and glitches.

try to remove all interrupt and test it in the main loop. Is it working without interrupt ?

If nothing is better, can you provide your schematic ??