#define F_CPU 7372800
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define DataPort PORTB
#define DataDDR DDRB
ISR(INT0_vect)
{
unsigned char i;
_delay_ms(500); // because of debouncing
/* This for loop blink LEDs on Dataport 5 times*/
for(i = 0; i < 5; i++)
{
DataPort = 0x00;
_delay_ms(500);
DataPort = 0xFF;
_delay_ms(500);
}
DataPort = 0;
int main(void)
{
DDRD = 1<<PD2; // Set PD2 as input (Using for interupt INT0)
PORTD = 1<<PD2; // Enable PD2 pull-up resistor
cli();
GICR = 1<<INT0; // Enable INT0
MCUCR = 1<<ISC01; // Trigger INT0 on falling edge
sei(); // Enable Global Interrupt
DataDDR = 0xFF; // Configure Dataport as output
DataPort = 0x01; // Initialise Dataport to 1
while(1)
{
if(DataPort >= 0x80)
DataPort = 1;
else
DataPort = (DataPort << 1);
_delay_ms(500);
}
}
C:\Users\User 1>cat low.bin high.bin
0xe4
0x99
#define F_CPU 7372800
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define DataPort PORTB
#define DataDDR DDRB
int ininterrupt;
ISR(INT0_vect)
{
ininterrupt = 1;
}
int main(void)
{
unsigned char i;
ininterrupt = 0;
DDRD = 1<<PD2;
PORTD = 1<<PD2;
cli();
GICR = 1<<INT0;
MCUCR = 1<<ISC01;
sei();
DataDDR = 0xFF;
DataPort = 0x01;
while(1)
{
if(DataPort >= 0x80)
DataPort = 1;
else
DataPort = (DataPort << 1);
_delay_ms(500);
if (ininterrupt == 1)
{
for(i = 0; i < 5; i++)
{
DataPort = 0x00;
_delay_ms(500);
DataPort = 0xFF;
_delay_ms(500);
}
DataPort = 0;
ininterrupt = 0;
}
}
}
DDRD = 1<<PD2;
PORTD = 1<<PD2;
DDRD = ~(1<<PD2); // sets pin as output
GICR|=1<<INT0;
GICR=1<<INT0;
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="int0" />
<Option pch_mode="2" />
<Option compiler="avrgcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/int0" prefix_auto="1" extension_auto="0" />
<Option working_dir="" />
<Option object_output="obj/Debug/" />
<Option type="5" />
<Option compiler="avrgcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/int0" prefix_auto="1" extension_auto="0" />
<Option working_dir="" />
<Option object_output="obj/Release/" />
<Option type="5" />
<Option compiler="avrgcc" />
<Compiler>
<Add option="-Os" />
</Compiler>
</Target>
<Environment>
<Variable name="MCU" value="atmega32" />
</Environment>
</Build>
<Compiler>
<Add option="-mmcu=atmega32" />
<Add option="-Os" />
<Add option="-Wall" />
<Add option="-DF_CPU=7372800UL" />
<Add directory="../../../WinAVR-20100110/lib/gcc/avr/4.3.3/include" />
<Add directory="../../../WinAVR-20100110/avr/include" />
</Compiler>
<Linker>
<Add option="-mmcu=atmega32" />
<Add option="-Wl,-Map=$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).map,--cref" />
</Linker>
<ExtraCommands>
<Add after='cmd /c "avr-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).lss"' />
<Add after="avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).hex" />
<Add after="avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).eep" />
<Add after="avr-objcopy --no-change-warnings -j .lock --change-section-lma .lock=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).lock" />
<Add after="avr-objcopy --no-change-warnings -j .signature --change-section-lma .signature=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).sig" />
<Add after="avr-objcopy --no-change-warnings -j .fuse --change-section-lma .fuse=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).fuse" />
<Add after="srec_cat $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).fuse -Intel -crop 0x00 0x01 -offset 0x00 -O $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).lfs -Intel" />
<Add after="srec_cat $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).fuse -Intel -crop 0x01 0x02 -offset -0x01 -O $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).hfs -Intel" />
</ExtraCommands>
<Unit filename="fuse.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
-------------- Clean: Release in int0 (compiler: GNU AVR GCC Compiler)---------------
Cleaned "int0 - Release"
-------------- Build: Release in int0 (compiler: GNU AVR GCC Compiler)---------------
avr-gcc.exe -mmcu=atmega32 -Os -Wall -DF_CPU=7372800UL -Os -I..\..\..\WinAVR-20100110\lib\gcc\avr\4.3.3\include -I..\..\..\WinAVR-20100110\avr\include -IC:\WinAVR-20100110\avr\include -c fuse.c -o obj\Release\fuse.o
avr-gcc.exe -mmcu=atmega32 -Os -Wall -DF_CPU=7372800UL -Os -I..\..\..\WinAVR-20100110\lib\gcc\avr\4.3.3\include -I..\..\..\WinAVR-20100110\avr\include -IC:\WinAVR-20100110\avr\include -c main.c -o obj\Release\main.o
avr-g++.exe -LC:\WinAVR-20100110\avr\lib -o bin\Release\int0 obj\Release\fuse.o obj\Release\main.o -mmcu=atmega32 -Wl,-Map=bin\Release\int0.map,--cref
Output size is 2.38 KB
Running project post-build steps
cmd /c "avr-objdump -h -S bin\Release\int0 > bin\Release\int0.lss"
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex bin\Release\int0 bin\Release\int0.hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex bin\Release\int0 bin\Release\int0.eep
avr-objcopy --no-change-warnings -j .lock --change-section-lma .lock=0 -O ihex bin\Release\int0 bin\Release\int0.lock
avr-objcopy --no-change-warnings -j .signature --change-section-lma .signature=0 -O ihex bin\Release\int0 bin\Release\int0.sig
avr-objcopy --no-change-warnings -j .fuse --change-section-lma .fuse=0 -O ihex bin\Release\int0 bin\Release\int0.fuse
srec_cat bin\Release\int0.fuse -Intel -crop 0x00 0x01 -offset 0x00 -O bin\Release\int0.lfs -Intel
srec_cat bin\Release\int0.fuse -Intel -crop 0x01 0x02 -offset -0x01 -O bin\Release\int0.hfs -Intel
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)
In the meantime i found how my fuse bits are set:
Code:C:\Users\User 1>cat low.bin high.bin 0xe4 0x99
If this is impotrant for interrupts problem anyway...
These fuse settings are for internal RC 8MHz, your mcu is not using the crystal but this is not the cause of the interrupt malfunction, it will just give a little sorter delays.
For GCC - Integer 'ininterrupt' should be declared globally but should be declared as 'volatile' also.
That should be done so for all other interrupts in order to work.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?