how to use Timer/Counter registers in tinkercad

hi there,

I was using Atmega2560. but now am shifting to uno and working on tinkercad simulator.
i have tried to run the code like this. but it doesn’t run as it does on 2560… can anyone tell me why. and how could i use this syntax on tinkercad. my code is.

#include <avr/io.h>
void fordelay()
{
TCNT0 = 0x74; // load TCNT0
TCCR0A = 0x00; // Timer0, Normal Mode
TCCR0B = 0x02; // 1/8 prescaler
while((TIFR0 & (1<<TOV0)) == 0); // wait for TOV0 to roll over
TCCR0B = 0x00; // stop the clock source
TIFR0 = 0x1<<TOV0; // clear TOV0
}
int main (void)
{
DDRA = 0xFF; // OUTPUT
while(1)
{
PORTA |= (1<<4);
fordelay();
PORTA &= ~(1<<4);
fordelay();
}
return 0;
}
thanks

TinkerCad uses Arduino code. Your code is not a Arduino sketch.

The fastest way to toggle a pin with the ATmega328P, is to write to the PIN register: https://forum.arduino.cc/index.php?topic=193537.msg1430074#msg1430074.

To output a frequency, you can use the Arduino tone(): tone() - Arduino Reference.

To output a frequency with a hardware timer, there is ToneAC: teckel12 / Arduino toneAC / wiki / Home — Bitbucket.