Edward LaBudde - 2011-10-04

Hugh, I get this error message :Error: Program is too large, cannot fit all subroutines into available program memory
Compiled with version: Great Cow BASIC (0.9 19/7/2011)
Attached is the program. If you comment out Line 103 (HPWM 1, 1, Heatpower) the error goes away.  The program is only using half the memory, Any Ideas?
Thanks, Ed.

'Chip model
#chip 16F88, 8      'Pic model and clock MHz
#config INTRC_IO    'Use internal Oscillator
Osctune = b'111110' 'works from 111000 to 000011
'Set the pin directions
dir portA.0 In  'Cold pin 17
dir portA.1 In  'Hot pin 18
dir portA.2 In  'Ambient Temp pin 1
dir portA.3 Out 'Heater pin 2
dir portA.4 Out 'Pump pin 3
dir portB.0 Out 'PWM pin 6 used to heat snow sensor
dir portB.1 In  'Manual Heat mode pin 7
dir portB.2 In  'Snow pin 8
dir PortB.3 Out 'Test port Pin 9
dir portB.4 In  'Manual Circulate Mode Pin 10
dir portB.5 Out 'LCD pin 11
'set defines
#define SendAHigh Set PORTB.5 Off                   'Note Polarity for 4X20 Newhaven display
#define SendALow Set PORTB.5  On 
#define Cold An0
#define Hot An1
#define Temp An2
#define Heater PortA.3
#define Pump PortA.4
#define ManualMode PortB.1
#define Snow PortB.2
#define Test PortB.3
#define ManualCirc PortB.4
#define LCD PortB.5 
dim AmbientT as integer
dim WaterinT as integer
dim WateroutT as integer
dim AmbientTemp as word
dim E_timemin as word
dim DeltaT as word
dim DisplayAmbT as word
dim DisplayinT as word
dim DisplayoutT as word
dim WaterinTemp as word
dim WateroutTemp as word
dim MeltTime_s as word
dim MeltTime_m as word
dim MeltTime_L as word
'Set inital parameters
InitSer 1, r2400, 1, 8, 1, none, invert                 'LCD interface Positive going Standby bit 2400 baud
Set LCD = On                                            'Init LCD
wait 200 ms
Option_reg.7 = off                                      'Enable WPU
HeatPower = 112                                         'Set heater power
MeltTime_s = 0                                          'Zero Melt times
MeltTime_m = 0
MeltTime_L = 0
E_timesec = 0                                           'Zero Elapsed times
E_timemin = 0
Standby:
    Set Pump = Off                                      'Turn system Off
    Set Heater = On                                     'Keep heater on to defrost
    PWMOff                                              'Turn off the PWM
    Set portB.0 = Off                                   'Turn off Port
    E_timesec = 0                                       'Zero Elapsed times
    E_timemin = 0
    Ambient = ReadAD(Temp)                              'Read Ambient air sensor
    ReadTable Tconvert, Ambient, AmbientTemp            'Look up temeperature value
    AmbientT = AmbientTemp - 80                         'Correct for lack of negiative numbers in table
    call ReadWater                                      'Check Water Temp
    call StandbyDisplay                                 'Refresh display    
    Count = 0                                           'Zero Write counter for EEprom writer
    If ManualMode = Off then Goto Manual                'Goto manual mode
    If ManualCirc = Off then Goto Circ                  'Goto circulate mode
    If Snow = On then Goto Heat                         'Goto heat mode
    If AmbientT > -25 then Goto Standby                 'Bypass fluid measurement
    Set Heater = Off
    Set Pump = On                                       'Circulate water to measure WaterinT
    wait 60 s
    Set Pump = Off
    Set Heater = On     
    call ReadWater      `                               'Read water temperature
    If AmbientT < -25 and WaterinT < -15 then Goto Warm 'Keep unit off for as long as possible
    'Wait 1 h                                           'Do hourly
Goto Standby
'Subs
Manual:                                                 'Turn on system Checked 08-09-11
    Call TurnOns
    Set Pump = On
    Set Heater = On
    HPWM 1, 1, Heatpower                                'Turn on heater on snow sensor
    If Snow = On then MeltTime_s += 1                   'record melt time
    MeltTime_m = MeltTime_s/60
    EPWrite 255, MeltTime_m                             'Record melt time
    call Elapsed_time                                   'Measure on time
    call ReadWater                                      'Read water temperature
    call ManualDisplay                                  'Refresh display
    call Write                                          'Measure DeltaT in 10 min intervals and write to EEprom
    If ManualMode = On then Goto Standby                
    Wait 713 ms                                 
Goto Manual
Circ:                                                   'Turn on system Checked?
    Set Pump = On
    Set Heater = Off
    call Elapsed_time                                   'Measure on time
    call ReadWater                                      'Read water temperature
    call CircDisplay                                    'Refresh display
    If ManualCirc = On then Goto Standby                
    Wait 713 ms                                 
Goto Circ
Heat:                                                   'Checked 08-09-11
    Call TurnOns
    Set Pump = On                                       'Turn on system
    Set Heater = On
    'HPWM 1, 1, Heatpower                               'Turn on heater on snow sensor
    If Snow = On then MeltTime_s += 1                   'record melt time
    MeltTime_m = MeltTime_s/60  
    EPWrite 255, MeltTime_m                             'Record melt time
    call Elapsed_time                                   'Measure on time
    call ReadWater                                      'Read water temperature
    call HeatDisplay                                    'Refresh display
    call Write                                          'Measure DeltaT in 10 min intervals and write to EEprom 
    If Snow = Off then                                  'Clear snow and wait 30 min.
        Wait 30 m
        goto Standby
    End If
    Wait 745 ms
Goto Heat
Warm:                                                   'Checked 08-09-11
    Set Pump = On                                       'Turn on system
    Set Heater = On
    call ReadWater                                      'Read water temperature
    call WarmDisplay                                    'Refresh display
    if WaterinT > 0 then goto Standby                   'Warm up water then turn off
    Wait 753 ms
Goto Warm
Sub ManualDisplay
    call Clear
    serprint 1, "Mode:"
    serprint 1, "Man"
    serprint 1, " T"
    Serprint 1, MeltTime_m
    Serprint 1, "m"
    call CommonDisplay
Return
Sub CircDisplay
    call Clear
    serprint 1, "Mode:"
    serprint 1, "Circ"
    call CommonDisplay
Return
Sub StandbyDisplay
    call Clear
    serprint 1, "Mode:"
    serprint 1, "Sby"
    EPRead 255, MeltTime_L
    Serprint 1, " MTime:"                                   'Read melt time
    Serprint 1, MeltTime_L
    call CommonDisplay
    Wait 1 s
Return
Sub WarmDisplay
    call Clear
    call First
    serprint 1, "Mode:"
    serprint 1, "Warm"
    call CommonDisplay
Return
Sub HeatDisplay
    call Clear
    call First
    serprint 1, "Mode:"
    serprint 1, "Heat"
    call CommonDisplay
Return
Sub CommonDisplay
    call second
    call Elapsed_time                                   'Measure on time
    serprint 1, "Ambient:"
    If AmbientT_H.7 = On then
    DisplayAmbT =  65536 - AmbientT
    Else
        DisplayAmbT = AmbientT
    End If
    If AmbientT_H.7 = On then
        serprint 1, "-"
        serprint 1, DisplayAmbT
    Else
        serprint 1, DisplayAmbT
    End If
    serprint 1, " ET:"
    serprint 1, E_timemin
    serprint 1, "m" 
    call Third
    If Waterin < 52 then
        DisplayinT =  65536 - WaterinT
    Else
        DisplayinT = WaterinT
    End If
    serprint 1, "WIn:"
    If WaterIn  < 52  then
        serprint 1, "-"
        serprint 1, DisplayinT
    Else
        serprint 1, DisplayinT
    End If
    call Fourth
    serprint 1, "WOut:"
    If Waterout < 52 then
        DisplayoutT =  65536 - WateroutT
    Else
        DisplayoutT = WateroutT
    End If
    If Waterout < 52 then
        serprint 1, "-"
        serprint 1, DisplayoutT
    Else
        serprint 1, DisplayoutT
    End If
    EPRead 254, Tons
    serprint 1, " Tons:"
    serprint 1, Tons
    'wait 1 s
Return
Sub ReadWater
    Waterin =  ReadAD (cold)
    ReadTable Tconvert, Waterin, WaterinTemp
    WaterinT = WaterinTemp - 80
    Waterout = ReadAD (hot)
    ReadTable Tconvert, Waterout, WateroutTemp
    WateroutT = WateroutTemp - 80
Return
  
Sub Elapsed_time
    E_timesec += 1                  'Seconds
    If E_timesec = 60 then
        E_timesec = 0
        E_timemin += 1              'Minutes
    end if
Return
Sub Write
    DeltaT = WateroutT - WaterinT
    EPWrite 0, DeltaT                   'Store first Delta T measurement
    If E_timemin % 10 = 0 then          'Measure DeltaT in 10 min intervals and write to EEprom     
        Count += 1
        EPWrite Count, DeltaT
    End If
Return
Sub TurnOns
    TurnOn +=1
    EPWrite 254, TurnOn
Return
Sub TestDisplay
Call Clear
    serprint 1, "First line"
    Call second 
    Serprint 1, "Second line"
    Call Third
    Serprint 1, "Third line"
    Call fourth
    Serprint 1, "Fourth line"
    wait 1 s
Return
'Display utilities
'NewHaven Display utilities
Sub Clear
    sersend 1, 254  'start CMD
    sersend 1, 81   'clear screen
Return
Sub First
    sersend 1, 254  'start CMD
    sersend 1, 69   'First line
    sersend 1, 0
Return
Sub Second
    sersend 1, 254  'start CMD
    sersend 1, 69   'second line
    sersend 1, 64
Return
Sub Third
    sersend 1, 254  'start CMD
    sersend 1, 69   'Third line
    sersend 1, 20
Return
Sub Fourth
    sersend 1, 254  'start CMD
    sersend 1, 69   'Fourth line
    sersend 1, 84
Return
Sub Baud
    '1=300, 2=1200, 3=2400, 4=9600, 5=14.4k. 6=19.2k, 7=57.6k, 8=115.2k
    sersend 1, 254  'start CMD
    sersend 1, 97   'baud select
    sersend 1, 4    '9600-
    wait 100 us
Return
Table Tconvert      'GCB can only handle positive values must subtract 80 for correct values
0
2
4
5
7
9
11
12
13
14
16
18
20
22
23
24
25
27
29
31
32
34
36
37
38
40
41
43
45
47
49
50
51
52
54
56
58
59
61
62
63
65
67
68
70
72
74
75
76
77
79
81
83
85
86
87
88
90
92
94
95
97
99
100
101
103
104
106
108
110
112
113
114
115
117
119
121
122
124
125
126
128
130
131
133
135
137
138
139
140
142
144
146
148
149
150
151
153
155
157
158
160
162
163
164
166
167
169
171
173
175
176
177
178
180
182
184
185
187
189
190
191
193
194
196
198
200
201
202
203
205
207
209
211
212
213
214
216
218
220
221
223
225
225
227
229
230
232
234
236
238
238
239
241
243
245
247
248
250
251
252
254
256
257
259
261
263
263
265
266
268
270
272
274
275
275
277
279
281
283
284
286
287
288
290
292
293
295
297
299
300
301
302
304
306
308
310
311
312
313
315
317
319
320
322
324
326
326
328
329
331
333
335
337
338
338
340
342
344
346
347
349
350
351
353
355
356
358
360
362
364
364
365
367
369
371
373
374
376
376
378
380
382
383
385
387
389
389
391
392
394
396
398
400
End Table/code]
[code]SOMETHING HERE[/code]