Hardwareinterrupt

Gast #1877820
Lesenswert?

Hallo,

ich versuch schon ne weile nen Hardwareinterrupt bei nem ATmega8 
auszulösen und es will einfach nicht funktionieren.Das hier ist mein 
Programmcode und ist in Pascal programmiert.


var
  i,:byte;


{--------------------------------------------------------------}
{ functions }

procedure InitPorts;
begin
  DDRD := %01100000;
  DDRB := %00000000;
  PortB:= %00000000;
  GICR := %11000011;
  MCUCR:= %00001100;
  sreg := %10000000;


  end InitPorts;

Interrupt Int0;
begin

i:=PinB.1;
sdelay(100);
if i=1 then
PortD.5:=1;
endif;
end;

Interrupt Int1;
begin
i:=PinB.1;
sdelay(100);
if i=1 then
PortD.5:=1;
endif;
end;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}

begin
  InitPorts;
  EnableInts;

  loop

  endloop;
end Interrupts.

mfg Thomas
#1877856
Lesenswert?

Ich kann zwar kein Pascal mehr (lang ists her ...), aber was mir 
trotzdem auffällt:  Wozu setzt Du IVSEL und IVCE in GICR (soweit habe 
ich mir die Mühe gemacht, die Bits rückwärts aufzudröseln, weiter nicht 
mehr.  Nimm bitte ihre symbolischen Namen)?  Du machst die Zuweisung nur 
einmal, somit dürfte sie ohne weiteren Einfluss bleiben, aber sinnlos 
ist es allemal.  Wäre die Zuweisung tatsächlich wirksam, würde sie zudem 
nur dann keinen Schaden anrichten, wenn Du speziell für einen Bootloader 
o.ä. kompilieren würdest.

In Deinem Programm löscht niemand PortD.5, wenn es einmal gesetzt ist. 
Ist das beabsichtigt?
Gast #1877869
Lesenswert?

Hi mein lauffähiger Code(schnipsel) sieht so aus: (mikroPascal/ATmega32)
Procedure Int0_ISR(); org IVT_ADDR_INT0;
begin
  // ...
end;
//-------------------------------------------------
Procedure Int1_ISR(); org IVT_ADDR_INT1;
begin
  // ...
end;
//-------------------------------------------------
// MAIN
 // ISC01=1, ISC00=0: The falling edge of INT0 generates an interrupt 
request.
  MCUCR.ISC00 := 0;   //  \ call ISR on
  MCUCR.ISC01 := 1;   //  / falling edge
  GICR.INT0   := 1;   // global interrupt control register

  // ISC11=1, ISC10=0: The falling edge of INT1 generates an interrupt 
request.
  MCUCR.ISC10 := 0;   //  \ call ISR on
  MCUCR.ISC11 := 1;   //  / falling edge
  GICR.INT1   := 1;   // global interrupt control register

  // setup timer1, enable interrupts
  TOIE1_bit  := 1;    // Timer1 overflow interrupt enable
  TCCR1B := %010;     // Start timer with 8 prescaler
  SREG_I_bit := 1;    // global Interrupt enable

// while ...

end.
Gast #1878547
Lesenswert?

Hier ist nochmal mein Prog jetzt n bischen ordentlicher.
Und das mit PortD soll so sein ich will erstmal nur sehen ob der 
Interrupt funktioniert.


procedure InitPorts;
begin
  DDRD := %01100000;
  GICR := %01000000; //INT0 activation
  MCUCR:= %00001100; //The rising edge of INT1 generates interrupt 
request
  sreg := %10000000; //global Interrupt enable
end InitPorts;

Interrupt Int0;
begin
PortD.5:=1;

end;

{--------------------------------------------------------------}
{ Main Program }
{$IDATA}

begin
  InitPorts;
  EnableInts;

  loop

  endloop;

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren