-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsb_delay.c
More file actions
40 lines (29 loc) · 795 Bytes
/
sb_delay.c
File metadata and controls
40 lines (29 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
*
* Copyright (c) Mateusz Maciejewski ^ TOXIC_DEATH.117, 2021 - 2023
*
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include <stddef.h>
static volatile uint8_t m_Timer1 = 0x00;
ISR(TIM1_OVF_vect) {
if(m_Timer1 > 0x00) {
m_Timer1--;
}
TCNT1 = 0x00; // reset Timer/Counter1
}
void SB_DELAY_Init(void) {
TCCR1 = 0x00; // stop Timer/Counter1
TCNT1 = 0x00; // reset Timer/Counter1
GTCCR |= _BV(PSR1); // Reset prescalers of Timer/Counter1
OCR1A = 0x00;
OCR1C = 0xFF;
TIMSK |= ( 1 << TOIE1 ); // enable Timer/Counter1 Overflow Interrupt
TCCR1 |= _BV( CS13 ) | _BV( CS11 ) | _BV( CS10 ); // start
}
void SB_DELAY_Delay(uint8_t lDelay) {
m_Timer1 = lDelay;
while(m_Timer1 > 0x00);
}