|
|
View previous topic :: View next topic |
Author |
Message |
Bieli Guest
|
External Interrupt |
Posted: Tue Jan 14, 2003 12:41 am |
|
|
In this program the led should blinking every one second. The signal is taken from real time clock. But it blinked 8 sometimes 2 or 4 times and after it it stop. The low level is puted on RB0, but the interrupt don't delete it ( WRITE_PCF8583( 00, 04 ); ) so propably the interrupt isn't taken.
The problem can be coused that I use 16F874.h and 16F874A chip <- Is this problem or my code is wrong?
#include <16f874.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#include <b_lcd.c>
#define EEPROM_SDA PIN_C2
#define EEPROM_SCL PIN_C3
#include <PCF8583.c>
#int_ext
Przerwanie_T1()
{ output_bit(pin_d0,!input(pin_d0)); //Blinking led
WRITE_PCF8583( 00, 04 ); //Delete interrupt flag in PCF8583
}
main() {
enable_interrupts(global);
enable_interrupts(INT_EXT);
EXT_INT_EDGE(H_TO_L);
init_PCF8583();
lcd_init();
.....
do {
printf(lcd_putc,"\f\%X:\%X:\%X\n \%X-\%X \%X",READ_PCF8583(04),READ_PCF8583(03),READ_PCF8583(02),READ_PCF8583(05),READ_PCF8583(06),READ_PCF8583(00));
} while (TRUE);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10673 |
|
|
kolio Guest
|
Re: External Interrupt |
Posted: Tue Jan 14, 2003 2:16 am |
|
|
Hi,
What will happen while execution of endless loop readings READ_PCF8583(xx) there appears an interrupt from RTC and in the middle of one reading at I2C bus ISR starts to write to RTC?
I don't know if at READ_PCF8583() the interrupts are previously disabled in order to avoid collisions, but you should prevent the asynchronous reference to RTC.
You can put TF clearing outside of ISR, like this:
short TF;
#int_ext
Przerwanie_T1()
{ output_bit(pin_d0,!input(pin_d0)); //Blinking led
TF = 1;
}
main() {
enable_interrupts(global);
enable_interrupts(INT_EXT);
EXT_INT_EDGE(H_TO_L);
init_PCF8583();
lcd_init();
TF = 0;
.....
do {
if(TF) {
WRITE_PCF8583( 00, 04 ); //Delete interrupt flag in PCF8583
TF = 0;
}
printf(lcd_putc,"\f\%X:\%X:\%X\n \%X-\%X \%X",READ_PCF8583(04),READ_PCF8583(03),READ_PCF8583(02),READ_PCF8583(05),READ_PCF8583(06),READ_PCF8583(00));
} while (TRUE);
}
According to me you shouldn't worry too much about the versions 874 and 874A.
Wish you luck!
___________________________
This message was ported from CCS's old forum
Original Post ID: 10677 |
|
|
Tomi Guest
|
Re: External Interrupt |
Posted: Tue Jan 14, 2003 2:19 am |
|
|
How do you attach the LED to D0 bit? Keep in mind that the input() function reads the pin so it could be 0 even if the LED lights. Additional problem that the input() function sets that pin to input first then the output_bit() function sets back it to output.
It would be better to use a RAM flag to set/reset it and then copy its state to pin_D0.
:=In this program the led should blinking every one second. The signal is taken from real time clock. But it blinked 8 sometimes 2 or 4 times and after it it stop. The low level is puted on RB0, but the interrupt don't delete it ( WRITE_PCF8583( 00, 04 ); ) so propably the interrupt isn't taken.
:=The problem can be coused that I use 16F874.h and 16F874A chip <- Is this problem or my code is wrong?
:=
:=#include <16f874.h>
:=#fuses HS,NOWDT,NOPROTECT,NOLVP
:=#use delay(clock=4000000)
:=#include <b_lcd.c>
:=
:=#define EEPROM_SDA PIN_C2
:=#define EEPROM_SCL PIN_C3
:=
:=#include <PCF8583.c>
:=
:=#int_ext
:=Przerwanie_T1()
:={ output_bit(pin_d0,!input(pin_d0)); //Blinking led
:= WRITE_PCF8583( 00, 04 ); //Delete interrupt flag in PCF8583
:=}
:=main() {
:=
:= enable_interrupts(global);
:= enable_interrupts(INT_EXT);
:= EXT_INT_EDGE(H_TO_L);
:= init_PCF8583();
:= lcd_init();
:=
:= .....
:=
:= do {
:= printf(lcd_putc,"\f\%X:\%X:\%X\n \%X-\%X \%X",READ_PCF8583(04),READ_PCF8583(03),READ_PCF8583(02),READ_PCF8583(05),READ_PCF8583(06),READ_PCF8583(00));
:= } while (TRUE);
:=
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10678 |
|
|
|
|
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
|