http://mirley.firlej.org/minitermometr_uniwersalny
linia 36 zapisuje do pamięci ale jak pierwszy raz zapisać wartość przy programowaniu , czy mikrokontroler przyjmie zero a potem zapisze właściwą wartość ?
Kod: Zaznacz cały
1 '****************************
2 'Konfiguracja
3 '****************************
4 $regfile = "attiny2313.dat"
5 $crystal = 8000000
6
7 Config Portb = &B11111111 : Portb = &B11111111
8 Config Portd = &B11111011 : Portd = &B11111111 'częś c portu jako OUT
9 ' orginał Config Porta = &B00000000 : Porta = &B11111111 'cały port a j
ako wejścia,
10 Config Porta = &B11111011 : Porta = &B11111111
11
12 Config Timer0 = Timer , Prescale = 256
13 Enable Timer0 : On Timer0 Przerwanie0
14
15
16 Enable Interrupts 'dla schematy orginalnego mirley
17 '****************************
18 'Zmienne
19 '****************************
20 Dim Dziel(2) As Byte
21 Dim Wysw As Word , Ww As Byte , W(3) As Byte
22 Dim Wysw_pomoc As Word
23 Dim T As Integer , Tu As Integer
24 Dim H As Integer , L As Integer
25 Dim Mux As Byte , I As Byte
26 Dim Ust As Bit
27 Dim Autoret As Byte
28
29 Dim F1s As Bit , F4ms As Bit , F100ms As Bit
30 Dim Minus As Bit
31 Dim Kanal As Byte
32 '****************************
33 'Wartosci Poczatkowe
34 '****************************
35 Kanal = 1 'Tu = ?
36 Readeeprom Tu , 1 'Tu = 550 nastawa Temp On/OFF
37 'Readeeprom Th , 10 ' Th = 10 histereza -bład36
38
39
40 '****************************
41 'Petla glowna
42 '****************************
43 Do
44
45 If F4ms = 1 Then
46 Reset F4ms
47 If Ust = 0 Then Wysw = T Else Wysw = Tu
48 Gosub Wyswietl_zmierz ''skocz do etykiety
49 End If
50
51 If F100ms = 1 Then
52 Reset F100ms 'jeżeli za pomocą przycisku S1 podamy stan (GND)n
a pin portuD każde przyciśnięcie
53 If Pind.2 = 0 Then 'pin6 -s1 'spowoduje że wartość temperatury ustawi
anej wzrośnie
54 Incr Tu 'Decr Tu
55
56 Autoret = 20
57 End If
58 If Pina.0 = 0 Then 'pin5 -s2
59 Decr Tu 'pomiar Tu chyba
60 Autoret = 20
61 End If
62
63 If Autoret > 0 Then
64 Ust = 1
65 Decr Autoret
66 Else
67 Ust = 0
68 End If
69
70 H = Tu + 10 'histereza powyżej temperatury ustawionej
71 L = Tu - 10 'L = Tu-Th
72
73 If T > H Then Set Portd.3 ' stanH out , na {portD.3(H)->GND}
74 If T < L Then Reset Portd.3 'portD.3 tp pin7 zmienić na out
75 End If 'do optotriak'a
76
77 Loop
78 End 'może skasować
79 '************************
80 'Zapis wartości do eeprom przełaczanej temperatury i hister :
81 '*************************
82 Zapis:
83 Disable Interrupts 'blokuje globalny system przerwań
84 Writeeeprom Tu , 1 'zapisuje w pamięci eeprom temperaturę ustawianą
w komórce o adresie 1
85 Portd = &B11111111
86 Waitms 200
87 Enable Interrupts
88 Return
89 'Zapis histerezy
90 'Disable Interrupts
91 'Writeeeprom Th , 10 'zapisuje w pamięci eeprom temperaturę ustawianą w
komórce o adresie 10
92 'Portd = &B11111111
93 ' Waitms 200
94 'Enable Interrupts
95
96 'Return
97 '****************************
98 'Przerwanie timer0
99 '****************************
100 Przerwanie0:
101 Timer0 = 131
102 Set F4ms
103 Incr Dziel(1)
104 If Dziel(1) = 25 Then
105 Dziel(1) = 0
106 Set F100ms
107 Incr Dziel(2)
108 If Dziel(2) = 10 Then
109 Dziel(2) = 0
110 Set F1s
111 End If
112 End If
113 Return
114 '****************************
115 'pomiar temp
116 '****************************
117 Temp: 'etykieta skok z Select Case
118 If F1s = 1 Then
119 Reset F1s
120 1wreset Pind , Kanal
121 1wwrite &HCC , 1 , Pind , Kanal
122 1wwrite &HBE , 1 , Pind , Kanal
123 T = 1wread(2 , Pind , Kanal):
124 Minus = T.15
125 T = Abs(t)
126 T = T * 10
127 T = T / 16
128 1wreset Pind , Kanal
129 1wwrite &HCC , 1 , Pind , Kanal
130 1wwrite &H44 , 1 , Pind , Kanal
131 End If
132 Return
133
134
135
136 '****************************
137 'wyswietlanie i wywolywanie pomiaru
138 '****************************
139 Wyswietl_zmierz:
140 Incr Mux
141 If Mux = 5 Then Mux = 0
142
143 'Portd.3 = Not Minus
144
145 For I = 1 To 3
146 Wysw_pomoc = Wysw Mod 10
147 Ww = Wysw_pomoc
148 W(i) = Lookup(ww , Tabela)
149 Wysw = Wysw / 10
150 Next I
151 If W(3) = 40 Then W(3) = 255 'wygaszenie zera wiodacego
152
153 Select Case Mux
154 Case 0:
155 Portb = W(3)
156 Reset Portd.6
157
158 Case 1:
159 Set Portd.6 'pin11- T1
160 Portb = W(2) And &B11011111
161 Reset Portd.5
162
163 Case 2:
164 Set Portd.5 'pin9 T2
165 Portb = W(1)
166 Reset Portd.4
167
168 Case 3:
169 Set Portd.4 'pin8 T3
170 Portb = 255
171 Gosub Temp
172
173 'Case 4: 'opoznienie na odczyt temp, je li nie ma to m
iga wyswietlacz
174
175 End Select
176
177 Return
178
179 '**************************************************************************
*****
180 'Tabele do wyswietlania na wyswietlaczu
181 '**************************************************************************
*****
182 Tabela:
183 Data 40 , 235 , 50 , 162 , 225 , 164 , 36 , 234 , 32 , 160
184 'znak: 0 1 2 3 4 5 6 7 8 9
185
- 3 -
przerobiłem program ale mam błąd
[/list]ROMIMAGE : 65E hex -> Will fit into ROM
ROMIMAGE : 1630 dec
FLASH USED : 79 %
BAUD : 9600 Baud
XTAL : 8000000 Hz
BAUD error : 0.16%