2022-02-10 19:03:59 +08:00
|
|
|
#define USE_STDPERIPH_DRIVER
|
|
|
|
#include "myprintk.h"
|
2022-02-10 20:08:02 +08:00
|
|
|
#include "stm32_p103.h"
|
|
|
|
|
|
|
|
void sleep() {
|
|
|
|
int i = 1000000;
|
|
|
|
while (i-- > 0)
|
|
|
|
;
|
|
|
|
}
|
2022-02-10 19:03:59 +08:00
|
|
|
|
2022-02-10 20:08:02 +08:00
|
|
|
/* redirect printf to myprintf */
|
|
|
|
#define printf myprintf
|
|
|
|
|
|
|
|
static void prime_number_100_c() {
|
|
|
|
int num = 0;
|
|
|
|
num = 0;
|
|
|
|
/* run */
|
|
|
|
for (int i = 2; i < 100; i++) {
|
|
|
|
int is_prime = 1;
|
|
|
|
for (int j = 2; j < i; j++) {
|
|
|
|
if (i % j == 0) {
|
|
|
|
is_prime = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_prime) {
|
|
|
|
num = num + i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (1060 != num) {
|
|
|
|
printf("[error]: prime_number_100\r\n");
|
|
|
|
}
|
2022-02-10 19:03:59 +08:00
|
|
|
}
|
|
|
|
|
2022-02-10 20:08:02 +08:00
|
|
|
int main(void) {
|
2022-02-10 19:03:59 +08:00
|
|
|
uint8_t b;
|
2022-02-10 20:08:02 +08:00
|
|
|
int32_t num1 = 0x1234;
|
|
|
|
char* str1 = "Strings";
|
|
|
|
char ch1 = 'Z';
|
2022-02-10 19:03:59 +08:00
|
|
|
|
2022-02-10 20:08:02 +08:00
|
|
|
// first init myprintf device(usart2)
|
2022-02-10 19:03:59 +08:00
|
|
|
myprintf_init();
|
2022-02-10 20:08:02 +08:00
|
|
|
prime_number_100_c();
|
|
|
|
while (1) {
|
|
|
|
myprintf("test num %d=0x%x str %s ch %c\n", num1, num1, str1, ch1);
|
2022-02-10 19:03:59 +08:00
|
|
|
sleep();
|
|
|
|
}
|
|
|
|
}
|