952 |
miho |
1 |
//********************************************************************** |
|
|
2 |
// program pro rizeni TRXu - HLAVICKOVY SOUBOR |
|
|
3 |
//********************************************************************** |
|
|
4 |
// (c) OK1XGL 2005 |
|
|
5 |
|
|
|
6 |
|
|
|
7 |
#include <16F877.h> |
|
|
8 |
#device ADC=8; |
|
|
9 |
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,NOLVP,NOCPD |
|
|
10 |
#use delay (clock=4000000,restart_wdt) |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
// LCD display |
|
|
14 |
#define LCD_RS PIN_D2 /* rizeni registru LCD displeje */ |
|
|
15 |
#define LCD_E PIN_D3 /* enable LCD displeje */ |
|
|
16 |
#define LCD_DATA_LSB PIN_D4 /* pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou) */ |
|
|
17 |
#define LCD_LED1 PIN_B5 |
|
|
18 |
#define LCD_LED2 PIN_B4 |
|
|
19 |
|
|
|
20 |
#define LCD_CHAR_a_FILL "\x80\x80\x0E\x01\x0F\x1F\x0F\x80" /* male a s s vyplnenym briskem */ |
|
|
21 |
#define LCD_CHAR_b_FILL "\x10\x10\x16\x1F\x1F\x1F\x1E\x80" /* male b s vyplnenym briskem */ |
|
|
22 |
#define LCD_CHAR_9_FILL "\x0E\x1F\x1F\x0F\x01\x02\x0C\x80" /* 9 s vyplnenym briskem */ |
|
|
23 |
|
|
|
24 |
// smimac polohy - ladeni |
|
|
25 |
#define ENCODER_CLK PIN_B0 /* musi zde byt ,je od nej preruseni */ |
|
|
26 |
#define ENCODER_DIR PIN_B1 |
|
|
27 |
|
|
|
28 |
// tlacitka |
|
|
29 |
#define KEY_ATN_KEY PIN_C7 |
|
|
30 |
#define KEY_SPLIT_MNU PIN_C4 |
|
|
31 |
#define KEY_A_B PIN_C5 |
|
|
32 |
#define KEY_RIT_STEP PIN_C6 |
|
|
33 |
#define KEYPORT PORTC |
|
|
34 |
// masky pro jednotlive funkce na tlacitkach |
|
|
35 |
#define KEY_MASK 0b11110000 /* maska pouzitych tlacitek */ |
|
|
36 |
#define KEY_LONG 100 /* doba, po, ktere je povazuje stisk tlacitka za dlouhy v jednotkach zakladniho tiku */ |
|
|
37 |
|
|
|
38 |
#define KEY_RIT 0b01000000 /* funkce RIT/STEP */ |
|
|
39 |
#define KEY_SPLIT 0b00010000 /* funkce SPLIT/MNU */ |
|
|
40 |
#define KEY_CHNGVFO 0b00100000 /* prepni VFO/srovnej VFO */ |
|
|
41 |
#define KEY_ATTN 0b10000000 /* nastav utlum/rychlost elbugu */ |
|
|
42 |
|
|
|
43 |
|
|
|
44 |
// tlg. klic |
|
|
45 |
#define KEY_DASH PIN_B6 |
|
|
46 |
#define KEY_DOT PIN_B7 |
|
|
47 |
|
|
|
48 |
// ridici signaly TRXu |
|
|
49 |
#define RXTX PIN_B2 /* prepinac prijem vysilani 1= vysilani*/ |
|
|
50 |
#define KEYING PIN_B3 /* klicovaci signal */ |
|
|
51 |
#define MUTE PIN_C3 /* uzavira NF cestu pri vysilani */ |
|
|
52 |
#define TONE PIN_C2 /* generovani tonu odposlechu NEMENIT!!! PWM1 je jen zde */ |
|
|
53 |
#define PWR_CTRL PIN_C1 /* vystup PWM2 pro rizeni vystupniho vykonu PA NEMENIT !!!*/ |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
// DDS signaly |
|
|
57 |
#define DDS_FSYNC PIN_D0 /* enable prenosu dat aktivni v log0 */ |
|
|
58 |
#define DDS_SCK PIN_D5 /* musi zde byt, hodiny sestupna hrana */ |
|
|
59 |
#define DDS_SDATA PIN_D4 /* musi zde byt, seriova data */ |
|
|
60 |
#define DDS_FSEL PIN_D1 /* prepnuti frekvencnich registru */ |
|
|
61 |
|
|
|
62 |
// rizeni attenuatoru |
|
|
63 |
#define ATN1 PIN_E0 |
|
|
64 |
#define ATN2 PIN_C0 |
|
|
65 |
#define ATNC PIN_E1 |
|
|
66 |
#define RELE_PULSE 10 /* delka prepinaciho pulzu pro rele v ms jednotkach */ |
|
|
67 |
|
|
|
68 |
|
|
|
69 |
// analogove vsupni signaly |
|
|
70 |
#define REF PIN_A1 |
|
|
71 |
#define FWD PIN_A0 |
|
|
72 |
#define MTR12V PIN_A2 |
|
|
73 |
#define SMTR PIN_A3 |
|
|
74 |
#define BAND PIN_A5 |
|
|
75 |
// cisla pouzitych kanalu |
|
|
76 |
#define REF_CH 0 |
|
|
77 |
#define FWD_CH 1 |
|
|
78 |
#define MTR12V_CH 2 |
|
|
79 |
#define SMTR_CH 3 |
|
|
80 |
#define BND_CH 4 |
|
|
81 |
|
|
|
82 |
|
|
|
83 |
// konstanty verze programu |
|
|
84 |
#define NAME "VERSION " |
|
|
85 |
#define VERSION " V1.6 " |
|
|
86 |
|
|
|
87 |
// konstanty timeru0 |
|
|
88 |
#define TICK_TIME 0xFFFF-(5000/128)+1 /* zakladni tik TMR0 bude 5ms */ |
|
|
89 |
#define UPDATE_TIME 10 /* doba, po ktere se muze updatovat kde co v jedntkach tick_time */ |
|
|
90 |
|
|
|
91 |
// konstanty timeru2 |
|
|
92 |
#define TONE_SET 0x4d /* konstanta urcujici kmitocet priposlechu, zde 800Hz */ |
|
|
93 |
|
|
|
94 |
// konstanty kmitoctu pro VFO |
|
|
95 |
#define CONVERT_CONST 5.36870912 /* 2^28/50000000 , tedy 2^28/kmitocet hodin DDS*/ |
|
|
96 |
#define FREQ_IF 4999600L /* kmitocet mezifrekvence v Hz */ |
|
|
97 |
#define SUB_IF_INDEX 3 /* index pasma, od ktereho se mezifrekvencni kmitocet odecita */ |
|
|
98 |
// zakladni nastaveni ridiciho registru DDS |
|
|
99 |
#define CTRL_FREQ0 0b0010000000000000 /* prepni se do freq0 */ |
|
|
100 |
#define CTRL_FREQ1 0b0010100000000000 /* prepni se do freq1 */ |
|
|
101 |
#define CTRL_RESET 0b0010000100000000 /* pozaduj reset */ |
|
|
102 |
#define CLR_PHASE0 0b1100000000000000 /* nuluj fazovy registr 0 */ |
|
|
103 |
#define CLR_PHASE1 0b1110000000000000 /* nuluj fazovy registr 1 */ |
|
|
104 |
|
|
|
105 |
#define ENC_HISTEREZE 10 /* necitlivost kroutitka pri nastavovani parametru v impulzech */ |
|
|
106 |
|
|
|
107 |
#define BAND_NUM 4 /* pocet pasem */ |
|
|
108 |
// tabulka meznich kmitoctu v Hz pro jednotliva pasma |
|
|
109 |
int32 const BAND_LIMIT[BAND_NUM][2] = { |
|
|
110 |
//{1800000,2000000}, |
|
|
111 |
{3500000,3620000}, |
|
|
112 |
{7000000,7045000}, |
|
|
113 |
{10100000,10150000}, |
|
|
114 |
{14000000,14120000} |
|
|
115 |
//{18068000,18168000} |
|
|
116 |
//{21000000,21450000} |
|
|
117 |
}; |
|
|
118 |
|
|
|
119 |
|
|
|
120 |
int32 const START_FREQ[BAND_NUM] = { |
|
|
121 |
//1810000, |
|
|
122 |
3560000, |
|
|
123 |
7030000, |
|
|
124 |
10116000, |
|
|
125 |
14060000, |
|
|
126 |
//18096000, |
|
|
127 |
//21060000 |
|
|
128 |
}; |
|
|
129 |
|
|
|
130 |
#define RIT_STEP 10 /* krok RITu v Hz */ |
|
|
131 |
signed int16 const RIT_LIMIT[2] = {-2000,2000}; /* rozsah RITu v Hz */ |
|
|
132 |
|
|
|
133 |
int16 const FREQ_STEP[2]={20,1000}; /* tabulka ladicich kroku v Hz */ |
|
|
134 |
|
|
|
135 |
// tabulka dekodovani pasma |
|
|
136 |
#define BAND_ADC_MASK 0b11100000 |
|
|
137 |
int8 const BAND_ADC[BAND_NUM]= { |
|
|
138 |
//0x00, /* 160m */ |
|
|
139 |
0x20, /* 80m */ |
|
|
140 |
0x40, /* 40m */ |
|
|
141 |
0x60, /* 30m */ |
|
|
142 |
0x80 /* 20m */ |
|
|
143 |
//0x82, /* 17m */ |
|
|
144 |
//0x84 /* 15m */ |
|
|
145 |
}; |
|
|
146 |
|
|
|
147 |
|
|
|
148 |
// hodnoty napeti z prevodniku odpovidajici prislusnym S stupnum |
|
|
149 |
int8 const S_METER[9]= { |
|
|
150 |
0xC7, /* S2 */ |
|
|
151 |
0xBA, /* S3 */ |
|
|
152 |
0xA8, /* S4 */ |
|
|
153 |
0x91, /* S5 */ |
|
|
154 |
0x82, /* S6 */ |
|
|
155 |
0x79, /* S7 */ |
|
|
156 |
0x73, /* S8 */ |
|
|
157 |
0x6C, /* S9 */ |
|
|
158 |
0x60 /* S9 + cca 10dB */ |
|
|
159 |
}; |
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
// priznaky v promenne flags |
|
|
164 |
#define _DDS_UPDATE flags,0 /* pozadavek zmeny kmitoctu DDS */ |
|
|
165 |
#define _LCD1_UPDATE flags,1 /* pozadavek aktualizace udaje v 1.radku LCD */ |
|
|
166 |
#define _LCD2_UPDATE flags,2 /* pozadavek aktualizace udaje ve 2. radku LCD */ |
|
|
167 |
#define _PAR_UPDATE flags,3 /* pozadavek aktualizace vybraneho parametru */ |
|
|
168 |
#define _RIT flags,4 /* misto kmitoctu zobrazuj RIT */ |
|
|
169 |
#define _SPLIT flags,5 /* zapnut rezim SPRIT */ |
|
|
170 |
#define _TRANSMIT flags,6 /* je prepnuto na vysilani */ |
|
|
171 |
#define _LED_UPDATE flags,7 /* zrcadlo stavu LED */ |
|
|
172 |
#define _ENC_CHNG flags,8 /* doslo ke zmene polohy korutitka */ |
|
|
173 |
#define _TXDELAY flags,9 /* bezi spozdeni mezi stiskem klice a zaklicovanim vysilace */ |
|
|
174 |
#define _ATTN flags,10 /* je zapnuty utlum */ |
|
|
175 |
#define _MNU flags,11 /* rezim nastavovani hodnoty parametru */ |
|
|
176 |
#define _MNU2 flags,12 /* rezim vyberu parametru */ |
|
|
177 |
#define _RUN_VOX flags,13 /* bezi vox timer */ |
|
|
178 |
#define _BATT_LOW flags,14 /* baterie je vybita */ |
|
|
179 |
#define _KEYING flags,15 /* je zaklicovan vysilac */ |
|
|
180 |
|
|
|
181 |
// priznaky promenne keys_flags |
|
|
182 |
#define _KEYS_LONG keys_flags,0 /* tlacitko stisknuto po dlouhou dobu */ |
|
|
183 |
#define _KEYS_VALID keys_flags,1 /* tlacitka jsou platna */ |
|
|
184 |
#define _KEYS_RELEASE keys_flags,2 /* cekej na uvolneni tlacitka = ukonceni reakce na tlacitko */ |
|
|
185 |
|
|
|
186 |
// priznaky promenne adc_flags |
|
|
187 |
#define _ADC_START adc_flags,0 /* spust_prevod */ |
|
|
188 |
|
|
|
189 |
// priznaky promenne elbug_flags |
|
|
190 |
#define _ELBUG_ON elbug_flags,0 /* klicovani bude rizeno elbugem */ |
|
|
191 |
#define _ELBUG_BSY elbug_flags,1 /* probiha generovani signalu _ELBUG */ |
|
|
192 |
#define _ELBUG_OUT elbug_flags,2 /* vystup z elbugu */ |
|
|
193 |
#define _ELBUG_SP elbug_flags,3 /* priste vysilej mezeru */ |
|
|
194 |
#define _ELBUG_DOT elbug_flags,4 /* byla stisknuta paka tecek */ |
|
|
195 |
#define _ELBUG_DASH elbug_flags,5 /* byla stisknuta paka carek */ |
|
|
196 |
#define _ELBUG_LAST elbug_flags,6 /* minula stisknuta paka 0=dot 1=dash */ |
|
|
197 |
#define _ELBUG_REV elbug_flags,7 /* reverzni chapani pak */ |
|
|
198 |
#define _ELBUG_REAL elbug_flags,8 /* zapnuto realne klicovani */ |
|
|
199 |
#define _ELBUG_ON_TMP elbug_flags,9 /* pro zapamatovani stavu _ELBUG_ON pri nastavovani vykonu */ |
|
|
200 |
|
|
|
201 |
// konstanta pro odmereni nejmensiho elementu elbugu (tecka nebo tez mezera) |
|
|
202 |
#define ELBUG_CONST ((60*1000)/(5*5*2))*125 /* 60 - prevod na vteriny */ |
|
|
203 |
/* 1000 - prevod na ms */ |
|
|
204 |
/* 5 - prevod WPM na LPM */ |
|
|
205 |
/* 5 - pocet tecek v 1sec pro 200WPM */ |
|
|
206 |
/* 2 - zajima nas sirka tecky */ |
|
|
207 |
/* 125 - prevodni konstanta pro timer */ |
|
|
208 |
|
|
|
209 |
#define PAR_NUM 7 /* pocet parametru TRXu */ |
|
|
210 |
// cisla (indexy) parametru TRXu |
|
|
211 |
// poradi urcuje poradi ve vyberovem menu |
|
|
212 |
// parametry za volnym radkem v menu nejsou, vybiraji se na funkcnich tlacitkach |
|
|
213 |
#define PAR_POWER 0 /* vykon vysilace */ |
|
|
214 |
#define PAR_VOX 1 /* doba prepnuti zpet na prijem */ |
|
|
215 |
#define INF_BATT 2 /* napeti baterie */ |
|
|
216 |
#define PAR_KEYER_REV 3 /* zap/vyp reverzni chapani pak */ |
|
|
217 |
#define PAR_KEYER_MODE 4 /* doplnkove nebo realne klicovani */ |
|
|
218 |
|
|
|
219 |
#define PAR_KEYER 5 /* rychlost elbugu */ |
|
|
220 |
#define PAR_ATTN 6 /* attenuator */ |
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
// tabulka mezi pro jednotlive parametry |
|
|
225 |
int8 const PAR_LIMIT[PAR_NUM][2] = { |
|
|
226 |
{0,16}, /* vykon ve 0.5w jednotkach */ |
|
|
227 |
{0,40}, /* meze pro vox v 50ms jednotkach */ |
|
|
228 |
{0,0}, /* hodnota napeti baterie */ |
|
|
229 |
{0,1}, /* meze pro zap/vyp reverzi pak */ |
|
|
230 |
{0,1}, /* mod klicovani */ |
|
|
231 |
{5,40}, /* meze pro elbug ve WPM */ |
|
|
232 |
{0,3} /* meze pro attenuator 0,-6,-12 a -18dB */ |
|
|
233 |
}; |
|
|
234 |
|
|
|
235 |
// adresy jednotlivych parametru ulozenych v eeprom |
|
|
236 |
#define EE_ADR_POWER 0 /* BAND_NUM bajtu - pro kazde pasmo jeden bajt */ |
|
|
237 |
#define EE_ADR_VOX BAND_NUM |
|
|
238 |
#define EE_ADR_BATT EE_ADR_VOX+1 |
|
|
239 |
#define EE_ADR_KEYER_REV EE_ADR_BATT+1 |
|
|
240 |
#define EE_ADR_KEYER_MODE EE_ADR_KEYER_REV+1 |
|
|
241 |
#define EE_ADR_KEYER EE_ADR_KEYER_MODE+1 |
|
|
242 |
#define EE_ADR_ATTN EE_ADR_KEYER+1 |
|
|
243 |
#define EE_ADR_CRC EE_ADR_ATTN+1 /* kontrolni soucet eeprom */ |
|
|
244 |
|
|
|
245 |
// pole adres parametru ulozenych v eeprom |
|
|
246 |
int8 const EE_ADDR[PAR_NUM] = { |
|
|
247 |
EE_ADR_POWER, |
|
|
248 |
EE_ADR_VOX, |
|
|
249 |
EE_ADR_BATT, // napeti baterie se neuklada, zde je zapsana konstantni hodnota |
|
|
250 |
EE_ADR_KEYER_REV, |
|
|
251 |
EE_ADR_KEYER_MODE, |
|
|
252 |
EE_ADR_KEYER, |
|
|
253 |
EE_ADR_ATTN |
|
|
254 |
}; |
|
|
255 |
|
|
|
256 |
|
|
|
257 |
#define BATT_MIN 173 // napeti baterie, od ktere se povazuje za vybitou (hodnota z prevodniku pro 10.8V) |
|
|
258 |
#define BAD_PSV 18 // od PSV > 1.8 se omezi vykon |
|
|
259 |
#define PWR_LIM 10 // vykon pri spatnem psv je omezen na 1W |
|
|
260 |
#define PWM_MIN 27 // minimalni hodnota pro PWM2 |
|
|
261 |
#define PWM_MAX 157 // maximalni hodnota pro PWM2 |
|
|
262 |
#define PWR_HIST_LO 2 // spodni povolena odchylka od pozadovaneho vykonu v nasobcich 100mW |
|
|
263 |
#define PWR_HIST_HI 1 // horni povolena odchylka od pozadovaneho vykonu v nasobcich 100mW |
|
|
264 |
#define PWR_FWD_CONST 5600 // prevodni konstatna pro prevod napeti z ADC na vykon |
|
|
265 |
|
|
|
266 |
|
|
|
267 |
int8 lcd_pos; // poloha znaku na LCD pro specialni fce s nazvy xxx_lcd_putc |
|
|
268 |
int32 freq_vfo[2]; // pozadovany kmitocet vfoA a vfoB |
|
|
269 |
signed int16 freq_rit; // rozladeni +- pri prijmu |
|
|
270 |
signed int8 enc_delta; // +-pocet impulzu zmeny kroutitka |
|
|
271 |
|
|
|
272 |
int8 update_timer; // periodicky casovac pro aktualizaci kde ceho |
|
|
273 |
int8 key_timer; // casovac pro rozpoznani dlouheho stisku tlacitka |
|
|
274 |
int16 vox_timer; // casovac pro automaticke prepnuti na prijem po urcite dobe bez vysilani |
|
|
275 |
int16 vox_time; // hodnota vox timeru, 0 = plny BK |
|
|
276 |
int8 flash_timer; // pro blikani ledkou pri vybite baterii |
|
|
277 |
|
|
|
278 |
int8 keys; // obsahuje tlacitka, ktera byla stisknuta (0=klidovy stav) |
|
|
279 |
int8 keys_work; // pro precteni stavu tlacitek v preruseni |
|
|
280 |
int8 keys_old; // predchozi stav tlacitek, pro osetreni zakmitu |
|
|
281 |
int8 keyer; // obsahuje stav stisknutych pak elbugu |
|
|
282 |
int8 keyerb; // obsahuje aktualni stav pak elbugu |
|
|
283 |
|
|
|
284 |
int1 step_index; // index do tabulky moznych kroku ladeni |
|
|
285 |
int1 vfo_index; // index do tabulky VFO |
|
|
286 |
int8 band_index; // index do tabulky rozsahu kmitoctu |
|
|
287 |
|
|
|
288 |
int16 flags; // stavove priznaky pro rizeni programu |
|
|
289 |
int16 elbug_flags; // stavove priznaky pro rizeni elbugu |
|
|
290 |
int8 keys_flags; // stavove priznaky tlacitek |
|
|
291 |
int8 adc_flags; // stavove priznaky pro rizeni ADC |
|
|
292 |
int8 par[PAR_NUM]; // parametry TRXu |
|
|
293 |
int8 par_index; // cislo nastavovaneho parametru |
|
|
294 |
|
|
|
295 |
int8 adc_ch; // citac kanalu ADC |
|
|
296 |
int8 adc_val; // napeti z ADC aktualniho kanalu |
|
|
297 |
int8 smtr_val; // hodnota napeti z ADC odpovidajici S-metru |
|
|
298 |
int8 pwr_val; // hodnota aktualniho vykonu v 100mW jednotkach |
|
|
299 |
int8 psv_val; // hodnota psv v desetinovych jednotkach |
|
|
300 |
int8 fwd_val; // napeti z ADC odpovidajici doprednemu vykonu |
|
|
301 |
int8 rev_val; // napeti z ADC odpovidajici odrazenemu vykonu |
|
|
302 |
int8 bnd_val; // napeti z ADC odpovidajici pasmu |
|
|
303 |
int8 batt_val; // napeti z ADC odpovidajici napeti baterie |
|
|
304 |
int8 pwm_val; // hodnota pro PWM2 - rizeni vykony PA |
|
|
305 |
int8 power; // pozadovany vykon PA |
|
|
306 |
int16 elbug_dot_sp; // hotnota timeru 1 pro generovani tecky a mezery |
|
|
307 |
int16 elbug_dash; // hordnota timeru1 pro generovani carky |
|
|
308 |
|
|
|
309 |
|
|
|
310 |
#bit _T0IF = 0x0B.2 // priznak preteceni timeru0 - vyuziva se pri spousteni TXDELAY |
|
|
311 |
// (vyuziva se pro nej prave timer0) aby byla jistota, ze se TXDELAY |
|
|
312 |
// skutecne odmeri |
|
|
313 |
|
|
|
314 |
#bit _TMR1IF = 0x0C.0 // priznak preruseni od timeru 1 - pro vyprovokovani preteceni (start elbugu) |
|
|
315 |
// End of File |