Code: Alles auswählen
#include <Arduino.h>
#include <avr/io.h>
#include <avr/interrupt.h>
void setup() {
pinMode(13, OUTPUT); // Pin 13 Output
TCCR2A = 0; // set timer2 normal mode
TCCR2B |= _BV(CS20); // timer2 clock = system clock
TIMSK2 |= _BV(TOIE2); // enable timer2 overflow interrupt
sei(); // enable interrupts
}
void loop() {
delay(1000); // wait for a second
}
ISR(TIMER2_OVF_vect) { // === Wie unter Pascal ?
static int z = 0;
z += 1;
if (z == 500) {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
}
if (z >= 1000) {
digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
z = 0;
}
}
Jetzt wollte ich dies in Pascal umsetzen, nur weis ich nicht, wie ich das mit ISR(TIMER2_OVF_vect) lösen soll.
Jemand eine Idee ?
Code: Alles auswählen
program Project1;
const
BP5 = 5; // Pin 13 des Arduino
sl = 250000;
WGM01 = 1;
CS20 = 0;
var
zaehler: integer;
procedure mysleep(t: int32);
var
i: Int32;
begin
for i := 0 to t do begin
asm
Nop;
end;
end;
end;
procedure sei; assembler;
asm
Sei;
end;
procedure ISR(TIMER2_OVF_vect); // Wie geht dies ?
begin
Inc(zaehler);
if zaehler = 500 then begin
PORTB := PORTB or (1 shl BP5);
end;
if zaehler = 1000 then begin
PORTB := PORTB and not (1 shl BP5);
zaehler := 0;
end;
end;
begin
DDRB := DDRB or (1 shl BP5); // Pin 13 Output
TCCR2A := 0; // set timer2 normal mode
TCCR2B := TCCR2B or (1 shl CS20); // timer2 clock = system clock
TIMSK2 := TIMSK2 or (1 shl TOIE2); // enable timer2 overflow interrupt
sei();
repeat
mysleep(sl);
until 1 = 2;
end.
In der Unit Atmega328p habe ich folgende Zeile gefunden:
Code: Alles auswählen
procedure TIMER2_OVF_ISR; external name 'TIMER2_OVF_ISR'; // Interrupt 9 Timer/Counter2 Overflow
Diese befinde sich im implementation-Teil und somit nicht öffentlich.
Ob die weiter hilft ?