922 |
kaklik |
1 |
//********************************************************************** |
|
|
2 |
// LCT-METER/PULSER - HLAVICKOVY SOUBOR |
|
|
3 |
//********************************************************************** |
|
|
4 |
// (c) OK1XGL 2004 |
|
|
5 |
// verze 1.00 - uvodni verze 10.1.2004 |
|
|
6 |
// verze 1.01 - pridano ukladani vlastni Cp/Lp do pameti EEPROM |
|
|
7 |
// - pridano ukladani stavu (mod, parametry modu ) do pameti EEROM |
|
|
8 |
// |
|
|
9 |
|
|
|
10 |
#use delay (clock=4000000,restart_wdt) |
|
|
11 |
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP |
|
|
12 |
|
|
|
13 |
// LCD display |
|
|
14 |
#define LCD_RS PIN_A0 /* rizeni registru LCD displeje */ |
|
|
15 |
#define LCD_E PIN_A1 /* enable LCD displeje */ |
|
|
16 |
#define LCD_DATA_LSB PIN_A2 /* pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou) */ |
|
|
17 |
#define LCD_CHAR_DELTA "\x80\x80\x80\x04\x0A\x11\x1F\x80" /* symbol delta */ |
|
|
18 |
#define LCD_CHAR_DEC "\x0E\x0A\x0E\x80\x80\x80\x80\x80" /* symbol stupen */ |
|
|
19 |
|
|
|
20 |
// rele pro prepinani modu mereni |
|
|
21 |
#define RE1_A PIN_C4 |
|
|
22 |
#define RE1_B PIN_C7 |
|
|
23 |
#define RE2_A PIN_C5 |
|
|
24 |
#define RE2_B PIN_C6 |
|
|
25 |
#define RELE_PULSE 10 /* delka prepinaciho pulzu pro rele v ms jednotkach */ |
|
|
26 |
|
|
|
27 |
// tlacitka (libovolne na brane B) |
|
|
28 |
#define NUL_KEY PIN_B7 /* pro nulovani pocatecni C nebo L NEBO T, pri generovani pulzu prepina sirku pulzu */ |
|
|
29 |
#define MODE_KEY PIN_B6 /* pro prepinani modu mereni */ |
|
|
30 |
|
|
|
31 |
// pulser (nelze zmenit, vystup PWM a CPP1 jednotky je jen zde) |
|
|
32 |
#define PULSER_PIN PIN_C2 /* vystup pulseru */ |
|
|
33 |
|
|
|
34 |
// teplomer (POZOR NA VSTUPY SE SHMIDTOVYM OBVODEM, NELZE POUZIT!!!!!) |
|
|
35 |
#define TM_PIN PIN_B0 /* pin, na kterem je teplomer pripojen */ |
|
|
36 |
#bit TM_PIN_BIT = PORTB.0 /* totez, ale definovan jako bit */ |
|
|
37 |
#define TM_PULLUP PIN_B1 /* pullup pro teplomer */ |
|
|
38 |
|
|
|
39 |
// konstanty pro mereni frekvence |
|
|
40 |
#define TIME_1S_L 0xff-194 /* urcuje dobu, za kterou vyprsi timer0 (zde 50ms),meri interval doby mereni frekvence */ |
|
|
41 |
#define TIME_1S_H 5 /* rozsiruje timer0, aby bylo mozne odmerit delsi casy zde 250ms */ |
|
|
42 |
#define CORIG 21 /* pro korekci intervalu doby mereni frekvence aby byla presne (vliv doby preruseni a nepresnost oscilatoru) */ |
|
|
43 |
#define FREQ_CALM_TIME 2000 /* cas pro ustaleni frekvence oscialtoru v ms jednotkach */ |
|
|
44 |
#define C_CALIB 996 /* hodnota kalibracniho kondenzatoru v pF */ |
|
|
45 |
#define F_CORRECT 4 /* korekce zmereneho kmitoctu, aby byl v Hz a ne v napr. v 4Hz jednotkach jako zde */ |
|
|
46 |
|
|
|
47 |
// adresy parametru v pameti EEROM |
|
|
48 |
#define CP_ADR_LOW 0 /* pro ulozeni vlastni kapacity 4 bajty*/ |
|
|
49 |
#define LP_ADR_LOW 4 /* pro ulozeni vlastni indukcnosti 4 bajty*/ |
|
|
50 |
#define MODE_ADR 8 /* uchovani modu zarizeni viz promenna mode */ |
|
|
51 |
#define WIDTH_ADR 9 /* uchovani sirky pulzu v modu pulser viz promenna pulse_width */ |
|
|
52 |
|
|
|
53 |
// konstanty pro mereni teploty |
|
|
54 |
#define CONV_WAIT 4 /* cas cekani az teplomer zmeri teplotu v jednotkach doby citani impulzu pri mereni frekvence */ |
|
|
55 |
|
|
|
56 |
// konstanty pro promennou mode ve funkci main() |
|
|
57 |
#define MODE_L 0 /* mereni indukcnosti */ |
|
|
58 |
#define MODE_C 1 /* mereni kapacity */ |
|
|
59 |
#define MODE_T 2 /* mereni teploty */ |
|
|
60 |
#define MODE_P 3 /* generator pulzu */ |
|
|
61 |
|
|
|
62 |
// konstanty pro promennou pulse_width ve funkci pulser() |
|
|
63 |
#define P_10US 0 |
|
|
64 |
#define P_20US 1 |
|
|
65 |
#define P_50US 2 |
|
|
66 |
#define P_100US 3 |
|
|
67 |
#define P_200US 4 |
|
|
68 |
#define P_500US 5 |
|
|
69 |
#define P_1MS 6 |
|
|
70 |
#define P_2MS 7 |
|
|
71 |
#define P_5MS 8 |
|
|
72 |
#define P_10MS 9 |
|
|
73 |
#define P_20MS 10 |
|
|
74 |
#define P_50MS 11 |
|
|
75 |
#define P_500MS 12 |
|
|
76 |
#define P_5US 13 |
|
|
77 |
|
|
|
78 |
// konstanty pro promennou status ve funkci measure_T() |
|
|
79 |
#define T_WAIT 0 /* odmer 1000 ms */ |
|
|
80 |
#define T_MEASURE 1 /* posli prikaz ke zmereni teploty */ |
|
|
81 |
#define T_DISPLAY 2 /* precti zmerenou teplotu a zobraz ji */ |
|
|
82 |
|
|
|
83 |
// konstanty pro promennou freq_done |
|
|
84 |
#define F_PEACE 0 /* klidovy stav tuto hodnotu nemenit !!!! */ |
|
|
85 |
#define F_DONE 1 /* mereni frekvence dokonceno */ |
|
|
86 |
#define F_KEY 2 /* stisknuto tlacitko, mereni frekvence preruseno */ |
|
|
87 |
|
|
|
88 |
// texty zobrazovane na 1.radku LCD displeje |
|
|
89 |
#define VERSION_MSG " Version 1.01" |
|
|
90 |
#define COPYRIGHT_MSG "(c) OK1XGL 2004" |
|
|
91 |
#define CALIB_MSG " Calibration" |
|
|
92 |
#define CONNECT_LX_MSG " Connect Lx !!!" |
|
|
93 |
#define ERROR_CX_MSG " Error Cx !!!" |
|
|
94 |
#define CONNECT_TEMP_MSG " Connect temp" |
|
|
95 |
#define PULSE_5us_MSG " 5us (100KHz)" |
|
|
96 |
#define PULSE_10us_MSG " 10us (50KHz)" |
|
|
97 |
#define PULSE_20us_MSG " 20us (25KHz)" |
|
|
98 |
#define PULSE_50us_MSG " 50us (10KHz)" |
|
|
99 |
#define PULSE_100us_MSG " 100us (5KHz)" |
|
|
100 |
#define PULSE_200us_MSG " 200us (2.5KHz)" |
|
|
101 |
#define PULSE_500us_MSG " 500us (1KHz)" |
|
|
102 |
#define PULSE_1ms_MSG " 1ms (500Hz)" |
|
|
103 |
#define PULSE_2ms_MSG " 2ms (250Hz)" |
|
|
104 |
#define PULSE_5ms_MSG " 5ms (100Hz)" |
|
|
105 |
#define PULSE_10ms_MSG " 10ms (50Hz)" |
|
|
106 |
#define PULSE_20ms_MSG " 20ms (25Hz)" |
|
|
107 |
#define PULSE_50ms_MSG " 50ms (10Hz)" |
|
|
108 |
#define PULSE_500ms_MSG " 500ms (1Hz)" |
|
|
109 |
|
|
|
110 |
// texty zobrazovane na 2. radku LCD displeje |
|
|
111 |
#define MODE_CX_NULL_MSG "MODE Cx NULL" |
|
|
112 |
#define MODE_LX_NULL_MSG "MODE Lx NULL" |
|
|
113 |
#define MODE_TMP_NULL_MSG "MODE +TMP NULL" |
|
|
114 |
#define MODE_PLZ_WIDTH_MSG "MODE +PLZ WIDTH" |
|
|
115 |
|
|
|
116 |
// konstantni pole pro prefix radu |
|
|
117 |
int8 const C_PREFIX[4] = {'p','n','u','m'}; |
|
|
118 |
char const L_PREFIX[4] = {'n','u','m',' '}; |
|
|
119 |
|
|
|
120 |
// uvodni nastaveni parametru v pameti eeprom |
|
|
121 |
#rom 0x2100={0,0,0,0,0,0,0,0,MODE_C,P_5US} |
|
|
122 |
|
|
|
123 |
// globalni promenne |
|
|
124 |
int8 freq_done; // stav procesu mereni frekvence |
|
|
125 |
int8 W_TMP; // pro ulozeni W v prerusovaci rutine |
|
|
126 |
int8 F_TMP; // pro ulozeni F v prerusovaci rutine |
|
|
127 |
int8 PCLATH_TMP; // pro ulozeni PCLATH v prerusovaci rutine |
|
|
128 |
int8 INT_TMP; // pomocna promenna pro preruseni |
|
|
129 |
int8 sampler_H; // rozsireni timeru0 ,ktery meri dobu citani impulzu mericiho oscilatoru v tmr0 jednotkach |
|
|
130 |
int8 counter_H; // rozsireni timeru1, ktery slouzi pro citani impulzu mericiho oscilatoru |
|
|
131 |
|
|
|
132 |
// End of File |