|
|
View previous topic :: View next topic |
Author |
Message |
young
Joined: 24 Jun 2004 Posts: 285
|
interrupt does not work |
Posted: Thu Jun 02, 2005 9:05 am |
|
|
I have following program
Code: |
#if defined(__PCM__)
#include <12f675.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,PUT,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600, parity=N, xmit=PIN_A0,INVERT)
void LCDSetGeometry();
void LCDReset();
void LCDinit();
void LCDSetBackLight(int8 backlit);
void LCDSetContrast(int8 contr);
void LCDClrScr();
void LCDNewLine();
void LCDCR();
void LCDTab();
void LCDVerTab();
void LCDBackSpaces(int8 bspa);
void LCDSetTab(int8 Stab);
void LCDSetCursorPos(int8 x, int8 y);
void LCDClrLine(int8 x, int8 y);
void LCDSetCursorStyle();
void LCDOnOff(int8 onoff);
int16 count;
#int_ext
void ext_isr()
{
count++;
}
void main()
{
setup_comparator(NC_NC_NC_NC); //setup_comparators(NC_NC_NC_NC); no "s"
LCDinit();
LCDClrScr();
LCDSetCursorPos(0,0);
puts("*Pulse counting*");
count=0;
EXT_INT_EDGE(L_TO_H);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1)
{
LCDSetCursorPos(1,1);
printf("Num=%lu",count);
}
}
|
I want to count every input to RA2, however, the count parameter does not change, and I also put led output, It looks like that the interrupt does not function at all, what is the problem?
thank you |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Thu Jun 02, 2005 9:17 am |
|
|
Do you mean GP2? The chip powers up with GP2 configured as an analog
input. Try setup_adc(ADC_OFF); _________________ David |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Thu Jun 02, 2005 9:49 am |
|
|
Thank you. That is it.
I set it
setup_adc_ports (NO_ANALOGS);
now it is changeing the count number, however, I had a new problem
when I put it low (connect to ground) and then connect to +5v, there is a increase of count, it is correct. however, when I connect to +5v, and unplug it from RB2 pin, and replug it to +5v, there is nothing change, when I unpluge it from +5v, it is suppose to be ground right? but the interrupt does not work?
I tried to put a pull down register on RB2 pin, and tried to unplug it from +5V and repluge it to +5v, this time, the count number jumps a lot, it was not increased by one, why? |
|
|
Ttelmah Guest
|
|
Posted: Thu Jun 02, 2005 10:27 am |
|
|
The pins are CMOS inputs. They will stay at the voltage you applied for _ages_. There is nothing to make a disconnected pin go either high or low (unless you attach a pull up/down resistor either internally - where available - or externally).
The reason the count jumps a lot, is 'keybounce', If you use a mechanical contact to make a signal like this, as the signal as changed, there can be hundreds of momentary contacts as the surface irregularities come into play. This is why key scanning routines, check a key, then check it again a few mSec latter to allow the bounce time to subside.
Your system is behaving exactly as expected.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|