nicer output on LCD: decimal numbers
Stefan Schuermans

Stefan Schuermans commited on 2012-03-24 23:13:53
Showing 1 changed files, with 23 additions and 11 deletions.

... ...
@@ -10,8 +10,19 @@
10 10
 
11 11
 unsigned char leds_val = 0x88;
12 12
 
13
+void uint2digits(unsigned int uint, unsigned int cnt, char digits[])
14
+{
15
+  while (cnt > 0) {
16
+    --cnt;
17
+    digits[cnt] = '0' + uint % 10;
18
+    uint /= 10;
19
+  }
20
+}
21
+
13 22
 void switches(void)
14 23
 {
24
+  char cnt_digits[4];
25
+
15 26
   lcd_chr(1, 0, switches_get_state(sw_0) ? '0' : ' ');
16 27
   lcd_chr(1, 1, switches_get_state(sw_1) ? '1' : ' ');
17 28
   lcd_chr(1, 2, switches_get_state(sw_2) ? '2' : ' ');
... ...
@@ -24,11 +35,11 @@ void switches(void)
24 35
   lcd_chr(1, 9, switches_get_state(sw_rot_a) ? 'a' : ' ');
25 36
   lcd_chr(1, 10, switches_get_state(sw_rot_b) ? 'b' : ' ');
26 37
 
27
-  unsigned int cnt = switches_get_rot_cnt();
28
-  lcd_chr(1, 12, '0' + (cnt >> 9 & 0x7));
29
-  lcd_chr(1, 13, '0' + (cnt >> 6 & 0x7));
30
-  lcd_chr(1, 14, '0' + (cnt >> 3 & 0x7));
31
-  lcd_chr(1, 15, '0' + (cnt & 0x7));
38
+  uint2digits(switches_get_rot_cnt(), 4, cnt_digits);
39
+  lcd_chr(1, 12, cnt_digits[0]);
40
+  lcd_chr(1, 13, cnt_digits[1]);
41
+  lcd_chr(1, 14, cnt_digits[2]);
42
+  lcd_chr(1, 15, cnt_digits[3]);
32 43
 }
33 44
 
34 45
 void uart(void)
... ...
@@ -46,16 +57,17 @@ void eth_task(void)
46 57
 {
47 58
   void *vptr;
48 59
   unsigned int sz, i;
60
+  char digits[2];
49 61
 
50 62
   while (eth_rx(&vptr, &sz))
51 63
     ethernet_recv(vptr, sz);
52 64
 
53
-  i = eth_rx_get_cnt();
54
-  lcd_chr(0, 11, '0' + (i >> 3 & 0x7));
55
-  lcd_chr(0, 12, '0' + (i & 0x7));
56
-  i = eth_tx_get_cnt();
57
-  lcd_chr(0, 14, '0' + (i >> 3 & 0x7));
58
-  lcd_chr(0, 15, '0' + (i & 0x7));
65
+  uint2digits(eth_rx_get_cnt(), 2, digits);;
66
+  lcd_chr(0, 11, digits[0]);
67
+  lcd_chr(0, 12, digits[1]);
68
+  uint2digits(eth_tx_get_cnt(), 2, digits);;
69
+  lcd_chr(0, 14, digits[0]);
70
+  lcd_chr(0, 15, digits[1]);
59 71
 }
60 72
 
61 73
 void tasks(void)
62 74