Line 46... |
Line 46... |
46 |
err++; |
46 |
err++; |
47 |
if(40==err) // do 40-ti kroku by se melo podarit otocit dolu |
47 |
if(40==err) // do 40-ti kroku by se melo podarit otocit dolu |
48 |
{ |
48 |
{ |
49 |
output_B(0); // vypnuti motoru |
49 |
output_B(0); // vypnuti motoru |
50 |
printf("E"); // Hlasime chybu |
50 |
printf("E"); // Hlasime chybu |
51 |
err=0; |
51 |
reset_cpu(); |
52 |
} |
52 |
} |
53 |
}; |
53 |
}; |
54 |
delay_ms(500); // cas na ustaleni trubky |
54 |
delay_ms(500); // cas na ustaleni trubky |
55 |
output_B(0); // vypnuti motoru |
55 |
output_B(0); // vypnuti motoru |
56 |
} |
56 |
} |
57 |
|
57 |
|
58 |
// --- Najeti na vychozi polohu dole --- |
58 |
// --- Najeti na vychozi polohu dole --- |
59 |
void nula() |
59 |
void nula() |
60 |
{ |
60 |
{ |
61 |
port=0b10100000; // vychozi nastaveni fazi pro rizeni motoru |
61 |
port=0b10010000; // vychozi nastaveni fazi pro rizeni motoru |
62 |
output_B(port); |
62 |
output_B(port); |
63 |
j=0; // smer dolu |
63 |
j=1; // smer dolu |
64 |
delay_ms(500); |
64 |
delay_ms(500); |
65 |
} |
65 |
} |
66 |
|
66 |
|
67 |
|
67 |
|
68 |
//------------------------------------------------ |
68 |
//------------------------------------------------ |
69 |
void main() |
69 |
void main() |
70 |
{ |
70 |
{ |
71 |
setup_oscillator(OSC_8MHZ|OSC_INTRC); // 8 MHz interni RC oscilator |
- |
|
72 |
|
- |
|
73 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
71 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
74 |
setup_adc(ADC_OFF); |
72 |
setup_adc(ADC_OFF); |
75 |
setup_spi(FALSE); |
73 |
setup_spi(SPI_SS_DISABLED); |
76 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
74 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
77 |
setup_timer_1(T1_DISABLED); |
75 |
setup_timer_1(T1_DISABLED); |
- |
|
76 |
setup_timer_2(T2_DISABLED,0,1); |
78 |
setup_ccp1(CCP_OFF); |
77 |
setup_ccp1(CCP_OFF); |
79 |
setup_comparator(NC_NC_NC_NC); |
78 |
setup_comparator(NC_NC_NC_NC); |
80 |
setup_vref(FALSE); |
79 |
setup_vref(FALSE); |
- |
|
80 |
setup_oscillator(OSC_8MHZ|OSC_INTRC); |
81 |
|
81 |
|
82 |
output_B(0); // vypnuti motoru a topeni |
82 |
output_B(0); // vypnuti motoru a topeni |
83 |
set_tris_B(0b00000111); // faze a topeni jako vystupy |
83 |
set_tris_B(0b00000111); // faze a topeni jako vystupy |
84 |
|
84 |
|
- |
|
85 |
nula(); |
- |
|
86 |
dolu(); // otoc trubku do vychozi pozice dolu |
85 |
|
87 |
|
86 |
while(true) |
88 |
while(true) |
87 |
{ |
89 |
{ |
88 |
nula(); |
- |
|
89 |
dolu(); // otoc trubku do vychozi pozice dolu |
- |
|
90 |
|
- |
|
91 |
CREN=0; CREN=1; // Reinitialise USART |
90 |
CREN=0; CREN=1; // Reinitialise USART |
92 |
|
91 |
|
93 |
while(!kbhit()) |
92 |
while(!kbhit()) |
94 |
{ |
93 |
{ |
95 |
if (!input(HALL)) // znovuotoceni trubky dolu, kdyby ji vitr otocil |
94 |
if (!input(HALL)) // znovuotoceni trubky dolu, kdyby ji vitr otocil |
Line 105... |
Line 104... |
105 |
nula(); |
104 |
nula(); |
106 |
j++; // reverz, nahoru |
105 |
j++; // reverz, nahoru |
107 |
|
106 |
|
108 |
krok(18); |
107 |
krok(18); |
109 |
printf("A"); // mereni teploty 45° nad obzorem |
108 |
printf("A"); // mereni teploty 45° nad obzorem |
110 |
delay_ms(200); |
109 |
delay_ms(300); |
111 |
krok(7); |
110 |
krok(7); |
112 |
printf("B"); // mereni teploty v zenitu |
111 |
printf("B"); // mereni teploty v zenitu |
113 |
delay_ms(200); |
112 |
delay_ms(300); |
114 |
krok(7); |
113 |
krok(7); |
115 |
printf("C"); // mereni teploty 45° nad obzorem na druhou stranu |
114 |
printf("C"); // mereni teploty 45° nad obzorem na druhou stranu |
116 |
delay_ms(200); |
115 |
delay_ms(300); |
117 |
|
116 |
|
118 |
j++; // reverz |
117 |
j++; // reverz |
119 |
dolu(); |
118 |
dolu(); |
120 |
printf("G"); // mereni teploty Zeme (<G>round) |
119 |
printf("G"); // mereni teploty Zeme (<G>round) |
121 |
|
120 |
|
122 |
continue; |
121 |
continue; |
123 |
} |
122 |
} |
124 |
|
123 |
|
125 |
if ('i'==uhel) {printf("I"); continue;} // Predani prikazu pro Info |
124 |
if ('i'==uhel) {printf("I"); continue;} // Predani prikazu pro Info |
126 |
if ('h'==uhel) {printf("H"); continue;} // Predani prikazu pro Topeni |
125 |
if ('h'==uhel) {printf("H"); continue;} // Predani prikazu pro Topeni |
127 |
if ('c'==uhel) {printf("C"); continue;} // Predani prikazu pro vypnuti topeni |
126 |
if ('f'==uhel) {printf("F"); continue;} // Predani prikazu pro vypnuti topeni |
128 |
if ('x'==uhel) // Zjisteni verze FW |
127 |
if ('x'==uhel) // Zjisteni verze FW |
129 |
{ |
128 |
{ |
130 |
printf("Mrakomer - Motor V%s (C) 2006 KAKL\n\r", VER); |
129 |
printf("Mrakomer - Motor V%s (C) 2006 KAKL\n\r", VER); |
131 |
printf("%s\n\r", REV); |
130 |
printf("%s\r\n", REV); |
132 |
} |
131 |
} |
133 |
|
132 |
|
134 |
if ((uhel>='0') && (uhel<='@')) // mereni v pozadovanem uhlu [0..;]=(0..11) |
133 |
if ((uhel>='0') && (uhel<='@')) // mereni v pozadovanem uhlu [0..;]=(0..11) |
135 |
{ |
134 |
{ |
136 |
uhel-='0'; |
135 |
uhel-='0'; |
Line 145... |
Line 144... |
145 |
for(i=0; i<uhel; i++) // dale odkrokuj podle pozadovaneho uhlu |
144 |
for(i=0; i<uhel; i++) // dale odkrokuj podle pozadovaneho uhlu |
146 |
{ |
145 |
{ |
147 |
krok(2); |
146 |
krok(2); |
148 |
}; |
147 |
}; |
149 |
printf("S"); |
148 |
printf("S"); |
150 |
delay_ms(200); |
149 |
delay_ms(300); |
151 |
|
150 |
|
152 |
j++; // reverz |
151 |
j++; // reverz |
153 |
dolu(); |
152 |
dolu(); |
154 |
printf("G"); // mereni teploty Zeme (<G>round) |
153 |
printf("G"); // mereni teploty Zeme (<G>round) |
155 |
} |
154 |
} |