-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
113 lines (93 loc) · 2.13 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
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
/* Uladzislau Harbuz, Yakymyshyn Maksym
* sdcc 3.6.0 Linux throw USB to RS232 converter
*/
#include "defines.h"
#include <8051.h>
#include "strc51_time.h"
#include "sort.h"
#define MAX_ARRAY_SIZE 1024
void func_isr(void) __interrupt 3 {
counter_timer();
}
static void init()
{
SCON = 0x50;
TMOD &= 0x0F;
TMOD |= 0x20;
TH1 = TL1 = 253;
TCON = 0x40;
PCON = 0x80;
}
static char getchar()
{
while(!RI);
RI = 0;
return SBUF;
}
static void putchar(char c)
{
while(!TI);
SBUF = c;
TI=0;
}
static int size = 0;
__xdata static uint8_t array1[MAX_ARRAY_SIZE];
__xdata static uint8_t array2[MAX_ARRAY_SIZE];
static void read_array() {
uint8_t i = 0;
size = (uint8_t)getchar();
getchar(); // ignore space
if (size > MAX_ARRAY_SIZE) return;
while (i < size) {
array1[i] = (uint8_t)getchar();
array2[i] = array1[i];
getchar(); //ignore next space;
}
}
static void print_array(uint8_t* a, uint8_t size) {
uint8_t i = 0;
putchar(size);
putchar(' ');
while (i < size) {
putchar(a[i]);
putchar(' ');
msleep(5);
}
}
static void unsafe_put_str_ln(char* str) {
while (*str != '\n') {
putchar(*str++);
msleep(5);
}
}
main (void) {
while (1) {
uint8_t i = 0;
uint8_t x = 0;
struct time tm = {0};
struct time tmtmp = {0};
struct time print_time = {0};
init();
init_time();
read_array();
gettime(&tm);
gettime(&tmtmp);
bubble_sort(array1, size);
diff_time(&tmtmp, &tm, &print_time);
unsafe_put_str_ln("bubble sort: ");
print_array(array1, size);
unsafe_put_str_ln("time:");
putchar(print_time.msecs);
unsafe_put_str_ln(" ms.");
sleep(5);
gettime(&tm);
gettime(&tmtmp);
insert_sort(array2, size);
diff_time(&tmtmp, &tm, &print_time);
unsafe_put_str_ln("insertion sort: ");
print_array(array1, size);
unsafe_put_str_ln("time:");
putchar(print_time.msecs);
unsafe_put_str_ln(" ms.");
}
}