-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreeRTOS
More file actions
112 lines (99 loc) · 2.56 KB
/
FreeRTOS
File metadata and controls
112 lines (99 loc) · 2.56 KB
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
#include <Arduino_FreeRTOS.h>
int digit_select_pin[] = {0,1,2,3}; // 11 10 9 8 PORTB
int segment_pin[] = {7,6,5,4,3,2,1,0}; // PORTD
unsigned char digits_data[10]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7C, 0x07, 0x7F, 0x67};
int time_delay = 15;
int d1000, d100, d10, d1;
unsigned char btn[4] = {0,0,0,0};
int count=1;
int speed = 10;
void TaskBlink( void *pvParameters );
//void TaskButton( void *pvParameters );
//void TaskAnalogRead( void *pvParameters );
void setup()
{
DDRB = 0xFF;
DDRD = 0xFF;
DDRC = 0x00;
/*Serial.begin(9600);
while (!Serial) {
;
}*/
xTaskCreate(TaskBlink,"Blink", 256, NULL, 2, NULL);
//xTaskCreate(TaskAnalogRead, "AnalogRead", 128, NULL, 1, NULL );
}
void loop() {
// put your main code here, to run repeatedly:
}
void show_digit(int pos, int number)
{
PORTB = 0xFF;
PORTB &= ~( 1 << digit_select_pin[pos] ); // pos=3 --> ~(1<<3) --> ~(0001 << 3) --> ~(1000) -->(0111)
PORTD = digits_data[number]; // number=1 --> 0x60
}
void TaskBlink(void *pvParameters) // This is a task.
{
for (;;)
{
for( int i = 0; i < 10000; i=i+count)
{
d1000 = i /1000;
d100 = i % 1000/100;
d10 = i % 100/10;
d1 = i % 10;
if((PINC & 0x0F) != 0)
{
btn[0] = PINC & 0x01;
btn[1] = PINC & 0x02;
btn[2] = PINC & 0x04;
btn[3] = PINC & 0x08;
if(btn[0] != 0)
{
speed += 10;
if(speed >= 400)
{
speed =400;
PORTB = 0xFF;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
if(btn[1] != 0)
{
speed -= 10;
if(speed <= 0)
{
speed = 10;
PORTB = 0xFF;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
if(btn[2] != 0)
count=1;
if(btn[3] != 0)
count=-1;
}
if(i < 0) i = 9999;
for(int j = 0 ; j < speed ; j++)
{
show_digit(0, d1000);
vTaskDelay(time_delay / portTICK_PERIOD_MS); //time_delay / portTICK_PERIOD_MS
show_digit(1, d100);
vTaskDelay(time_delay / portTICK_PERIOD_MS);
show_digit(2, d10);
vTaskDelay(time_delay / portTICK_PERIOD_MS);
show_digit(3, d1);
vTaskDelay(time_delay / portTICK_PERIOD_MS);
}
}
}
}
/*void TaskAnalogRead(void *pvParameters) // This is a task.
{
(void) pvParameters;
for (;;)
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
vTaskDelay(1);
}
}*/