-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
62 lines (50 loc) · 1.53 KB
/
main.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifdef __AVR_ATmega328P__
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdbool.h>
#define F_CPU 16000000UL
#define NORMAL_MODE_VALUE(timer_bit, n_seconds, prescaler) ((int)(((1UL) << (timer_bit)) - ((n_seconds) * ((F_CPU) / (prescaler)))))
#define CTC_MODE_VALUE(n_seconds, prescaler) ((int)(((n_seconds) * ((F_CPU) / (prescaler))) - (1UL)))
#define UBRR_VALUE(UART_BAUDRATE) ((unsigned char)(((F_CPU)/((UART_BAUDRATE) * (16UL)))-((double)(1UL))))
#include <avr/io.h>
void Timer_1_Delay(); // Prototype for Delay Function
int main(void)
{
DDRB = 1<<0; // PB0 as Output
PORTB = 1<<0; // Initial LOW
while (1) // INF Loop
{
//Timer_1_Delay(); // Call 1 s Delay
// PORTB ^= (1<<0); // Toggle
PORTB = 0xFF;
}
}
void Timer_1_Delay()
{
// Timer 1 16 bit timer with prescaler = 1024
// 1 * 16M / 1024 = 15625
OCR1AH = 0x3D; // CTC OCR
OCR1AL = 0x08; // 15625 - 1 = 0x3D08
TCCR1A = 0x00; // CTC Mode
TCCR1B = 0x0D; // CTC Mode, Prescaler = 1024
while ((TIFR1 &(1<<OCF1A))==0); // Continue Until Overflow
TCCR1B = 0x00; // Stop Timer 1
TIFR1 = (1<<OCF1A); // Reset OCR1A
}
#else
#include "gtest/gtest.h"
using ::testing::InitGoogleTest;
// Demonstrate some basic assertions.
TEST(MyTest, BasicAssertions) {
// // Expect two strings not to be equal.
// EXPECT_STRNE("hello", "world");
// // Expect equality.
// EXPECT_EQ(7 * 6, 42);
EXPECT_EQ(UBRR_VALUE(9600), 103);
EXPECT_EQ(UBRR_VALUE(4800), 207);
}
int main(int argc, char** argv) {
InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#endif