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
|
#include "project.h"
static void
kbd_dispatch (void)
{
uint8_t c;
if (ring_read_byte (&rx1_ring, &c))
return;
printf ("KEY> %c\r\n", c);
}
int
main (void)
{
char buf[128];
int c;
/*set up pll */
rcc_clock_setup_in_hse_8mhz_out_72mhz ();
/*turn on clocks which aren't done elsewhere */
rcc_periph_clock_enable (RCC_GPIOA);
rcc_periph_clock_enable (RCC_GPIOB);
rcc_periph_clock_enable (RCC_GPIOC);
rcc_periph_clock_enable (RCC_AFIO);
/*Adjust interrupt priorities so that uarts trump timer */
nvic_set_priority (NVIC_USART1_IRQ, 0x40);
nvic_set_priority (NVIC_USART2_IRQ, 0x40);
nvic_set_priority (NVIC_USART3_IRQ, 0x40);
nvic_set_priority (NVIC_SYSTICK_IRQ, 0xff);
ticker_init ();
led_init ();
usart_init ();
i2cp_init ();
lcd_init ();
lcd_write ("Hello world", 0, 0);
for (;;)
{
if (!ring_empty (&rx1_ring))
kbd_dispatch ();
delay_ms (1000);
printf ("Counter is %x\n", c);
sprintf (buf, "%8x", c++);
lcd_write (buf, 0, 1);
led_set (c & 1 ? LED0 : LED1);
}
return 0;
}
|