-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiny_memmove.c
128 lines (114 loc) · 2.17 KB
/
tiny_memmove.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define LED PB1
#define SIZE 230
#define ITERATIONS 1000000
volatile uint32_t ticks = 0;
bool flag = false;
uint32_t loop_const;
uint16_t delay_const;
uint8_t source[SIZE];
uint8_t destination[SIZE];
void delay(uint16_t milliseconds)
{
for(delay_const = 0; delay_const < (milliseconds / 10); delay_const++)
{
_delay_ms(10);
}
}
void led_on()
{
PORTB = PORTB | (1 << LED);
}
void led_off()
{
PORTB = PORTB & ~(1 << LED);
}
void flash_num(uint32_t input)
{
led_on();
delay(2000);
led_off();
for(loop_const = 0; loop_const < 32; loop_const++)
{
if((input >> loop_const) % 2 == 0)
{
led_on();
delay(250);
led_off();
delay(1000);
}
else if((input >> loop_const) % 2 == 1)
{
led_on();
delay(750);
led_off();
delay(1000);
}
}
}
ISR(TIMER1_COMPA_vect)
{
ticks = ticks + 1;
if((ticks % (122L * 5L)) == 0)
{
led_on();
delay(10);
led_off();
}
}
int main(void)
{
cli();
GTCCR = GTCCR | (1 << TSM) | (1 << PSR0) | (1 << PSR1);
DDRB = DDRB | (1 << LED);
//TCCR0A = 0 | (1 << WGM01);
//TCCR0B = 0 | (1 << CS02);
//OCR0A = 255;
TIMSK = 0 | (1 << OCIE1A);
TCCR1 = 0 | (1 << CTC1) | (1 << CS13) | (1 << CS10);
OCR1C = 255;
OCR1A = 255;
//TCNT0 = 0;
TCNT1 = 0;
GTCCR = GTCCR & ~(1 << TSM);
sei();
led_off();
for(loop_const = 0; loop_const < SIZE; loop_const++)
{
source[loop_const] = loop_const;
}
ticks = 0;
for(loop_const = 0; loop_const < ITERATIONS / 2; loop_const++)
{
memcpy(destination, source, sizeof(uint8_t) * SIZE);
memcpy(source, destination, sizeof(uint8_t) * SIZE);
}
cli();
ticks = ticks / 122;
for(loop_const = 0; loop_const < SIZE; loop_const++)
{
if(source[loop_const] != loop_const)
{
flag = true;
}
}
if(flag == false)
{
while(1)
{
flash_num(ticks);
}
}
else
{
led_on();
while(1)
{
}
}
}