Interrupt mit ATmega8

tilo
 
Avatar
 
Subject:

Interrupt mit ATmega8

 · 
Posted: 11.10.2010 - 08:07  ·  #1
Hi,

ich hab schonmal was zu meinem Problem gepostet aber nicht wirklich hilfe bekommen also versuch ichs nochmal.
Also ich bin Anfänger und versuch grad ein kleines Programm mit ein Interrupt zuschreiben.Will aber weder aufm Simulator noch sonst wie funktionieren und hab schon alles mögliche ausprobiert und kann den Fehler einfach nicht finden.Das Programm soll bei einem Signal an PinD.2 ein Interrupt auslösen und in diesem soll eine LED eingeschaltet werden.

Code

program Interrupts;

{$NOSHADOW}
{ $WG} {global Warnings off}


Device = mega8, VCC=5;
{ $BOOTRST $00C00} {Reset Jump to $00C00}

Define_Fuses
Override_Fuses;
NoteBook = A;
COMport = USB;
LockBits0 = [];
FuseBits0 = [];
FuseBits1 = [];

Import SysTick ;
From System Import ;


Define
ProcClock = 8000000; {Hertz}
SysTick = 10; {msec}
StackSize = $0032, iData;
FrameSize = $0032, iData;

Implementation

{$IDATA}

{--------------------------------------------------------------}
{ Type Declarations }

type


{--------------------------------------------------------------}
{ Const Declarations }

{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var


{--------------------------------------------------------------}
{ functions }
procedure InitPorts;
begin
DDRD := %01100000; //set PinD.5/6 as output
GICR := GICR OR %11000000; //INT0/INT1 activation
MCUCR:= MCUCR or %00001111; //The rising edge of INT1/INT0 generates an interrupt request
GIMSK:= GIMSK or %11000000;
end InitPorts;

Interrupt INT0;
begin
Toggle(PortD.5);
end;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}

begin
InitPorts;
EnableInts;

loop
nop;
endloop;
end Interrupts. //Programm heißt Interrupts


tilo
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

Re: Interrupt mit ATmega8

 · 
Posted: 11.10.2010 - 09:44  ·  #2
Hi tilo.

Quote

PinD.5:=1;


What the purpose of this statement?

Also why are you setting D2, D3 as outputs? They are interrupts 0 and 1 which should be inputs. I am sure, however, you did not do that last time.

I assume that you have external pull/ups or pull/downs when the input is not driven, or that it is driven both high and low? If not you must either add these to your circuit or operate the internal pull-ups.

Regards

Merlin
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Interrupt mit ATmega8

 · 
Posted: 11.10.2010 - 14:50  ·  #3
Hallo tilo,

da geht garnichts:
PinD.5:=1;
1. ist PinX immer ein Input, also muss es heissen: PortD.5:= 1;
2. wäre es besser so:
Toggle(PortD.5);
Damit wird bei jedem Interrupt dieser Port Pin umgeschaltet.

Das Init des Interrupts habe ich nicht geprüft...

rolf
tilo
 
Avatar
 
Subject:

Re: Interrupt mit ATmega8

 · 
Posted: 12.10.2010 - 08:13  ·  #4
Ich erklär jetzt noch ma genauer mein Problem.
Undzwar das Programm an sich funktioniert ja ich krieg keine Fehlermehldung oder so im Simulator.Nur ist das Problem das er nicht den Interrupt auslöst also INTF setzt wenn ich es ausprobieren will, egal wie ich die Register setze ob nun Int1 oder Int0 oder auf welche Flanke er reagieren soll oder sonstwas.
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   78   92 · Page-Gen-Time: 0.021869s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI