View previous topic :: View next topic |
Author |
Message |
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
Frequency Interrupt |
Posted: Mon Mar 11, 2013 8:34 am |
|
|
I am in a middle of a project and currently I am facing a problem with the interrupt Service Routine ISR. I made some test code below:
Code: |
#include <frequency.h>
#define LCD_ENABLE_PIN PIN_A1
#define LCD_RS_PIN PIN_A3
#define LCD_RW_PIN PIN_A2
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#include <lcd1.c>
int zc_count, period_read = 0;
#int_TIMER1
void TIMER1_isr(void)
{
}
#int_TIMER2
void TIMER2_isr(void)
{
}
#int_TIMER3
void TIMER3_isr(void)
{
}
#int_EXT
void EXT_isr(void)
{
zc_count++;
if (zc_count == 3)
{
period_read = get_timer1();
set_timer1(0);
zc_count = 0;
}
}
#int_EXT1
void EXT1_isr(void)
{
}
void setup()
{
set_tris_a(0x00);
set_tris_b(0x01);
set_tris_c(0xff);
set_tris_d(0x00);
set_tris_e(0x00);
output_a(0x00);
output_b(0xfd);
output_c(0x00);
output_d(0x00);
output_e(0x00);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //104 ms overflow
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER2);
enable_interrupts(INT_TIMER3);
enable_interrupts(INT_EXT);
enable_interrupts(INT_EXT1);
enable_interrupts(GLOBAL);
lcd_init();
delay_ms(6);
lcd_gotoxy(4,1);
lcd_putc("Welcome");
}
void main()
{
setup();
while(1)
{
}
} |
for the time being please on focus on the EXT ISR, ignore the rest.
To test I am feeding an input on RB0 but the routing is not being executed.
Code: |
#int_EXT
void EXT_isr(void)
{
zc_count++;
if (zc_count == 3)
{
period_read = get_timer1();
set_timer1(0);
zc_count = 0;
}
} |
I checked everything twice but still nothing is working for the interrupt. Can somebody help me?
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Mar 11, 2013 9:26 am |
|
|
You are doing a port wide output on portB after setting the TRIS. This will set the tris on the whole port as _output_, so B0, can't work as an interrupt input.
Best Wishes |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Mon Mar 11, 2013 11:29 am |
|
|
Thanks Telmah. That was the problem. Everything is working now. In my example, I have put the RB0 (bit1) as "1" and the other bits as output "0". So if I have bit 6 and bit 7 as outputs how I can deal with this in TRIS? |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Mar 11, 2013 11:47 am |
|
|
deal with this in TRIS?
covered in user manual |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Mar 11, 2013 11:49 am |
|
|
aaronik19 wrote: | Thanks Telmah. That was the problem. Everything is working now. In my example, I have put the RB0 (bit1) as "1" and the other bits as output "0". So if I have bit 6 and bit 7 as outputs how I can deal with this in TRIS? |
1) Output individual bits to port B instead of the whole port.
2) Use TRIS after setting port B so the Int bit is an input.
3) Use fixed_IO instead of TRIS.
4) Use bit_test() to set the Int bit as an input _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|