|
|
View previous topic :: View next topic |
Author |
Message |
epulse Guest
|
Question! External interrupt in PIC12F675 |
Posted: Sun May 29, 2005 10:18 pm |
|
|
I'm just a beginner with C, so please don't be too hard on me regarding my style!
The code below does try to work. And I use the CCS-C compiler and PIC12F675.
The problem is the external interrup in PIC12F675.
I want to control the LED with PIC12F675, but the external interrupt don't operate.
What could be causing this?
=================================
#include <12f675.h>
#fuses INTRC,NOWDT,NOCPD,PROTECT,NOMCLR
#fuses NOPUT,NOBROWNOUT
#use delay (clock=4000000)
#use fixed_io(a_outputs=pin_a0, pin_a1)
#byte porta=0x06
#byte intcon=0x0b
#bit INTF=INTCON.1
#int_ext
ext_isr()
{
INTF=0;
output_bit(PIN_A0,1);
}
void main(void)
{
ext_int_edge(0,L_to_H);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(true)
{
output_bit(PIN_A0,0);
}
}
[/b] |
|
|
Ttlemah Guest
|
|
Posted: Mon May 30, 2005 5:20 am |
|
|
First comment, you don't need to clear the interrupt flag in the handler. The compiler will do this for your, unless the 'noclear' option is used in the definition. It doesn't 'matter', but is an unecessary instruction.
The same applies to the ext_int_edge definition, on the 12675, with only one interrupt, you just need:
ext_int_edge(L_to_H);
You won't see an LED operate with the code as shown. The interrupt will set the bit on, but as soon as the interrupt exits, the main loop will clear it. The LED will light for a few uSec only, which unless the interrupt if being triggered at a frequent interval, will not be enough to be visible.
Rewrite the main loop with:
Code: |
while (true) {
if (input(PIN_A0)) {
delay_ms(10);
output_low(PIN_A0);
}
}
|
This way the LED will light for 10mSec (plus the interrupt return time), when triggered.
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
|