/*using Timer 1 for delay in Normal mode(TIMER1 - 16bit)
ATMega2560 clock = 16MHz*/
//#include<stdint.h>
void T0_ms_Delay(uint16_t);
void setup() {
volatile uint8_t *DDR_F=(volatile uint8_t *)0x30;
*DDR_F|=(1<<3); //Settng portF 3rd pin as output pin
volatile uint8_t *PORT_F=(volatile uint8_t *)0x31;
Serial.begin(9600);
while(1){
*PORT_F^=(1<<3);
T0_ms_Delay(50);
}
}
void T0_ms_Delay(uint16_t ms){
for(uint16_t i=0;i<ms;i++){
Serial.print(i,DEC);
Serial.print("\t");
volatile uint8_t *TIMER0_TCNT0 = (volatile uint8_t *)0x46;
*TIMER0_TCNT0 = 6; //takes 250 pulses to generate 1ms delay, So 256-250=6, So count starts from 6
volatile char *TIMER0_TCCR0A = (volatile char *)0x44;
*TIMER0_TCCR0A = 0x00;
volatile char *TIMER0_TCCR0B = (volatile char *)0x45;
*TIMER0_TCCR0B = 0x03; //Timer0, Normal Mode, Prescalar 64
volatile char *TIMER0_TIFR0 = (volatile char *)0x35;
//Serial.print(*TIMER0_TIFR0, DEC);
while((*TIMER0_TIFR0 & 0x06) == 0x00);
//Serial.print(*TIMER0_TIFR0, HEX);
*TIMER0_TCCR0B = 0;
*TIMER0_TIFR0 = 0;
}
}
void loop() {
// put your main code here, to run repeatedly:
}