root / trunk / code / projects / colonet / utilities / robot_slave / bom.c @ 13
History | View | Annotate | Download (1.75 KB)
1 |
#include <stdio.h> |
---|---|
2 |
#include <dragonfly_lib.h> |
3 |
#include "bom.h" |
4 |
#include "dio.h" |
5 |
#include "analog.h" |
6 |
|
7 |
const int lookup[16] = {7,6,5,0xe,1,4,3,2,0xf,0,0xd,8,0xc,0xb,9,0xa}; |
8 |
|
9 |
int getMaxBom(void) { |
10 |
int max_bom_temp = 0; |
11 |
int a, i, j, h;
|
12 |
h = 255;
|
13 |
|
14 |
for (j = 0; j < 16; j++) |
15 |
{ |
16 |
i = lookup[j]; |
17 |
|
18 |
if (i&8) |
19 |
output_high(MONK3); |
20 |
else
|
21 |
output_low(MONK3); |
22 |
|
23 |
if (i&4) |
24 |
output_high(MONK2); |
25 |
else
|
26 |
output_low(MONK2); |
27 |
|
28 |
if (i&2) |
29 |
output_high(MONK1); |
30 |
else
|
31 |
output_low(MONK1); |
32 |
|
33 |
if (i&1) |
34 |
output_high(MONK0); |
35 |
else
|
36 |
output_low(MONK0); |
37 |
|
38 |
a = analog8(MONKI); |
39 |
|
40 |
if (a < h)
|
41 |
{ |
42 |
h = a; |
43 |
max_bom_temp = j; |
44 |
} |
45 |
|
46 |
} |
47 |
printf("max_bom_temp = %d\n", max_bom_temp);
|
48 |
return max_bom_temp;
|
49 |
} |
50 |
|
51 |
char bytetosymb(unsigned int c) |
52 |
{ |
53 |
c = 255 - c;
|
54 |
|
55 |
if (c < 32) |
56 |
return ' '; |
57 |
if (c < 64) |
58 |
return '_'; |
59 |
if (c < 96) |
60 |
return ','; |
61 |
if (c < 128) |
62 |
return '.'; |
63 |
if (c < 160) |
64 |
return '-'; |
65 |
if (c < 192) |
66 |
return '~'; |
67 |
if (c < 224) |
68 |
return '\''; |
69 |
return '`'; |
70 |
} |
71 |
|
72 |
void bom_on(void) |
73 |
{ |
74 |
output_high(MONKL); |
75 |
|
76 |
} |
77 |
|
78 |
void bom_off(void) |
79 |
{ |
80 |
output_low(MONKL); |
81 |
} |
82 |
|
83 |
void output_high(int which) { |
84 |
digital_output(which, 1);
|
85 |
} |
86 |
|
87 |
void output_low(int which) { |
88 |
digital_output(which, 0);
|
89 |
} |
90 |
|
91 |
int printAllBoms(void){ |
92 |
int i,j;
|
93 |
for(i=0;i<16;i++){ |
94 |
j=lookup[i]; |
95 |
digital_output(MONK0,j&1);
|
96 |
digital_output(MONK1, (j>>1)&1); |
97 |
digital_output(MONK2, (j>>2)&1); |
98 |
digital_output(MONK3, (j>>3)&1); |
99 |
usb_puts("Bom ");
|
100 |
usb_puti(i); |
101 |
usb_puts(": ");
|
102 |
usb_puti(analog8(MONKI)); |
103 |
usb_puts("\n\r");
|
104 |
} |
105 |
return 1; |
106 |
} |
107 |
|