547 |
miho |
1 |
//********************************************************************** |
|
|
2 |
// program pro rizeni TRXu |
|
|
3 |
//********************************************************************** |
|
|
4 |
// (c) OK1XGL 2005 |
|
|
5 |
// verze 1.0.0 - uvodni verze |
|
|
6 |
// verze 1.0.1 - prechod 16F877 a usazeni sibnalu na porty |
|
|
7 |
// verze 1.0.2 = odladeni zakladnich funkci - muzeme delat tistak |
|
|
8 |
// verze 1.0.3 - definitivni usazeni signalu - hotovy DPS |
|
|
9 |
// verze 1.0.4 - prvni pouzitelna verze |
|
|
10 |
// verze 1.1.0 - SIGNAL ATN1 PRESUNUT NA RE0 A SIGNAL ATN2 PRESUNUT NA RC0 !!!!! |
|
|
11 |
// verze 1.2.0 - doprobramovan jednopakovy klic |
|
|
12 |
// verze 1.3.0 - elbug zmenen na dvoupakovy a cely presunut do preruseni |
|
|
13 |
// verze 1.4.0 - po zapnuti se RX naladi na QRP kmitocet na danem pasmu |
|
|
14 |
// - PSV se povazuje za platne jen kdyz je skutecne zaklicovano |
|
|
15 |
// verze 1.5.0 - upraven zpusob cteni dat z AD prevodniku |
|
|
16 |
// - pwm rozsirena na 157 kroku |
|
|
17 |
// - doplneno ALC pro vykon a nastaveni vykonu v 0.5W jednotkach |
|
|
18 |
// verze 1.6.0 - provedena kalibrace S-metru |
|
|
19 |
|
|
|
20 |
|
|
|
21 |
// Poznamky: |
|
|
22 |
// zobrazeni kmitoctu na LCD trva 30ms !!! |
|
|
23 |
// pri rychlosti klicovani 200zn/s je sirka impulzu (tecka) cca 30ms |
|
|
24 |
// timer2 vyhrazen na generovani tonu a ma nastaven kmitocet 800Hz, ton se generuje PWM, rizeni vykonu tez PWM 800Hz je baze |
|
|
25 |
// timer 1 vyhrazen pro elbug |
|
|
26 |
|
|
|
27 |
|
|
|
28 |
//DODELAT: - pri BK provozu je treba, aby se pri prepnuti na prjem mezi elementy znacky nezobrazoval S-metr, protoze |
|
|
29 |
// se to tak rychle nestiha zobrazovat a je lepsi,aby se zobrazovalo stale psv a vykon. Nyni je toho dosazeno tak, |
|
|
30 |
// ze pokud je aktivni elbug, tak se zobrazeni nedela ovsem toto reseni nebude fungovat pri externim elbugu |
|
|
31 |
// spravne reseni je timerem, ktery bude vykryvat cas mezi znackami |
|
|
32 |
// - projit kod a nektere veci ucesat |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
#include "vfo.h" |
|
|
37 |
#include <lcd.c> |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
//#define ADC_LCD // misto obvyklych udaju zobrazuje hodnoty AD prevodniku |
|
|
41 |
//#define NO_FILTER_CONTROL // vyrazuje prubeznou kontrolu pritomnosti filtru pro prislusne pasmo |
|
|
42 |
|
|
|
43 |
|
|
|
44 |
/////////// FUNKCE PRO ZOBRAZOVANI NA LCD ///////// |
|
|
45 |
|
|
|
46 |
// podpora zobrazeni RIT |
|
|
47 |
// POZOR: pred pouzitim je nutno vynulovat promennou lcd_pos !!! |
|
|
48 |
void rit_lcd_putc(int8 c) |
|
|
49 |
{ |
|
|
50 |
lcd_pos++; |
|
|
51 |
if(lcd_pos==2) lcd_putc('.'); // prida tecku za KHZ |
|
|
52 |
lcd_putc(c); |
|
|
53 |
} // rit_lcd_putc |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
// podpora zobrazeni kmitoctu VFO |
|
|
58 |
// POZOR: pred pouzitim je nutno vynulovat promennou lcd_pos !!! |
|
|
59 |
void vfo_lcd_putc(int8 c) |
|
|
60 |
{ |
|
|
61 |
lcd_pos++; |
|
|
62 |
// za MHz dopln pismenko VFO |
|
|
63 |
if(lcd_pos==3) |
|
|
64 |
if(vfo_index) |
|
|
65 |
if(bit_test(_SPLIT)) lcd_putc('\21'); // vyplnene b |
|
|
66 |
else lcd_putc('b'); |
|
|
67 |
else if(bit_test(_SPLIT)) lcd_putc('\22'); // vyplnene a |
|
|
68 |
else lcd_putc('a'); |
|
|
69 |
// za KHz dopln tecku |
|
|
70 |
if(lcd_pos==6) |
|
|
71 |
if(step_index) lcd_putc(':'); // hrube ladeni |
|
|
72 |
else lcd_putc('.'); // jemne ladeni |
|
|
73 |
lcd_putc(c); |
|
|
74 |
} //vfo_lcd_putc |
|
|
75 |
|
|
|
76 |
|
|
|
77 |
// podpora zobrazeni vykonu a psv |
|
|
78 |
// POZOR: pred pouzitim je nutno vynulovat promennou lcd_pos !!! |
|
|
79 |
void pwr_lcd_putc(int8 c) |
|
|
80 |
{ |
|
|
81 |
lcd_pos++; |
|
|
82 |
if(lcd_pos==2) lcd_putc('.'); |
|
|
83 |
lcd_putc(c); |
|
|
84 |
} // pwr_lcd_putc |
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
// podpora zobrazeni napeti baterie |
|
|
89 |
// POZOR: pred pouzitim je nutno vynulovat promennou lcd_pos !!! |
|
|
90 |
void batt_lcd_putc(int8 c) |
|
|
91 |
{ |
|
|
92 |
lcd_pos++; |
|
|
93 |
if(lcd_pos==3) lcd_putc('.'); |
|
|
94 |
lcd_putc(c); |
|
|
95 |
} // batt_lcd_putc |
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
/////////// FUNKCE PRO PRACI S DDS ///////// |
|
|
101 |
|
|
|
102 |
// odesle 16 bitovy zaznam do DDS |
|
|
103 |
// |
|
|
104 |
void dds_send(int16 record) |
|
|
105 |
{ |
|
|
106 |
int8 i; |
|
|
107 |
#use fast_io(A) |
|
|
108 |
#use fast_io(B) |
|
|
109 |
#use fast_io(C) |
|
|
110 |
#use fast_io(D) |
|
|
111 |
|
|
|
112 |
output_low(DDS_FSYNC); // zacatek komunikace s DDS |
|
|
113 |
i=16; |
|
|
114 |
do |
|
|
115 |
{ |
|
|
116 |
if(bit_test(record,15)) output_high(DDS_SDATA); // vystav datovy bit, zaciname MSB |
|
|
117 |
else output_low(DDS_SDATA); |
|
|
118 |
output_low(DDS_SCK); // hodinovy impulz |
|
|
119 |
output_high(DDS_SCK); |
|
|
120 |
record=record<<1; // na dalsi bit |
|
|
121 |
} while(--i); |
|
|
122 |
|
|
|
123 |
output_high(DDS_FSYNC); // konec komunikace s DDS |
|
|
124 |
#use standard_io(A) |
|
|
125 |
#use standard_io(B) |
|
|
126 |
#use standard_io(C) |
|
|
127 |
#use standard_io(D) |
|
|
128 |
} // dds_send |
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
// naplni registr0 pro kmitocet v DDS (28 bitu) |
|
|
134 |
// |
|
|
135 |
void dds_freq0(int32 freq) |
|
|
136 |
{ |
|
|
137 |
int16 record; |
|
|
138 |
|
|
|
139 |
// posli ridici slovo |
|
|
140 |
dds_send(CTRL_FREQ0); |
|
|
141 |
|
|
|
142 |
// zapis pozadovane frekvence |
|
|
143 |
// zapis LSB |
|
|
144 |
record=(int16)freq; |
|
|
145 |
bit_set(record,14); // zapis do frekvencniho registru 0 |
|
|
146 |
bit_clear(record,15); |
|
|
147 |
dds_send(record); |
|
|
148 |
// zapis MSB |
|
|
149 |
record=(int16)((freq<<2)>>16); // divny zapis, ale >> 14 dava hrozny vysledek |
|
|
150 |
bit_set(record,14); // zapis do frekvencniho registru 0 |
|
|
151 |
bit_clear(record,15); |
|
|
152 |
dds_send(record); |
|
|
153 |
} // dds_freq0 |
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
/////////// FUNKCE PRO RIZENI PRIPOSLECHU ///////// |
|
|
158 |
|
|
|
159 |
// vypne generovani tonu priposlechu |
|
|
160 |
// |
|
|
161 |
#inline |
|
|
162 |
void tone_off() |
|
|
163 |
{ |
|
|
164 |
int8 a; |
|
|
165 |
a=input(TONE); |
|
|
166 |
} // tone_off() |
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
// zapne generovani tonu priposlechu |
|
|
171 |
// |
|
|
172 |
#inline |
|
|
173 |
void tone_on() |
|
|
174 |
{ |
|
|
175 |
output_low(TONE); |
|
|
176 |
} // tone_on |
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
///////////////////////////////// |
|
|
182 |
// Prerusovaci rutiny |
|
|
183 |
///////////////////////////////// |
|
|
184 |
// rezie preruseni je cca 30+30 cyklu |
|
|
185 |
|
|
|
186 |
// preruseni od zmeny polohy kroutitka |
|
|
187 |
#int_EXT |
|
|
188 |
void Encoder_handler() |
|
|
189 |
{ |
|
|
190 |
#use fast_io(a) |
|
|
191 |
#use fast_io(b) |
|
|
192 |
#use fast_io(c) |
|
|
193 |
#use fast_io(d) |
|
|
194 |
|
|
|
195 |
|
|
|
196 |
int1 dir; |
|
|
197 |
|
|
|
198 |
dir=input(ENCODER_DIR); // zapamatuj si smer krouceni |
|
|
199 |
bit_set(_ENC_CHNG); // oznam zmenu polohy kroutitka |
|
|
200 |
if(dir) enc_delta++; // pridej |
|
|
201 |
else enc_delta--; // uber |
|
|
202 |
|
|
|
203 |
#use standard_io(a) |
|
|
204 |
#use standard_io(b) |
|
|
205 |
#use standard_io(c) |
|
|
206 |
#use standard_io(d) |
|
|
207 |
} // Encoder_handler |
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
// periodicke tiky, granularita TICK_TIME |
|
|
212 |
// citace/ casovace se granularitou TICK_TIME |
|
|
213 |
#INT_TIMER0 |
|
|
214 |
void Tick_handler() |
|
|
215 |
{ |
|
|
216 |
#use fast_io(a) |
|
|
217 |
#use fast_io(b) |
|
|
218 |
#use fast_io(c) |
|
|
219 |
#use fast_io(d) |
|
|
220 |
|
|
|
221 |
set_timer0(TICK_TIME); // znovu natahni timer |
|
|
222 |
|
|
|
223 |
// mereni napeti z prevodniku |
|
|
224 |
if(bit_test(_ADC_START)) |
|
|
225 |
{ |
|
|
226 |
read_adc(ADC_START_ONLY); // spust prevod |
|
|
227 |
bit_clear(_ADC_START); // priste budeme cist vysledek |
|
|
228 |
} else |
|
|
229 |
{ |
|
|
230 |
adc_val=read_adc(ADC_READ_ONLY); // vyzvedni vysledek |
|
|
231 |
|
|
|
232 |
if(bit_test(_KEYING)) // hodnoty vykonu aktualizuj jen pokud je zaklicovano |
|
|
233 |
{ |
|
|
234 |
if(adc_ch==1) fwd_val=adc_val; |
|
|
235 |
if(adc_ch==0) rev_val=adc_val; |
|
|
236 |
} |
|
|
237 |
if(adc_ch==2) batt_val=adc_val; |
|
|
238 |
else if(adc_ch==3) smtr_val=adc_val; |
|
|
239 |
else if(adc_ch==4) bnd_val=adc_val; |
|
|
240 |
if(adc_ch>=4) adc_ch=0; // mame 5 kanalu |
|
|
241 |
else adc_ch++; |
|
|
242 |
set_adc_channel(adc_ch); // priste nasledujici kanal |
|
|
243 |
bit_set(_ADC_START); // priste budeme spoustet prevod |
|
|
244 |
} |
|
|
245 |
|
|
|
246 |
// klicovani |
|
|
247 |
if(bit_test(_TXDELAY)) // jen pokud tx_delay vyprsel |
|
|
248 |
{ |
|
|
249 |
if(!bit_test(_ELBUG_ON)) |
|
|
250 |
keyer=(~input_b()) & 0b10000000; // pokud neni zapnut elbug, zavzorkuj stav klice |
|
|
251 |
|
|
|
252 |
if((keyer!=0 && !bit_test(_ELBUG_ON)) || // pri vypnutem elbugu rizeno stavem pak |
|
|
253 |
(bit_test(_ELBUG_OUT) && bit_test(_ELBUG_ON))) // pri zapnutem elbugu rizeno stavem _ELBUG_ON |
|
|
254 |
{ |
|
|
255 |
// zaklicuj |
|
|
256 |
output_high(KEYING); |
|
|
257 |
tone_on(); |
|
|
258 |
bit_clear(_RUN_VOX); |
|
|
259 |
bit_set(_KEYING); |
|
|
260 |
adc_ch=0; // zacneme merit dopredny vykon |
|
|
261 |
set_adc_channel(adc_ch); |
|
|
262 |
bit_set(_ADC_START); // priste spustime prevod ADC |
|
|
263 |
} else |
|
|
264 |
{ |
|
|
265 |
// prestan klicovat |
|
|
266 |
output_low(KEYING); |
|
|
267 |
vox_timer=vox_time; // natahni vox_timer |
|
|
268 |
bit_set(_RUN_VOX); |
|
|
269 |
tone_off(); |
|
|
270 |
bit_clear(_KEYING); |
|
|
271 |
} |
|
|
272 |
bit_clear(_TXDELAY); |
|
|
273 |
} |
|
|
274 |
|
|
|
275 |
|
|
|
276 |
// periodicky timer na aktualizaci kde ceho |
|
|
277 |
if(update_timer==0xFF) update_timer=UPDATE_TIME; |
|
|
278 |
else update_timer--; |
|
|
279 |
|
|
|
280 |
// vox timer |
|
|
281 |
if(bit_test(_RUN_VOX)) |
|
|
282 |
if(vox_timer!=0) vox_timer--; |
|
|
283 |
else |
|
|
284 |
{ |
|
|
285 |
// vox vyprsel |
|
|
286 |
bit_clear(_RUN_VOX); |
|
|
287 |
output_low(RXTX); // prepni zpet na prijem |
|
|
288 |
bit_clear(_TRANSMIT); |
|
|
289 |
bit_set(_DDS_UPDATE); |
|
|
290 |
} |
|
|
291 |
|
|
|
292 |
// timer pro zjisteni dlouheho stisku tlacitek |
|
|
293 |
if(key_timer!=0) key_timer--; |
|
|
294 |
|
|
|
295 |
|
|
|
296 |
// periodicke cteni tlacitek |
|
|
297 |
#use fast_io(C) |
|
|
298 |
keys_work=(~input_c()) & KEY_MASK; // precti stav tlacitek |
|
|
299 |
#use standard_io(C) |
|
|
300 |
if(keys_work!=keys_old) keys_old=keys_work; // neshoda zapamatuj si novy stav |
|
|
301 |
else |
|
|
302 |
{ |
|
|
303 |
// shoda |
|
|
304 |
if(keys_work!=0) |
|
|
305 |
{ |
|
|
306 |
// tlacitko je STISKNUTO |
|
|
307 |
if(keys==0) |
|
|
308 |
{ |
|
|
309 |
// akceptujeme jen pokud bylo zpracovano vse predchozi |
|
|
310 |
keys=keys_work; // zapamatuj si nove tlacitko |
|
|
311 |
key_timer=KEY_LONG; // natahni casovac pro zjisteni dlouheho stisku |
|
|
312 |
} else |
|
|
313 |
{ |
|
|
314 |
// neco je jeste ke zpracovani |
|
|
315 |
if(key_timer==0 && !bit_test(_KEYS_RELEASE)) |
|
|
316 |
{ |
|
|
317 |
// jde o dlouhy stisk tlacitka |
|
|
318 |
bit_set(_KEYS_LONG); |
|
|
319 |
bit_set(_KEYS_VALID); |
|
|
320 |
} |
|
|
321 |
} |
|
|
322 |
} else |
|
|
323 |
{ |
|
|
324 |
// tlacitko je UVOLNENO |
|
|
325 |
if(key_timer!=0) |
|
|
326 |
{ |
|
|
327 |
// jde o kratky stisk tlacitka |
|
|
328 |
bit_set(_KEYS_VALID); |
|
|
329 |
key_timer=0; |
|
|
330 |
} else if(bit_test(_KEYS_RELEASE)) |
|
|
331 |
{ |
|
|
332 |
keys_flags=0; // jde o klidovy stav - tlacitka zpracovana |
|
|
333 |
keys=0; |
|
|
334 |
} |
|
|
335 |
} |
|
|
336 |
} |
|
|
337 |
|
|
|
338 |
#use standard_io(a) |
|
|
339 |
#use standard_io(b) |
|
|
340 |
#use standard_io(c) |
|
|
341 |
#use standard_io(d) |
|
|
342 |
} // Tick_handler |
|
|
343 |
|
|
|
344 |
|
|
|
345 |
|
|
|
346 |
|
|
|
347 |
// periodicke tiky kazdych 5ms |
|
|
348 |
// vyuzito pro rizeli LCD_LED |
|
|
349 |
// |
|
|
350 |
#INT_TIMER2 |
|
|
351 |
void led_handler() |
|
|
352 |
{ |
|
|
353 |
#use fast_io(a) |
|
|
354 |
#use fast_io(b) |
|
|
355 |
#use fast_io(c) |
|
|
356 |
#use fast_io(d) |
|
|
357 |
|
|
|
358 |
|
|
|
359 |
flash_timer++; |
|
|
360 |
|
|
|
361 |
// rizeni LED |
|
|
362 |
// pri prijmu bez attenuatoru sviti zelena |
|
|
363 |
// pri prijmu s attenuatorem sviti zluta |
|
|
364 |
// pri vysilani sviti cervena |
|
|
365 |
// pri vybite baterii pri prijmu led blika |
|
|
366 |
|
|
|
367 |
|
|
|
368 |
if(bit_test(_TRANSMIT)) |
|
|
369 |
{ |
|
|
370 |
// vysilani - rozsvid cervenou LED |
|
|
371 |
if(bit_test(_LED_UPDATE)) output_high(LCD_LED1); |
|
|
372 |
else output_low(LCD_LED1); |
|
|
373 |
output_low(LCD_LED2); |
|
|
374 |
} else |
|
|
375 |
{ |
|
|
376 |
if(bit_test(_BATT_LOW) && bit_test(flash_timer,7)) |
|
|
377 |
{ |
|
|
378 |
// zhasni led |
|
|
379 |
output_low(LCD_LED1); |
|
|
380 |
output_low(LCD_LED2); |
|
|
381 |
} else |
|
|
382 |
{ |
|
|
383 |
// prijem - rozsvid zelenou nebo zlutou led |
|
|
384 |
if(bit_test(_LED_UPDATE)) |
|
|
385 |
{ |
|
|
386 |
output_high(LCD_LED2); |
|
|
387 |
output_low(LCD_LED1); |
|
|
388 |
} else |
|
|
389 |
{ |
|
|
390 |
output_low(LCD_LED2); |
|
|
391 |
if(bit_test(_ATTN)) output_high(LCD_LED1); |
|
|
392 |
else output_low(LCD_LED1); |
|
|
393 |
} |
|
|
394 |
} |
|
|
395 |
} |
|
|
396 |
|
|
|
397 |
if(bit_test(_LED_UPDATE)) bit_clear(_LED_UPDATE); |
|
|
398 |
else bit_set(_LED_UPDATE); |
|
|
399 |
|
|
|
400 |
#use standard_io(a) |
|
|
401 |
#use standard_io(b) |
|
|
402 |
#use standard_io(c) |
|
|
403 |
#use standard_io(d) |
|
|
404 |
} // led_handler |
|
|
405 |
|
|
|
406 |
|
|
|
407 |
|
|
|
408 |
|
|
|
409 |
// cteni pak, klice |
|
|
410 |
#INT_RB |
|
|
411 |
void paddle_handler() |
|
|
412 |
{ |
|
|
413 |
#use fast_io(a) |
|
|
414 |
#use fast_io(b) |
|
|
415 |
#use fast_io(c) |
|
|
416 |
#use fast_io(d) |
|
|
417 |
|
|
|
418 |
keyerb=(~input_b()); // precti stav pak |
|
|
419 |
if(bit_test(_ELBUG_ON)) keyerb=keyerb & 0b11000000; // platne jsou obe paky |
|
|
420 |
else keyerb=keyerb & 0b10000000; // platna je paka tecek |
|
|
421 |
|
|
|
422 |
if(!bit_test(_TXDELAY)) // reagujeme jen kdyz nebezi TXDELAY |
|
|
423 |
{ |
|
|
424 |
if(!bit_test(_ELBUG_ON)) |
|
|
425 |
{ |
|
|
426 |
// RUCNI KLICOVANI |
|
|
427 |
set_timer0(TICK_TIME); // txdelay je dano jednim zakladnim tikem, natahni tik |
|
|
428 |
_T0IF=0; |
|
|
429 |
bit_set(_TXDELAY); // spustime TXDELAY |
|
|
430 |
} else |
|
|
431 |
{ |
|
|
432 |
// ELBUG |
|
|
433 |
// nastav priznaky pak |
|
|
434 |
if(bit_test(_ELBUG_REV)) |
|
|
435 |
{ |
|
|
436 |
if(bit_test(keyerb,6)) bit_set(_ELBUG_DOT); |
|
|
437 |
if(bit_test(keyerb,7)) bit_set(_ELBUG_DASH); |
|
|
438 |
} else |
|
|
439 |
{ |
|
|
440 |
if(bit_test(keyerb,7)) bit_set(_ELBUG_DOT); |
|
|
441 |
if(bit_test(keyerb,6)) bit_set(_ELBUG_DASH); |
|
|
442 |
} |
|
|
443 |
if(!bit_test(_ELBUG_BSY)) |
|
|
444 |
{ |
|
|
445 |
// spusteni elbugu |
|
|
446 |
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); // spust casovac |
|
|
447 |
_TMR1IF=1; |
|
|
448 |
} |
|
|
449 |
} |
|
|
450 |
if(!bit_test(_TRANSMIT) && keyerb!=0) // pri stisku pak prejdeme na vysilani pokud tomu jiz tak neni |
|
|
451 |
{ |
|
|
452 |
bit_set(_TRANSMIT); // priznak stavu vysilani |
|
|
453 |
output_high(RXTX); // prepni TRX na vysilani |
|
|
454 |
bit_set(_DDS_UPDATE); // nastav vysilaci kmitocet |
|
|
455 |
} |
|
|
456 |
} |
|
|
457 |
|
|
|
458 |
#use standard_io(a) |
|
|
459 |
#use standard_io(b) |
|
|
460 |
#use standard_io(c) |
|
|
461 |
#use standard_io(d) |
|
|
462 |
} // paddle_handler |
|
|
463 |
|
|
|
464 |
|
|
|
465 |
|
|
|
466 |
// elbug |
|
|
467 |
// |
|
|
468 |
#int_timer1 |
|
|
469 |
void elbug_handler() |
|
|
470 |
{ |
|
|
471 |
#use fast_io(a) |
|
|
472 |
#use fast_io(b) |
|
|
473 |
#use fast_io(c) |
|
|
474 |
#use fast_io(d) |
|
|
475 |
|
|
|
476 |
|
|
|
477 |
if(bit_test(_ELBUG_SP)) |
|
|
478 |
{ |
|
|
479 |
// odvysilali jsem tecku nebo carku - musime dovysilat mezeru |
|
|
480 |
bit_clear(_ELBUG_SP); // priste budeme vysilat podle stavu pak |
|
|
481 |
bit_clear(_ELBUG_OUT); |
|
|
482 |
set_timer1(elbug_dot_sp); // natahni casovac na mezeru |
|
|
483 |
set_timer0(TICK_TIME); // txdelay je dano jednim zakladnim tikem, natahni tik |
|
|
484 |
_T0IF=0; |
|
|
485 |
bit_set(_TXDELAY); // spustime TXDELAY |
|
|
486 |
return; |
|
|
487 |
} |
|
|
488 |
|
|
|
489 |
if(bit_test(_ELBUG_BSY)) |
|
|
490 |
{ |
|
|
491 |
// odvysilali jsme posloupnost tecka-mezera nebo carka-mezera |
|
|
492 |
// nuluj priznak prave dovysilaneho elementu |
|
|
493 |
if(bit_test(_ELBUG_LAST)) bit_clear(_ELBUG_DASH); |
|
|
494 |
else bit_clear(_ELBUG_DOT); |
|
|
495 |
// dale se rozhodujeme podle stavu pak |
|
|
496 |
keyer=(~input_b()) & 0b11000000; // precti stav pak |
|
|
497 |
|
|
|
498 |
// nastav priznak pak podle stisknute paky |
|
|
499 |
if(bit_test(_ELBUG_REV)) |
|
|
500 |
{ |
|
|
501 |
if(bit_test(keyer,6)) bit_set(_ELBUG_DOT); |
|
|
502 |
if(bit_test(keyer,7)) bit_set(_ELBUG_DASH); |
|
|
503 |
} else |
|
|
504 |
{ |
|
|
505 |
if(bit_test(keyer,7)) bit_set(_ELBUG_DOT); |
|
|
506 |
if(bit_test(keyer,6)) bit_set(_ELBUG_DASH); |
|
|
507 |
} |
|
|
508 |
|
|
|
509 |
if(bit_test(_ELBUG_REAL) && keyer==0) // nestisknuto nic |
|
|
510 |
{ |
|
|
511 |
// pri realnem klicovani po uvolneni pak se uz dal nic nevysila |
|
|
512 |
bit_clear(_ELBUG_DOT); |
|
|
513 |
bit_clear(_ELBUG_DASH); |
|
|
514 |
} |
|
|
515 |
} |
|
|
516 |
|
|
|
517 |
// prepnuti na vysilani pokud tomu uz tak neni |
|
|
518 |
if(!bit_test(_TRANSMIT) && |
|
|
519 |
(bit_test(_ELBUG_DOT) || bit_test(_ELBUG_DASH))) |
|
|
520 |
{ |
|
|
521 |
bit_set(_TRANSMIT); // priznak stavu vysilani |
|
|
522 |
output_high(RXTX); // prepni TRX na vysilani |
|
|
523 |
bit_set(_DDS_UPDATE); // nastav vysilaci kmitocet |
|
|
524 |
} |
|
|
525 |
|
|
|
526 |
// nastav hodnotu casovace podle stisknute paky |
|
|
527 |
if(bit_test(_ELBUG_DOT)) |
|
|
528 |
{ |
|
|
529 |
if(bit_test(_ELBUG_DASH)) |
|
|
530 |
{ |
|
|
531 |
// stisknuty obe paky - vysilej opak priznaku LAST |
|
|
532 |
if(bit_test(_ELBUG_LAST)) |
|
|
533 |
{ |
|
|
534 |
bit_clear(_ELBUG_LAST); |
|
|
535 |
set_timer1(elbug_dot_sp); // natahni casovac na tecku |
|
|
536 |
} else |
|
|
537 |
{ |
|
|
538 |
bit_set(_ELBUG_LAST); |
|
|
539 |
set_timer1(elbug_dash); // natahni casovac na carku |
|
|
540 |
} |
|
|
541 |
} else |
|
|
542 |
{ |
|
|
543 |
bit_clear(_ELBUG_LAST); |
|
|
544 |
set_timer1(elbug_dot_sp); // natahni casovac na tecku |
|
|
545 |
} |
|
|
546 |
} else if(bit_test(_ELBUG_DASH)) |
|
|
547 |
{ |
|
|
548 |
bit_set(_ELBUG_LAST); |
|
|
549 |
set_timer1(elbug_dash); // natahni casovac na carku |
|
|
550 |
} else |
|
|
551 |
{ |
|
|
552 |
// NENI CO VYSILAT -KONCIME |
|
|
553 |
bit_clear(_ELBUG_BSY); |
|
|
554 |
setup_timer_1(T1_DISABLED); // zastav casovac |
|
|
555 |
return; |
|
|
556 |
} |
|
|
557 |
|
|
|
558 |
bit_set(_ELBUG_BSY); // elbug bezi |
|
|
559 |
bit_set(_ELBUG_SP); // priste musime vysilat mezeru |
|
|
560 |
bit_set(_ELBUG_OUT); |
|
|
561 |
set_timer0(TICK_TIME); // txdelay je dano jednim zakladnim tikem, natahni tik |
|
|
562 |
_T0IF=0; |
|
|
563 |
bit_set(_TXDELAY); // spustime TXDELAY |
|
|
564 |
|
|
|
565 |
#use standard_io(a) |
|
|
566 |
#use standard_io(b) |
|
|
567 |
#use standard_io(c) |
|
|
568 |
#use standard_io(d) |
|
|
569 |
} // elbug_handler |
|
|
570 |
|
|
|
571 |
|
|
|
572 |
|
|
|
573 |
/////////// FUNKCE PRO OVLADANI UTLUMU ///////// |
|
|
574 |
|
|
|
575 |
// natavi utlum |
|
|
576 |
// |
|
|
577 |
void Attn_0dB() |
|
|
578 |
{ |
|
|
579 |
output_low(ATN1); |
|
|
580 |
output_low(ATN2); |
|
|
581 |
output_high(ATNC); |
|
|
582 |
delay_ms(RELE_PULSE); |
|
|
583 |
input(ATNC); // prepni ANTC zpet do tretiho stavu (vstup) |
|
|
584 |
delay_ms(RELE_PULSE); |
|
|
585 |
input(ATN1); |
|
|
586 |
input(ATN2); |
|
|
587 |
} |
|
|
588 |
|
|
|
589 |
|
|
|
590 |
// natavi utlum |
|
|
591 |
// |
|
|
592 |
void Attn_6dB() |
|
|
593 |
{ |
|
|
594 |
output_high(ATN1); |
|
|
595 |
output_low(ATNC); |
|
|
596 |
delay_ms(RELE_PULSE); |
|
|
597 |
input(ATNC); // prepni ANTC zpet do tretiho stavu (vstup) |
|
|
598 |
output_low(ATN2); |
|
|
599 |
output_high(ATNC); |
|
|
600 |
delay_ms(RELE_PULSE); |
|
|
601 |
input(ATNC); // prepni ANTC zpet do tretiho stavu (vstup) |
|
|
602 |
delay_ms(RELE_PULSE); |
|
|
603 |
input(ATN1); |
|
|
604 |
input(ATN2); |
|
|
605 |
} |
|
|
606 |
|
|
|
607 |
|
|
|
608 |
// natavi utlum |
|
|
609 |
// |
|
|
610 |
void Attn_12dB() |
|
|
611 |
{ |
|
|
612 |
output_low(ATN1); |
|
|
613 |
output_high(ATNC); |
|
|
614 |
delay_ms(RELE_PULSE); |
|
|
615 |
input(ATNC); // prepni ANTC zpet do tretiho stavu (vstup) |
|
|
616 |
output_high(ATN2); |
|
|
617 |
output_low(ATNC); |
|
|
618 |
delay_ms(RELE_PULSE); |
|
|
619 |
input(ATNC); // prepni ANTC zpet do tretiho stavu (vstup) |
|
|
620 |
delay_ms(RELE_PULSE); |
|
|
621 |
input(ATN1); |
|
|
622 |
input(ATN2); |
|
|
623 |
} |
|
|
624 |
|
|
|
625 |
|
|
|
626 |
// natavi utlum |
|
|
627 |
// |
|
|
628 |
void Attn_18dB() |
|
|
629 |
{ |
|
|
630 |
output_high(ATN1); |
|
|
631 |
output_high(ATN2); |
|
|
632 |
output_low(ATNC); |
|
|
633 |
delay_ms(RELE_PULSE); |
|
|
634 |
input(ATNC); // prepni ANTC zpet do tretiho stavu (vstup) |
|
|
635 |
delay_ms(RELE_PULSE); |
|
|
636 |
input(ATN1); |
|
|
637 |
input(ATN2); |
|
|
638 |
} |
|
|
639 |
|
|
|
640 |
|
|
|
641 |
|
|
|
642 |
/* |
|
|
643 |
// precte z prevodnihu hornich 8 bitu |
|
|
644 |
// |
|
|
645 |
int8 adc() |
|
|
646 |
{ |
|
|
647 |
return(read_adc()>>8) ; |
|
|
648 |
} // adc |
|
|
649 |
*/ |
|
|
650 |
|
|
|
651 |
|
|
|
652 |
/////////// FUNKCE PRO PRACI S EEPROM ///////// |
|
|
653 |
|
|
|
654 |
// aktualizuje kontrolni soucet |
|
|
655 |
// |
|
|
656 |
void update_eeprom() |
|
|
657 |
{ |
|
|
658 |
int8 i; |
|
|
659 |
int8 crc; |
|
|
660 |
crc=0; |
|
|
661 |
for(i=0;i<EE_ADR_CRC;i++) crc+=read_eeprom(i); |
|
|
662 |
crc=0-crc; |
|
|
663 |
write_eeprom(EE_ADR_CRC,crc); |
|
|
664 |
} // update_eeprom |
|
|
665 |
|
|
|
666 |
|
|
|
667 |
|
|
|
668 |
// zkontroluje obsah pameti eeprom a pokud je poskozen, nAstavi defaultni parametry |
|
|
669 |
// |
|
|
670 |
void check_eeprom() |
|
|
671 |
{ |
|
|
672 |
int8 i; |
|
|
673 |
int8 crc; |
|
|
674 |
|
|
|
675 |
crc=0; |
|
|
676 |
for(i=0;i<=EE_ADR_CRC;i++) crc=crc+read_eeprom(i); |
|
|
677 |
|
|
|
678 |
if(crc!=0) |
|
|
679 |
{ |
|
|
680 |
i=EE_ADR_POWER; |
|
|
681 |
while(i<BAND_NUM) write_eeprom(i++,PAR_LIMIT[PAR_POWER][0]); // minimalni vykon na vsech pasmech |
|
|
682 |
write_eeprom(EE_ADR_KEYER,20); // nastaveno 20 WPM |
|
|
683 |
write_eeprom(EE_ADR_VOX,6); // vox 300ms |
|
|
684 |
write_eeprom(EE_ADR_BATT,0); // konstantni hodntota,dale se nemeni |
|
|
685 |
write_eeprom(EE_ADR_KEYER_REV,0); // nereverzuj paky |
|
|
686 |
write_eeprom(EE_ADR_KEYER_MODE,0); // doplnkove klicovani |
|
|
687 |
write_eeprom(EE_ADR_ATTN,PAR_LIMIT[PAR_VOX][0]); // utlum vypnut |
|
|
688 |
update_eeprom(); // aktualizuj kontorlni soucet |
|
|
689 |
} |
|
|
690 |
|
|
|
691 |
} // check_eeprom |
|
|
692 |
|
|
|
693 |
|
|
|
694 |
|
|
|
695 |
|
|
|
696 |
|
|
|
697 |
///////////////////////////////////// |
|
|
698 |
// VYKONNE FUNKCE HLAVNI SMYCKY |
|
|
699 |
///////////////////////////////////// |
|
|
700 |
|
|
|
701 |
|
|
|
702 |
// zpracovani zmeny polohy kroutitka |
|
|
703 |
// trva max 600cyklu (600us) |
|
|
704 |
// |
|
|
705 |
// CHELO BY TO UCESAT POMOCI KONSTRUKCE IF - RETURN |
|
|
706 |
#inline |
|
|
707 |
void enc_chng() |
|
|
708 |
{ |
|
|
709 |
int32 freq_dds; |
|
|
710 |
signed int32 delta_freq; |
|
|
711 |
signed int16 delta_rit; |
|
|
712 |
|
|
|
713 |
if(bit_test(_MNU) || bit_test(_MNU2)) |
|
|
714 |
{ |
|
|
715 |
// NASTAVUJEME PARAMETRY |
|
|
716 |
if(enc_delta<ENC_HISTEREZE && enc_delta>-ENC_HISTEREZE) return; // zmeny pod minimum si nevsimej |
|
|
717 |
|
|
|
718 |
if(enc_delta>0) |
|
|
719 |
{ |
|
|
720 |
// nastala zmena +1 |
|
|
721 |
if(bit_test(_MNU2)) |
|
|
722 |
{ |
|
|
723 |
if(par_index<PAR_NUM-3) |
|
|
724 |
{ |
|
|
725 |
par_index++; // zmena typu parametru pokud projde kontrola horni meze |
|
|
726 |
bit_set(_LCD2_UPDATE); |
|
|
727 |
} |
|
|
728 |
} else if(par[par_index]<PAR_LIMIT[par_index][1]) // zmena hodnoty parametru pokud projde kontrola horni meze |
|
|
729 |
{ |
|
|
730 |
par[par_index]++; |
|
|
731 |
bit_set(_PAR_UPDATE); // pozadavek aktualizace parametru |
|
|
732 |
} |
|
|
733 |
} else |
|
|
734 |
{ |
|
|
735 |
// nastala zmena -1 |
|
|
736 |
if(bit_test(_MNU2)) |
|
|
737 |
{ |
|
|
738 |
if(par_index>0) |
|
|
739 |
{ |
|
|
740 |
par_index--; // zmena typu parametru pokud projde kontrola dolni meze |
|
|
741 |
bit_set(_LCD2_UPDATE); |
|
|
742 |
} |
|
|
743 |
} else if(par[par_index]>PAR_LIMIT[par_index][0]) // zmena hodnoty parametru pokud projde kontrola dolni meze |
|
|
744 |
{ |
|
|
745 |
par[par_index]--; |
|
|
746 |
bit_set(_PAR_UPDATE); // pozadavek aktualizace parametru |
|
|
747 |
} |
|
|
748 |
} |
|
|
749 |
enc_delta=0; // zmena provedena |
|
|
750 |
} else |
|
|
751 |
{ |
|
|
752 |
// LADIME KMITOCET |
|
|
753 |
if(bit_test(_RIT)) |
|
|
754 |
{ |
|
|
755 |
// ladime RIT |
|
|
756 |
delta_rit=enc_delta*RIT_STEP; |
|
|
757 |
enc_delta=0; |
|
|
758 |
if(freq_rit+delta_rit <=RIT_LIMIT[1] && |
|
|
759 |
freq_rit+delta_rit >=RIT_LIMIT[0]) freq_rit+=delta_rit; |
|
|
760 |
} else |
|
|
761 |
{ |
|
|
762 |
// ladime VFO |
|
|
763 |
delta_freq=enc_delta*FREQ_STEP[step_index]; |
|
|
764 |
enc_delta=0; |
|
|
765 |
freq_dds=freq_vfo[vfo_index]+delta_freq; |
|
|
766 |
if(freq_dds <=BAND_LIMIT[band_index][1] && |
|
|
767 |
freq_dds >=BAND_LIMIT[band_index][0]) freq_vfo[vfo_index]+=delta_freq; |
|
|
768 |
} |
|
|
769 |
bit_set(_DDS_UPDATE); // pozadujeme zmenu kmitoctu v DDS |
|
|
770 |
} |
|
|
771 |
bit_clear(_ENC_CHNG); // zmena polohy kroutitka zpracovana |
|
|
772 |
} // enc_chng |
|
|
773 |
|
|
|
774 |
|
|
|
775 |
|
|
|
776 |
|
|
|
777 |
|
|
|
778 |
// aktualizuje parametry |
|
|
779 |
// |
|
|
780 |
#inline |
|
|
781 |
void par_update() |
|
|
782 |
{ |
|
|
783 |
|
|
|
784 |
// int16 power; |
|
|
785 |
|
|
|
786 |
bit_clear(_PAR_UPDATE); |
|
|
787 |
|
|
|
788 |
switch(par_index) |
|
|
789 |
{ |
|
|
790 |
case PAR_ATTN: |
|
|
791 |
bit_set(_ATTN); // pri utlumu bude misto zelene led svitit zluta |
|
|
792 |
switch(par[PAR_ATTN]) |
|
|
793 |
{ |
|
|
794 |
case 1: Attn_6dB(); |
|
|
795 |
break; |
|
|
796 |
case 2: Attn_12dB(); |
|
|
797 |
break; |
|
|
798 |
case 3: Attn_18dB(); |
|
|
799 |
break; |
|
|
800 |
default:Attn_0dB(); |
|
|
801 |
bit_clear(_ATTN); // zadny utlum, zpet zelena led |
|
|
802 |
break; |
|
|
803 |
} |
|
|
804 |
break; |
|
|
805 |
case PAR_POWER: |
|
|
806 |
// set_pwm2_duty(par[PAR_POWER]); |
|
|
807 |
// power=par[PAR_POWER]; |
|
|
808 |
// set_pwm2_duty(power<<1); |
|
|
809 |
//!!!!! |
|
|
810 |
power=par[PAR_POWER]*5; // vykon je v nasobcich 0.5W |
|
|
811 |
break; |
|
|
812 |
case PAR_KEYER: |
|
|
813 |
if(par[PAR_KEYER]<=PAR_LIMIT[PAR_KEYER][0]) bit_clear(_ELBUG_ON); ///elbug_flags=0; // vypni elbug |
|
|
814 |
else |
|
|
815 |
{ |
|
|
816 |
// zapni elbug a nastav rychlost |
|
|
817 |
bit_set(_ELBUG_ON); |
|
|
818 |
elbug_dot_sp=~(ELBUG_CONST/par[PAR_KEYER]); // preved na hodnotu citace TMR1 |
|
|
819 |
elbug_dot_sp++; |
|
|
820 |
elbug_dash=(elbug_dot_sp<<1)+elbug_dot_sp; // *3, ale rychleji |
|
|
821 |
} |
|
|
822 |
|
|
|
823 |
break; |
|
|
824 |
case PAR_VOX: |
|
|
825 |
vox_time=par[PAR_VOX]; |
|
|
826 |
if(vox_time!=0) vox_time=vox_time*10; // cas je ve 50ms jednotkach |
|
|
827 |
else vox_time=1; // minimalni vox je 5ms |
|
|
828 |
break; |
|
|
829 |
case PAR_KEYER_REV: |
|
|
830 |
if(par[PAR_KEYER_REV]) bit_set(_ELBUG_REV); // |
|
|
831 |
else bit_clear(_ELBUG_REV); |
|
|
832 |
break; |
|
|
833 |
case PAR_KEYER_MODE: |
|
|
834 |
// if(par[PAR_KEYER_MODE]) bit_set(_ELBUG_REAL); // |
|
|
835 |
// else bit_clear(_ELBUG_REAL); |
|
|
836 |
break; |
|
|
837 |
} |
|
|
838 |
bit_set(_LCD2_UPDATE); // pozadujeme update 2. radku dispeje |
|
|
839 |
} // par_update() |
|
|
840 |
|
|
|
841 |
|
|
|
842 |
|
|
|
843 |
|
|
|
844 |
// aktualizuje kmitocet v dds |
|
|
845 |
// trva max. cca 2500cyklu (2.5ms) |
|
|
846 |
// |
|
|
847 |
#inline |
|
|
848 |
void dds_update() |
|
|
849 |
{ |
|
|
850 |
int32 freq_dds; |
|
|
851 |
signed int32 delta_freq; |
|
|
852 |
signed int32 freq_rit2; |
|
|
853 |
|
|
|
854 |
|
|
|
855 |
if(!bit_test(_TRANSMIT)) |
|
|
856 |
{ |
|
|
857 |
// PRIJEM |
|
|
858 |
if(band_index>=SUB_IF_INDEX) freq_dds=freq_vfo[vfo_index]-FREQ_IF; // pri prijmu na 14MHz se odecita kmitocet mezifrekvence |
|
|
859 |
else freq_dds=freq_vfo[vfo_index]+FREQ_IF; // pri prijmu pod 14MHz se pricita kmitocet mezifrekvence |
|
|
860 |
|
|
|
861 |
if(bit_test(_RIT)) |
|
|
862 |
{ |
|
|
863 |
freq_rit2=freq_rit; // prevod na signed int32, chyba v C, neumi int32 + signed int16 |
|
|
864 |
freq_dds=freq_dds+freq_rit2; // je-li zapnut RIT, udelej korekci kmitoctu |
|
|
865 |
} |
|
|
866 |
bit_set(_LCD1_UPDATE); // pozadujeme zmenit kmitocet na lcd |
|
|
867 |
} else |
|
|
868 |
{ |
|
|
869 |
// VYSILANI |
|
|
870 |
if(bit_test(_SPLIT)) // pri split se pouzije opacne vfo |
|
|
871 |
freq_dds=freq_vfo[(~vfo_index)]; |
|
|
872 |
else freq_dds=freq_vfo[vfo_index]; |
|
|
873 |
} |
|
|
874 |
|
|
|
875 |
dds_freq0((int32)((float)freq_dds*CONVERT_CONST)); // odesli jej do DDS trva to cca 2050 cylklu (2.05ms) |
|
|
876 |
bit_clear(_DDS_UPDATE); // kmitocet v dds zmenen |
|
|
877 |
// bit_set(_LCD1_UPDATE); // pozadujeme zmenit kmitocet na lcd |
|
|
878 |
} // dds_update |
|
|
879 |
|
|
|
880 |
|
|
|
881 |
|
|
|
882 |
|
|
|
883 |
// aktualizuje zobrazeni na lcd - 1.radek |
|
|
884 |
// trva max. 3000cyklu (30ms) !!!!!! |
|
|
885 |
// |
|
|
886 |
//#inline |
|
|
887 |
#separate |
|
|
888 |
int8 lcd1_update() |
|
|
889 |
{ |
|
|
890 |
int16 rit_val; |
|
|
891 |
|
|
|
892 |
lcd_gotoxy(1,1); |
|
|
893 |
bit_clear(_LCD1_UPDATE); |
|
|
894 |
|
|
|
895 |
if(bit_test(_MNU2)) printf(lcd_putc,"PARAM: "); // zobraz ze vybirame typ parametru |
|
|
896 |
else if(bit_test(_MNU)) |
|
|
897 |
{ |
|
|
898 |
// zobraz nazev parametru |
|
|
899 |
switch(par_index) |
|
|
900 |
{ |
|
|
901 |
case PAR_ATTN: printf(lcd_putc,"ATTN: "); |
|
|
902 |
break; |
|
|
903 |
case PAR_POWER: printf(lcd_putc,"POWER: "); |
|
|
904 |
break; |
|
|
905 |
case PAR_KEYER: printf(lcd_putc,"KEYER: "); |
|
|
906 |
break; |
|
|
907 |
case PAR_VOX: printf(lcd_putc,"DELAY: "); |
|
|
908 |
break; |
|
|
909 |
case INF_BATT: printf(lcd_putc,"BATTERY:"); |
|
|
910 |
break; |
|
|
911 |
case PAR_KEYER_MODE: printf(lcd_putc,"MODE: "); |
|
|
912 |
break; |
|
|
913 |
case PAR_KEYER_REV: printf(lcd_putc,"REVERSE:"); |
|
|
914 |
break; |
|
|
915 |
|
|
|
916 |
} |
|
|
917 |
} else if(bit_test(_RIT)) |
|
|
918 |
{ |
|
|
919 |
// POZN: fce printf spatne zachazi se znaminkovimi cisly, proto je znamenko |
|
|
920 |
// zobrazeno samostatne a rit je preveden na neznamenkove cislo |
|
|
921 |
printf(lcd_putc,"RIT:"); |
|
|
922 |
if(freq_rit<0) lcd_putc('+'); |
|
|
923 |
else lcd_putc('-'); |
|
|
924 |
rit_val=abs(freq_rit); |
|
|
925 |
lcd_pos=0; |
|
|
926 |
printf(rit_lcd_putc,"%04LU",rit_val); // zobraz RIT na LCD |
|
|
927 |
} else |
|
|
928 |
{ |
|
|
929 |
lcd_pos=0; |
|
|
930 |
printf(vfo_lcd_putc,"%8LD",freq_vfo[vfo_index]); // zobraz kmitocet na LCD |
|
|
931 |
} |
|
|
932 |
} // lcd1_update |
|
|
933 |
|
|
|
934 |
|
|
|
935 |
|
|
|
936 |
// pomocna funkce pro zobrazeni vykonu a psv na lcd |
|
|
937 |
// |
|
|
938 |
#separate |
|
|
939 |
void lcd_pwr_psv() |
|
|
940 |
{ |
|
|
941 |
#ifdef ADC_LCD |
|
|
942 |
printf(lcd_putc,"F%2X R%2X",pwr_val,psv_val); |
|
|
943 |
#else |
|
|
944 |
|
|
|
945 |
// vysilani - zobrazujeme vykon a psv |
|
|
946 |
if(pwr_val>99) printf(lcd_putc,">10"); |
|
|
947 |
else |
|
|
948 |
{ |
|
|
949 |
lcd_pos=0; |
|
|
950 |
printf(pwr_lcd_putc,"%02U",pwr_val); |
|
|
951 |
} |
|
|
952 |
printf(lcd_putc,"W "); |
|
|
953 |
if(psv_val>99) printf(lcd_putc,">10"); |
|
|
954 |
else |
|
|
955 |
{ |
|
|
956 |
lcd_pos=0; |
|
|
957 |
printf(pwr_lcd_putc,"%02U",psv_val); |
|
|
958 |
} |
|
|
959 |
#endif |
|
|
960 |
} // lcd_pwr_psv |
|
|
961 |
|
|
|
962 |
|
|
|
963 |
|
|
|
964 |
// aktualizuje zobrazeni na lcd - 2.radek |
|
|
965 |
// trva max 2000 cyklu (2ms) |
|
|
966 |
// |
|
|
967 |
//#inline |
|
|
968 |
#separate |
|
|
969 |
void lcd2_update() |
|
|
970 |
{ |
|
|
971 |
int8 i; |
|
|
972 |
int16 vox; |
|
|
973 |
int16 batt; |
|
|
974 |
|
|
|
975 |
bit_clear(_LCD2_UPDATE); |
|
|
976 |
lcd_gotoxy(1,2); |
|
|
977 |
|
|
|
978 |
if(bit_test(_MNU2)) |
|
|
979 |
{ |
|
|
980 |
// zobraz vybrany parametr |
|
|
981 |
switch(par_index) |
|
|
982 |
{ |
|
|
983 |
case PAR_POWER: printf(lcd_putc,"POWER "); |
|
|
984 |
break; |
|
|
985 |
case PAR_VOX: printf(lcd_putc,"DELAY "); |
|
|
986 |
break; |
|
|
987 |
case INF_BATT: printf(lcd_putc,"BATTERY "); |
|
|
988 |
break; |
|
|
989 |
case PAR_KEYER_MODE: printf(lcd_putc,"MODE "); |
|
|
990 |
break; |
|
|
991 |
case PAR_KEYER_REV: printf(lcd_putc,"REVERSE "); |
|
|
992 |
break; |
|
|
993 |
|
|
|
994 |
} |
|
|
995 |
} else if(bit_test(_MNU)) |
|
|
996 |
{ |
|
|
997 |
// zobraz hodnotu parametru |
|
|
998 |
switch(par_index) |
|
|
999 |
{ |
|
|
1000 |
case PAR_ATTN: printf(lcd_putc,"-%2U dB ",par[PAR_ATTN]*6); // krok je po 6dB |
|
|
1001 |
break; |
|
|
1002 |
case PAR_POWER: if(!bit_test(_TRANSMIT)) |
|
|
1003 |
{ |
|
|
1004 |
lcd_pos=0; |
|
|
1005 |
printf(pwr_lcd_putc,"%02UW PTT",power); // prijem - zobraz pozadovany vykon a vyzvu k vysilani |
|
|
1006 |
} else lcd_pwr_psv(); // vysilani - zobraz vykon a psv |
|
|
1007 |
break; |
|
|
1008 |
case PAR_KEYER: if( par[PAR_KEYER]<=PAR_LIMIT[PAR_KEYER][0]) printf(lcd_putc,"OFF "); |
|
|
1009 |
else printf(lcd_putc,"%2U ",par[PAR_KEYER]); |
|
|
1010 |
break; |
|
|
1011 |
case PAR_VOX: |
|
|
1012 |
vox=par[PAR_VOX]; |
|
|
1013 |
vox=vox*50; // ve 50ms jednotkach |
|
|
1014 |
printf(lcd_putc,"%4LU ms ",vox); |
|
|
1015 |
break; |
|
|
1016 |
case INF_BATT: |
|
|
1017 |
#ifdef ADC_LCD |
|
|
1018 |
printf(lcd_putc,"%3X V ",batt_val); |
|
|
1019 |
#else |
|
|
1020 |
// zobraz napeti baterie na desetiny voltu |
|
|
1021 |
batt=batt_val; |
|
|
1022 |
batt=(batt*10)/16; |
|
|
1023 |
lcd_pos=0; |
|
|
1024 |
printf(batt_lcd_putc,"%03UV ",(int8)batt); |
|
|
1025 |
|
|
|
1026 |
#endif |
|
|
1027 |
break; |
|
|
1028 |
case PAR_KEYER_MODE: |
|
|
1029 |
if(par[PAR_KEYER_MODE]) printf(lcd_putc,"B "); |
|
|
1030 |
else printf(lcd_putc,"A "); |
|
|
1031 |
break; |
|
|
1032 |
case PAR_KEYER_REV: |
|
|
1033 |
if(par[PAR_KEYER_REV]) printf(lcd_putc,"YES "); |
|
|
1034 |
else printf(lcd_putc,"NO "); |
|
|
1035 |
break; |
|
|
1036 |
|
|
|
1037 |
} |
|
|
1038 |
} else if(bit_test(_TRANSMIT)) lcd_pwr_psv(); // vysilani - zobraz vykon a psv |
|
|
1039 |
else if(!bit_test(_ELBUG_BSY)) // v mezerach mezi znackami elbugu S-metr nezobrazuj |
|
|
1040 |
{ |
|
|
1041 |
// prijem - zobrazujeme S-metr |
|
|
1042 |
#ifdef ADC_LCD |
|
|
1043 |
printf(lcd_putc,"SMTR:%2X ",smtr_val); |
|
|
1044 |
#else |
|
|
1045 |
if(smtr_val<=S_METER[0]) lcd_putc('2'); |
|
|
1046 |
else lcd_putc(' '); |
|
|
1047 |
if(smtr_val<=S_METER[1]) lcd_putc('3'); |
|
|
1048 |
else lcd_putc(' '); |
|
|
1049 |
if(smtr_val<=S_METER[2]) lcd_putc('4'); |
|
|
1050 |
else lcd_putc(' '); |
|
|
1051 |
if(smtr_val<=S_METER[3]) lcd_putc('5'); |
|
|
1052 |
else lcd_putc(' '); |
|
|
1053 |
if(smtr_val<=S_METER[4]) lcd_putc('6'); |
|
|
1054 |
else lcd_putc(' '); |
|
|
1055 |
if(smtr_val<=S_METER[5]) lcd_putc('7'); |
|
|
1056 |
else lcd_putc(' '); |
|
|
1057 |
if(smtr_val<=S_METER[6]) lcd_putc('8'); |
|
|
1058 |
else lcd_putc(' '); |
|
|
1059 |
if(smtr_val<=S_METER[8]) lcd_putc('\23'); |
|
|
1060 |
else if(smtr_val<=S_METER[7]) lcd_putc('9'); |
|
|
1061 |
else lcd_putc(' '); |
|
|
1062 |
#endif |
|
|
1063 |
} |
|
|
1064 |
} // lcd2_update() |
|
|
1065 |
|
|
|
1066 |
|
|
|
1067 |
|
|
|
1068 |
|
|
|
1069 |
// nastavi pasmo podle pripojeneho filtru |
|
|
1070 |
// |
|
|
1071 |
//#inline |
|
|
1072 |
void set_band() |
|
|
1073 |
{ |
|
|
1074 |
// int8 adc_band; |
|
|
1075 |
|
|
|
1076 |
set_adc_channel (BND_CH); // prepni ADC na vstup signalu BAND |
|
|
1077 |
delay_ms(20); |
|
|
1078 |
|
|
|
1079 |
// opakuj dokud neni pripojen vhodny filtr |
|
|
1080 |
for(;;) |
|
|
1081 |
{ |
|
|
1082 |
bnd_val=read_adc() & BAND_ADC_MASK; |
|
|
1083 |
// prohlidni tabulku moznych filtru |
|
|
1084 |
band_index=BAND_NUM; |
|
|
1085 |
while(band_index--) |
|
|
1086 |
{ |
|
|
1087 |
if(bnd_val==BAND_ADC[band_index]) return; // platny filtr pritomen |
|
|
1088 |
} |
|
|
1089 |
printf(lcd_putc,"\rCONNECT\n"); |
|
|
1090 |
printf(lcd_putc," FILTER"); |
|
|
1091 |
delay_ms(500); |
|
|
1092 |
} |
|
|
1093 |
} // set_band |
|
|
1094 |
|
|
|
1095 |
|
|
|
1096 |
|
|
|
1097 |
|
|
|
1098 |
// mereni analogovych vstupu |
|
|
1099 |
// |
|
|
1100 |
// doba trvani max 3000 cyklu (3ms) |
|
|
1101 |
#separate |
|
|
1102 |
void analog_inputs() |
|
|
1103 |
{ |
|
|
1104 |
static int8 count; |
|
|
1105 |
int16 k; |
|
|
1106 |
int32 pom32,pom32_2; // pro vypocet dopredneho vykonu |
|
|
1107 |
int16 pom16,pom16_2; // pro vypocet PSV |
|
|
1108 |
signed int8 delta; |
|
|
1109 |
|
|
|
1110 |
|
|
|
1111 |
#ifndef NO_FILTER_CONTROL // vyrazuje prubeznou kontrolu pritomnosti filtru pro prislusne pasmo |
|
|
1112 |
if((bnd_val & BAND_ADC_MASK)!=BAND_ADC[band_index]) reset_cpu(); // fittr byl odpojen |
|
|
1113 |
#endif |
|
|
1114 |
|
|
|
1115 |
// mereni napeti baterie |
|
|
1116 |
if(batt_val+5<=BATT_MIN) bit_set(_BATT_LOW); // baterie je vybita |
|
|
1117 |
|
|
|
1118 |
// vypocti aktualni vykon a psv a reguluj vykon |
|
|
1119 |
if(bit_test(_TRANSMIT)) |
|
|
1120 |
{ |
|
|
1121 |
#ifdef ADC_LCD // vypina zpracovani - zobrazuje prime hodnoty z prevodniku |
|
|
1122 |
pwr_val=fwd_val; |
|
|
1123 |
psv_val=rev_val; |
|
|
1124 |
#else |
|
|
1125 |
// vypocti vykon na desetiny watu |
|
|
1126 |
pom32=fwd_val; |
|
|
1127 |
pom32=pom32*pom32; // vykon je umerny kvadratu napeti |
|
|
1128 |
// vynasobime *10 - vykon bude 100mW jednotkach |
|
|
1129 |
// realizuje *10, je vyrazne casove kratsi ( o cca 500cyklu) |
|
|
1130 |
pom32_2=pom32<<3; |
|
|
1131 |
pom32_2=pom32_2+pom32; |
|
|
1132 |
pom32_2=pom32_2+pom32; |
|
|
1133 |
pwr_val=pom32_2/PWR_FWD_CONST; // vydelime kalibracni konstantou pro dopredny vykon |
|
|
1134 |
|
|
|
1135 |
// vypocti PSV na desetinu |
|
|
1136 |
if(fwd_val>=0 && rev_val==0) psv_val=10; // psv je 1.0 pokud je odrazeny vykon nulovy |
|
|
1137 |
else |
|
|
1138 |
{ |
|
|
1139 |
pom16=fwd_val; |
|
|
1140 |
pom16=pom16<<4; // vynasobime *16 pro vetsi presnost |
|
|
1141 |
k=pom16/rev_val; // pomer odpovidajici ciniteli odrazu |
|
|
1142 |
if(k<=16) psv_val=250; // PSV se blizi nekonecnu |
|
|
1143 |
else if(k>337) psv_val=10; // psv je lepsi jak 1.1 tedy ho povazujeme za 1.0 |
|
|
1144 |
else |
|
|
1145 |
{ |
|
|
1146 |
// toto realizuje vyraz (k+16)*10 |
|
|
1147 |
pom16=k+16; |
|
|
1148 |
pom16_2=pom16<<3; |
|
|
1149 |
pom16_2=pom16_2+pom16; |
|
|
1150 |
pom16_2=pom16_2+pom16; |
|
|
1151 |
// vypocet psv |
|
|
1152 |
psv_val=pom16_2/(k-16); |
|
|
1153 |
} |
|
|
1154 |
} |
|
|
1155 |
|
|
|
1156 |
// rizeni vykonu (ALC) |
|
|
1157 |
if(psv_val>BAD_PSV) delta=PWR_LIM-pwr_val; // pri spatnem PSV omez vykon |
|
|
1158 |
else delta=power-pwr_val; |
|
|
1159 |
if(delta<-PWR_HIST_HI && pwm_val>PWM_MIN) |
|
|
1160 |
{ |
|
|
1161 |
if(delta<-10) pwm_val=pwm_val-4; |
|
|
1162 |
else pwm_val--; |
|
|
1163 |
pom16=pwm_val; |
|
|
1164 |
set_pwm2_duty(pom16<<1); |
|
|
1165 |
} else if(delta>PWR_HIST_LO && pwm_val<PWM_MAX) |
|
|
1166 |
{ |
|
|
1167 |
if(delta>10) pwm_val=pwm_val+4; |
|
|
1168 |
else pwm_val++; |
|
|
1169 |
pom16=pwm_val; |
|
|
1170 |
set_pwm2_duty(pom16<<1); |
|
|
1171 |
} |
|
|
1172 |
#endif |
|
|
1173 |
} |
|
|
1174 |
|
|
|
1175 |
// zobrazeni na LCD delame mene casto |
|
|
1176 |
if(count>4) |
|
|
1177 |
{ |
|
|
1178 |
bit_set(_LCD2_UPDATE); |
|
|
1179 |
count=0; |
|
|
1180 |
} else count++; |
|
|
1181 |
}// analog_inputs |
|
|
1182 |
|
|
|
1183 |
|
|
|
1184 |
/* |
|
|
1185 |
void pwr_control() |
|
|
1186 |
{ |
|
|
1187 |
int16 aaa; |
|
|
1188 |
signed int8 delta; |
|
|
1189 |
|
|
|
1190 |
if(bit_test(_TRANSMIT)) |
|
|
1191 |
{ |
|
|
1192 |
delta=power-pwr_val; |
|
|
1193 |
if(delta<-1 && pwm_val>27) |
|
|
1194 |
{ |
|
|
1195 |
if(delta<-10) pwm_val=pwm_val-4; |
|
|
1196 |
else |
|
|
1197 |
pwm_val--; |
|
|
1198 |
aaa=pwm_val; |
|
|
1199 |
set_pwm2_duty(aaa<<1); |
|
|
1200 |
} else if(delta>2 && pwm_val<157) |
|
|
1201 |
{ |
|
|
1202 |
if(delta>10) pwm_val=pwm_val+4; |
|
|
1203 |
else |
|
|
1204 |
pwm_val++; |
|
|
1205 |
aaa=pwm_val; |
|
|
1206 |
set_pwm2_duty(aaa<<1); |
|
|
1207 |
} |
|
|
1208 |
} |
|
|
1209 |
} // pwr_control |
|
|
1210 |
*/ |
|
|
1211 |
|
|
|
1212 |
|
|
|
1213 |
|
|
|
1214 |
|
|
|
1215 |
///////////////////////////////// |
|
|
1216 |
///// HLAVNI FUNKCE ///// |
|
|
1217 |
///////////////////////////////// |
|
|
1218 |
void main() |
|
|
1219 |
{ |
|
|
1220 |
int8 ee_adr; |
|
|
1221 |
|
|
|
1222 |
int8 a; |
|
|
1223 |
int8 b; |
|
|
1224 |
signed int8 c; |
|
|
1225 |
|
|
|
1226 |
|
|
|
1227 |
|
|
|
1228 |
// inicializace LCD |
|
|
1229 |
lcd_init(); |
|
|
1230 |
// definice specialnich znaku |
|
|
1231 |
lcd_define_char(2,LCD_CHAR_a_FILL); |
|
|
1232 |
lcd_define_char(1,LCD_CHAR_b_FILL); |
|
|
1233 |
lcd_define_char(3,LCD_CHAR_9_FILL); |
|
|
1234 |
|
|
|
1235 |
// nastaveni smeru signalu a jejich klidovych stavu |
|
|
1236 |
port_b_pullups(TRUE); |
|
|
1237 |
output_high(DDS_FSYNC); // zapis_so DDS neaktivni |
|
|
1238 |
output_low(DDS_SDATA); // data do 0 |
|
|
1239 |
output_high(DDS_SCK); // hodiny do neaktivniho stavu |
|
|
1240 |
output_low(RXTX); // prepni na prijem |
|
|
1241 |
output_low(KEYING); // neklicuj |
|
|
1242 |
output_low(LCD_LED2); // zhasni led |
|
|
1243 |
output_low(LCD_LED1); // zhasni led |
|
|
1244 |
input(TONE); // vypni priposlech |
|
|
1245 |
output_low(PWR_CTRL); // nulovy vykon |
|
|
1246 |
|
|
|
1247 |
output_low(ATN1); |
|
|
1248 |
output_low(ATN2); |
|
|
1249 |
output_low(ATNC); |
|
|
1250 |
|
|
|
1251 |
// inicializace DDS |
|
|
1252 |
dds_send(CTRL_RESET); // pozadujeme reset |
|
|
1253 |
dds_send(CLR_PHASE0); |
|
|
1254 |
dds_send(CLR_PHASE1); |
|
|
1255 |
|
|
|
1256 |
|
|
|
1257 |
// zakladni nastaveni ridicich promennych programu |
|
|
1258 |
update_timer=UPDATE_TIME; // natahni periodicky timer pro LCD |
|
|
1259 |
flags=0; // nuluj priznaky ridici program |
|
|
1260 |
elbug_flags=0; // nuluj priznaky pro elbug |
|
|
1261 |
keys_flags=0; |
|
|
1262 |
adc_flags=0; |
|
|
1263 |
adc_ch=0; |
|
|
1264 |
pwm_val=PWM_MIN; |
|
|
1265 |
enc_delta=0; // zadna zmena od kroutitka |
|
|
1266 |
keys=0; // zadna tlacitka nejsou stisknuta |
|
|
1267 |
freq_rit=0; // nuluj RIT |
|
|
1268 |
|
|
|
1269 |
// uvodni hlaseni programu |
|
|
1270 |
lcd_gotoxy(1,1); |
|
|
1271 |
printf(lcd_putc,NAME); |
|
|
1272 |
lcd_gotoxy(1,2); |
|
|
1273 |
printf(lcd_putc,VERSION); |
|
|
1274 |
delay_ms(1000); |
|
|
1275 |
|
|
|
1276 |
// nastaveni AD prevodniku |
|
|
1277 |
setup_adc(ADC_CLOCK_DIV_8); |
|
|
1278 |
setup_adc_ports(AN0_AN1_AN2_AN3_AN4); // povoleny porty AN0-AN4 |
|
|
1279 |
|
|
|
1280 |
set_band(); // nastav pasmo podle pripojeneho filtru nebo cekej na jeho pripojeni |
|
|
1281 |
|
|
|
1282 |
check_eeprom(); // kontrola platnosti obsahu eeprom, pri poruse nastav defaultni parametry |
|
|
1283 |
|
|
|
1284 |
// obnoveni a nastaveni parametru programu |
|
|
1285 |
par[PAR_POWER]=read_eeprom(EE_ADR_POWER+band_index); // vyzvedni nastaveny vykon pro dane pasmo |
|
|
1286 |
power=par[PAR_POWER]*5; |
|
|
1287 |
|
|
|
1288 |
par[PAR_KEYER]=read_eeprom(EE_ADR_KEYER); // vyzvedni rychlost klice |
|
|
1289 |
if(par[PAR_KEYER]<=PAR_LIMIT[PAR_KEYER][0]) elbug_flags=0; // vypni elbug |
|
|
1290 |
else |
|
|
1291 |
{ |
|
|
1292 |
// zapni elbug a nastav rychlost |
|
|
1293 |
bit_set(_ELBUG_ON); |
|
|
1294 |
elbug_dot_sp=~(ELBUG_CONST/par[PAR_KEYER]); // preved na hodnotu citace TMR1 |
|
|
1295 |
elbug_dot_sp++; |
|
|
1296 |
elbug_dash=(elbug_dot_sp<<1)+elbug_dot_sp; // *3, ale rychleji |
|
|
1297 |
} |
|
|
1298 |
|
|
|
1299 |
par[PAR_VOX]=read_eeprom(EE_ADR_VOX); // vyzvedni vox |
|
|
1300 |
vox_time=par[PAR_VOX]; |
|
|
1301 |
if(vox_time!=0) vox_time=vox_time*20; // cas je ve 100ms jednotkach |
|
|
1302 |
else vox_time=2; |
|
|
1303 |
|
|
|
1304 |
par[PAR_KEYER_REV]=read_eeprom(EE_ADR_KEYER_REV); // vyzvedni chapani pak |
|
|
1305 |
if(par[PAR_KEYER_REV]) bit_set(_ELBUG_REV); // |
|
|
1306 |
else bit_clear(_ELBUG_REV); |
|
|
1307 |
|
|
|
1308 |
|
|
|
1309 |
par[PAR_KEYER_REV]=read_eeprom(EE_ADR_KEYER_REV); // vyzvedni mod elbugu |
|
|
1310 |
// if(par[PAR_KEYER_REV]) bit_set(_ELBUG_REAL); // |
|
|
1311 |
// else bit_clear(_ELBUG_REAL); |
|
|
1312 |
bit_clear(_ELBUG_REAL); // mod elbugu je zatim vzdy doplnkovy |
|
|
1313 |
|
|
|
1314 |
par[PAR_ATTN]=PAR_LIMIT[PAR_ATTN][0]; // attenuator vzdy vypnut |
|
|
1315 |
Attn_0dB(); |
|
|
1316 |
freq_vfo[0]=START_FREQ[band_index]; // QRP volaci kmitocet BAND_LIMIT[band_index][0] ; // po zapnuti ma VFO nejmensi kmitocet pasma |
|
|
1317 |
freq_vfo[1]=START_FREQ[band_index]; // QRP volaci kmitocet BAND_LIMIT[band_index][0] ; // po zapnuti ma VFO nejmensi kmitocet pasma |
|
|
1318 |
bit_set(_DDS_UPDATE); // pozadujeme nastavit kmitocet v dds |
|
|
1319 |
step_index=0; // defaultne jemny krok ladeni |
|
|
1320 |
vfo_index=0; // defaultne vfoA |
|
|
1321 |
|
|
|
1322 |
|
|
|
1323 |
|
|
|
1324 |
// nastaveni zakladniho tiku |
|
|
1325 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128); |
|
|
1326 |
set_timer0(TICK_TIME); |
|
|
1327 |
|
|
|
1328 |
// nastaveni pro generovani priposlechu, rizeni LCD_LED a PWM pro rizeni vykonu |
|
|
1329 |
setup_timer_2(T2_DIV_BY_16,TONE_SET,4); // zajisti pro PWM rozliseni 8.28 bitu |
|
|
1330 |
setup_ccp1(CCP_PWM); // pro generovani tonu |
|
|
1331 |
set_pwm1_duty((TONE_SET+1)/2); // strida cca 1:1 |
|
|
1332 |
tone_off(); // priposlech vypnut |
|
|
1333 |
setup_ccp2(CCP_PWM); // pro rizeni vykonu |
|
|
1334 |
set_pwm2_duty((int16)27); // |
|
|
1335 |
setup_timer_1(T1_DISABLED); // elbug je v klidu |
|
|
1336 |
|
|
|
1337 |
|
|
|
1338 |
#use fast_io(b) |
|
|
1339 |
keyer=(~input_b()) & 0b11000000; // precti stav pak |
|
|
1340 |
#use standard_io(b) |
|
|
1341 |
|
|
|
1342 |
if(bit_test(keyer,6)) bit_clear(_ELBUG_ON); // pokud je ori zapnuti stisknuta paka carek, je pripojen rucni klic |
|
|
1343 |
|
|
|
1344 |
|
|
|
1345 |
// povoleni preruseni |
|
|
1346 |
enable_interrupts(INT_EXT); // preruseni od zmeny polohy kroutitka |
|
|
1347 |
enable_interrupts(INT_TIMER0); // zakadni tik |
|
|
1348 |
enable_interrupts(INT_TIMER2); // preruseni pro rizeni vykonu, LED a generovani priposlechu |
|
|
1349 |
enable_interrupts(INT_TIMER1); // preruseni pro elbug |
|
|
1350 |
enable_interrupts(INT_RB); // preruseni od stavu pak klice |
|
|
1351 |
enable_interrupts(GLOBAL); |
|
|
1352 |
|
|
|
1353 |
|
|
|
1354 |
|
|
|
1355 |
|
|
|
1356 |
|
|
|
1357 |
//#define TEST |
|
|
1358 |
#ifdef TEST |
|
|
1359 |
|
|
|
1360 |
bit_set(_TRANSMIT); |
|
|
1361 |
//bit_set(_MNU); |
|
|
1362 |
|
|
|
1363 |
fwd_val=150; |
|
|
1364 |
rev_val=10; |
|
|
1365 |
smtr_val=150; |
|
|
1366 |
bnd_val=0x20; |
|
|
1367 |
|
|
|
1368 |
a=50; |
|
|
1369 |
b=5; |
|
|
1370 |
|
|
|
1371 |
|
|
|
1372 |
// testovaci smycka pro zjistovani doby behu testovane funkce |
|
|
1373 |
setup_timer_1(T1_INTERNAL|RTCC_DIV_1); |
|
|
1374 |
set_timer1(0); |
|
|
1375 |
|
|
|
1376 |
//Analog_inputs(); |
|
|
1377 |
|
|
|
1378 |
c=b-a; |
|
|
1379 |
|
|
|
1380 |
setup_timer_1(T1_DISABLED); |
|
|
1381 |
lcd_gotoxy(1,1); |
|
|
1382 |
printf(lcd_putc,"T:%LU",get_timer1()); |
|
|
1383 |
lcd_gotoxy(1,2); |
|
|
1384 |
printf(lcd_putc,"%D",c); |
|
|
1385 |
|
|
|
1386 |
for(;;); |
|
|
1387 |
|
|
|
1388 |
#else |
|
|
1389 |
|
|
|
1390 |
|
|
|
1391 |
|
|
|
1392 |
// HLAVNI SMYCKA |
|
|
1393 |
for(;;) |
|
|
1394 |
{ |
|
|
1395 |
|
|
|
1396 |
///////////////// |
|
|
1397 |
// pozadavek na zmenu kmitoctu (max. 2,5ms) |
|
|
1398 |
if(bit_test(_DDS_UPDATE)) dds_update(); |
|
|
1399 |
|
|
|
1400 |
//////////////// |
|
|
1401 |
// nastala zmena polohy kroutitka |
|
|
1402 |
if(bit_test(_ENC_CHNG)) enc_chng(); |
|
|
1403 |
|
|
|
1404 |
///////////////// |
|
|
1405 |
// zmena parametru |
|
|
1406 |
if(bit_test(_PAR_UPDATE)) par_update(); |
|
|
1407 |
|
|
|
1408 |
///////////////// |
|
|
1409 |
// pozadavek zmeny kmitoctu na lcd - 1.radek (zabere 30ms !!!!!) |
|
|
1410 |
// PODMINKU NUTNO UPRAVIT |
|
|
1411 |
if(bit_test(_LCD1_UPDATE) && update_timer==0 && !bit_test(_ELBUG_BSY)) lcd1_update(); |
|
|
1412 |
|
|
|
1413 |
|
|
|
1414 |
///////////////// |
|
|
1415 |
// pozadavek na zmenu informaci na lcd - 2.radek (max 2ms) |
|
|
1416 |
if(bit_test(_LCD2_UPDATE) && update_timer==0) |
|
|
1417 |
{ |
|
|
1418 |
lcd2_update(); |
|
|
1419 |
update_timer=0xFF; // ukonci okno,kdy je timer vyprseny |
|
|
1420 |
} |
|
|
1421 |
|
|
|
1422 |
|
|
|
1423 |
///////////////// |
|
|
1424 |
// periodicka mereni (max 3ms) |
|
|
1425 |
if(update_timer==0) |
|
|
1426 |
{ |
|
|
1427 |
analog_inputs(); |
|
|
1428 |
update_timer=0xFF; // ukonci okno,kdy je timer vyprseny |
|
|
1429 |
} |
|
|
1430 |
|
|
|
1431 |
|
|
|
1432 |
///////////////// |
|
|
1433 |
// stisknuta tlacitka |
|
|
1434 |
|
|
|
1435 |
if(bit_test(_KEYS_VALID)) // stisknuto nejake tlacitko |
|
|
1436 |
{ |
|
|
1437 |
// kratky stisk libovolneho tlacitka ukonci nastavovani |
|
|
1438 |
if(bit_test(_MNU) && !bit_test(_KEYS_LONG)) |
|
|
1439 |
{ |
|
|
1440 |
bit_clear(_MNU); // vypni nastavovani |
|
|
1441 |
enc_delta=0; // zahod nacitane zbyle impulzy korutitka |
|
|
1442 |
if(bit_test(_ELBUG_ON_TMP)) bit_set(_ELBUG_ON); // obnov zapnuti elbugu pokud byl zapnut |
|
|
1443 |
|
|
|
1444 |
if(par_index!=PAR_ATTN) // stav attenuatoru se neuklada do eeprom |
|
|
1445 |
{ |
|
|
1446 |
ee_adr=EE_ADDR[par_index]; |
|
|
1447 |
if(par_index==PAR_POWER) ee_adr=ee_adr+band_index; // pro parametr vykonu urci adresu eeprom pro dane pasmo |
|
|
1448 |
if(read_eeprom(ee_adr)!=par[par_index]) // pokud doslo ke zmene parametru, aktualizuj ho v eeprom |
|
|
1449 |
{ |
|
|
1450 |
write_eeprom(ee_adr,par[par_index]); |
|
|
1451 |
update_eeprom(); |
|
|
1452 |
} |
|
|
1453 |
} |
|
|
1454 |
bit_set(_LCD1_UPDATE); |
|
|
1455 |
bit_set(_LCD2_UPDATE); |
|
|
1456 |
} else |
|
|
1457 |
{ |
|
|
1458 |
// ktere tlacitko je stisknuto? |
|
|
1459 |
if(keys==KEY_SPLIT) // SPLIT/MNU |
|
|
1460 |
{ |
|
|
1461 |
if(bit_test(_KEYS_LONG)) |
|
|
1462 |
{ |
|
|
1463 |
// dlouhy stisk - vstup do MENU |
|
|
1464 |
bit_set(_MNU2); // prvni stisk - vyber parametr |
|
|
1465 |
par_index=PAR_POWER; |
|
|
1466 |
bit_set(_LCD1_UPDATE); |
|
|
1467 |
bit_set(_LCD2_UPDATE); |
|
|
1468 |
} else |
|
|
1469 |
{ |
|
|
1470 |
// kratky stisk - pokracovani v MENU |
|
|
1471 |
if(bit_test(_MNU2)) |
|
|
1472 |
{ |
|
|
1473 |
if(par_index==PAR_POWER) |
|
|
1474 |
{ |
|
|
1475 |
// zapamatuj si , zda je elbug zapnut nebo vypnut |
|
|
1476 |
if(bit_test(_ELBUG_ON)) bit_set(_ELBUG_ON_TMP); |
|
|
1477 |
else bit_clear(_ELBUG_ON_TMP); |
|
|
1478 |
bit_clear(_ELBUG_ON); // pri nastavovani vykonu je elbug vypnut |
|
|
1479 |
} |
|
|
1480 |
bit_clear(_MNU2); // druhy stisk - prejdi do vybraneho parametru |
|
|
1481 |
bit_set(_MNU); |
|
|
1482 |
} else |
|
|
1483 |
{ |
|
|
1484 |
// kratky stisk - funkce SPLIT |
|
|
1485 |
if(bit_test(_SPLIT)) bit_clear(_SPLIT); |
|
|
1486 |
else bit_set(_SPLIT); |
|
|
1487 |
} |
|
|
1488 |
bit_set(_LCD1_UPDATE); |
|
|
1489 |
} |
|
|
1490 |
} // KEY_SPLIT |
|
|
1491 |
|
|
|
1492 |
// ostani tlacitka jsou aktivni jen kdyz nejsme ve vyberu parametru |
|
|
1493 |
if(!bit_test(_MNU2)) |
|
|
1494 |
{ |
|
|
1495 |
if(keys==KEY_RIT) // RIT/STEP |
|
|
1496 |
{ |
|
|
1497 |
if(bit_test(_KEYS_LONG)) |
|
|
1498 |
{ |
|
|
1499 |
// dlouhy stisk - funkce STEP |
|
|
1500 |
if(step_index) step_index=0; |
|
|
1501 |
else step_index=1; |
|
|
1502 |
bit_set(_LCD1_UPDATE); |
|
|
1503 |
} else |
|
|
1504 |
{ |
|
|
1505 |
// kratky stisk - funkce RIT |
|
|
1506 |
if(bit_test(_RIT)) |
|
|
1507 |
{ |
|
|
1508 |
bit_clear(_RIT); |
|
|
1509 |
freq_rit=0; // pri vypnuti RIT vynuluj |
|
|
1510 |
} else bit_set(_RIT); |
|
|
1511 |
bit_set(_DDS_UPDATE); |
|
|
1512 |
} |
|
|
1513 |
} // KEY_RIT |
|
|
1514 |
|
|
|
1515 |
if(keys==KEY_CHNGVFO) // prepni VFO/srovnej VFO |
|
|
1516 |
{ |
|
|
1517 |
if(bit_test(_KEYS_LONG)) |
|
|
1518 |
{ |
|
|
1519 |
// dlouhy stisk - funkce srovnej VFO |
|
|
1520 |
if(vfo_index) freq_vfo[0]=freq_vfo[1]; |
|
|
1521 |
else freq_vfo[1]=freq_vfo[0]; |
|
|
1522 |
} else |
|
|
1523 |
{ |
|
|
1524 |
// kratky stisk - funkce prepni VFO |
|
|
1525 |
if(vfo_index) vfo_index=0; |
|
|
1526 |
else vfo_index=1; |
|
|
1527 |
bit_set(_DDS_UPDATE); |
|
|
1528 |
} |
|
|
1529 |
} // KEY_CHNGVFO |
|
|
1530 |
|
|
|
1531 |
if(keys==KEY_ATTN) // ATTN/ELBUG |
|
|
1532 |
{ |
|
|
1533 |
if(bit_test(_KEYS_LONG)) |
|
|
1534 |
{ |
|
|
1535 |
// dlouhy stisk - funkce ELBUG |
|
|
1536 |
par_index=PAR_KEYER; |
|
|
1537 |
bit_set(_MNU); |
|
|
1538 |
bit_set(_LCD1_UPDATE); |
|
|
1539 |
bit_set(_LCD2_UPDATE); |
|
|
1540 |
} else |
|
|
1541 |
{ |
|
|
1542 |
// kratky stisk - funkce ATTN - mozne jen pokud se nevysila |
|
|
1543 |
par_index=PAR_ATTN; |
|
|
1544 |
bit_set(_MNU); |
|
|
1545 |
bit_set(_LCD1_UPDATE); |
|
|
1546 |
bit_set(_LCD2_UPDATE); |
|
|
1547 |
} |
|
|
1548 |
} // KEY_ATTN |
|
|
1549 |
} |
|
|
1550 |
} |
|
|
1551 |
bit_clear(_KEYS_VALID); // tlacitko zpracovano |
|
|
1552 |
bit_set(_KEYS_RELEASE); // budeme cekat na uvolneni tlacitek |
|
|
1553 |
} |
|
|
1554 |
|
|
|
1555 |
} // hlavni smycka |
|
|
1556 |
#endif |
|
|
1557 |
} |
|
|
1558 |
// End of File |