HERE IS THE RELEVENT PARTS:
#chip 16F767, 12 'mhz
#config MCLRE=off, WDT=off
lcdcon = 0
CCP2=RC1
#define USART_BLOCKING
#define SerInPort PORTc.7
#define SerOutPort PORTc.6
#define USART_BAUD_RATE 9600 'the speed you want
InitUsart
On Interrupt UsartRX1Ready call rec_data
dir porte.3 in 'pilot
dir porta.0 in 'temp inside
dir porta.1 in 'humid inside
dir porta.2 in 'pressure
dir porta.3 in 'photo
dir porta.4 in 'gas heat in
dir porta.5 in 'bat volt
dir portc.0 out 'opener
dir portc.1 out 'charge
dir portc.2 out 'watering
dir portc.3 out 'elec heat out
dir portc.4 out 'load off
dir portc.5 out 'cooling h2o
dir portc.7 in 'serial in
dir portc.6 out 'serial out
dir portb.0 in 'pv+
dir portb.1 out 'fan
dir portb.2 in 'rain
dir portb.3 in 'out temp
dir portb.4 in 'out humid
dir portb.5 in 'wind
dir portb.6 in 'high water
dir portb.7 in 'med water
dim test1 as word
dim test2 as word
dim test3 as word
dim lcdvaluetemp as word
dim lcdvalue as word
dim rain as word
dim test5 as word
dim test6 as word
dim test7 as word
dim test4 as byte
dim state as byte
dim limit as byte
dim min as word
dim max as word
dim EHM as byte
dim EHH as word
dim GHM as byte
dim GHH as word
dim h2o as byte
dim heatd as byte
dim heatn as byte
dim coold as byte
dim cooln as byte
dim waterd as byte
dim watern as byte
dim test8 as Word
dim volt as byte
dim state1 as byte
dim loc as byte
dim tempa as byte
dim tempb as byte
dim tempc as byte
dim tempd as byte
dim tempe as byte
dim tempz as byte
tempa = 0
tempe = 0
waterer = 0
waterd = 41
watern = 41
coold = 38
cooln = 34
heatd = 29
heatn = 26
ghh = 0
ghm = 0
ehm = 0
ehh = 0
limit = 0
state = 0
wait 1 s
min = (ReadAD10(AN0)-18)*5
max = min
rain = 0
rains = 0
loc = 0
if rains = 0 then
if portb.2 off then rains = 1
end if
if rains = 1 then
if portb.2 on then rains = 0
rain = rain + 1
end if
Bin2ascii1 (rain_H)
Bin2ascii2 (rain)
HSerPrint "in rain "
if porta.3 on then day
if porta.3 off then night
if EHM = 600 then
EHH = EHH + 10
EHM = 0
end if
if GHM = 600 then
GHH = GHH + 10
GHM = 0
end if
h2o = 0
if portb.7 off then h2o = 1
if portb.6 off then h2o = 2
if waterer = 1 then set portc.2 on
if waterer = 0 then set portc.2 off
display
if state1 = 1 then HSerPrint "C:SLD " ''* IF I ADD THIS LINE OR ANY OTHER LINE
IT DOES NOT REPOND TO MY QUERY,
BUT IF A REMOVE IT, IT WORKS FINE?
wait 3 s
goto start
sub display
HSerSend 10
HSerSend 13
if porta.3 on then HSerPrint "Day "
if porta.3 off then HSerPrint "Night "
if state = 0 then HSerPrint "Rest "
if state = 1 then HSerPrint "Heat "
if state = 2 then HSerPrint "Cool "
if state = 3 then HSerPrint "H-cool "
test5 = ((ReadAD10(AN0)-18)*5)
test6 = ((ReadAD10(AN0)-18)*5)
test7 = test5 + test6
test7 = test7 / 2
if test7 < min then min = test7
if test7 > max then max = test7
Bin2ascii1 (test7_H)
Bin2ascii2 (test7)
end sub
sub rec_data
If RCIF On Then
HSerReceive tempz
if tempz = 48 then display_data
end if
end sub
sub display_data
HSerPrint "Got it"
end sub
sub Bin2ascii1 (LCDValue)#NR
sertho = 0
SErtho = LCDValue + 48
end sub
if sertho = 51 then
LCDValueTemp = LCDValue + 768
end if
if sertho = 49 then
LCDValueTemp = LCDValue + 256
end if
if sertho = 50 then
LCDValueTemp = LCDValue + 512
end if
if sertho = 48 then
LCDValueTemp = LCDValue
end if
lcdvaluetemp = lcdvalue / 10000
SERtho = LCDValueTemp + 48
if sertho<>48 then
HSerSend Sertho
end if
LCDValue = lcdvalue - LCDValueTemp * 10000
lcdvaluetemp = lcdvalue / 1000
SERCEN = LCDValueTemp + 48
if sercen<>48 then
HSerSend SerCen
end if
LCDValue = lcdvalue - LCDValueTemp * 1000
SERUN = LCDValue + 48
if serun<>48 then
HSerPrint "."
HSerSend Serun
end if
end sub
when the line that is commented on is in it will run but does not repond to my serial in query, without the line it will run and respond fine, and the actual command on that line, can be almost anything readad, bin2ascii, etc, why?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
What are State and State1 ?
You well dim state1 and state and you include them in conditions but we never find them anywhere in your program .
Also they never obtain the values you hope .State1 will never be 1 and state will never be 1 , 2 or 3 . It will only be 0
I'am not sure but I think It's the reason why your program does not responds.
CG
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
it was just part of the program, here is the full program, it runs fine and compiles, but when i send it a serial "0" it locks up and does nothing, i have made some changes to it to try and frre up memory and clean it up:
#chip 16F767, 12 'mhz
#config MCLRE=off, WDT=off
lcdcon = 0
CCP2=RC1
#define USART_BLOCKING
#define SerInPort PORTc.7
#define SerOutPort PORTc.6
#define USART_BAUD_RATE 9600 'the speed you want
InitUsart
On Interrupt UsartRX1Ready call getinfo
dir porte.3 in 'pilot
dir porta.0 in 'temp inside
dir porta.1 in 'humid inside
dir porta.2 in 'pressure
dir porta.3 in 'photo
dir porta.4 in 'gas heat in
dir porta.5 in 'bat volt
dir portc.0 out 'opener
dir portc.1 out 'charge
dir portc.2 out 'watering
dir portc.3 out 'elec heat out
dir portc.4 out 'load off
dir portc.5 out 'cooling h2o
dir portc.7 in 'serial in
dir portc.6 out 'serial out
dir portb.0 in 'pv+
dir portb.1 out 'fan
dir portb.2 in 'rain
dir portb.3 in 'out temp
dir portb.4 in 'out humid
dir portb.5 in 'wind
dir portb.6 in 'high water
dir portb.7 in 'med water
dim test1 as word
dim lcdvaluetemp as word
dim lcdvalue as word
dim rain as word
dim test6 as word
dim test7 as word
dim min as word
dim max as word
dim EHM as word
dim EHH as word
dim GHM as word
dim GHH as word
tempa = 0
tempe = 0
waterer = 0
waterd = 41
watern = 41
coold = 38
cooln = 34
heatd = 29
heatn = 26
ghh = 0
ghm = 0
ehm = 0
ehh = 0
limit = 0
state = 0
wait 1 s
min = (ReadAD10(AN0)-18)*5
max = min
rain = 0
rains = 0
loc = 0
tempz = 0
answer = 0
'Main routine
Start:
main1
main2
main3
display
disp1
disp2
disp4
disp3
if answer = 1 then
HSerPrint "Got it"
answer = 0
end if
wait 2 s
goto start
sub main2
select case test1
case <=20
HSerPrint "0"
case <= 50
HSerPrint "<5"
case <=100
HSerPrint "5-10"
end select
HSerPrint "mph "
select case rains
case 0
if portb.2 off then rains = 1
case 1
if portb.2 on then
rains = 0
rain = rain + 1
end if
end select
Bin2ascii1 (rain_H)
Bin2ascii2 (rain)
HSerPrint "in rain "
select case porta.3
case 0
night
case 1
day
end select
end sub
sub main3
select case ehm
case 600
EHH = EHH + 10
EHM = 0
end select
select case ghm
case 600
GHH = GHH + 10
GHM = 0
end select
h2o = 0
if portb.7 off then h2o = 1
if portb.6 off then h2o = 2
select case waterer
case 0
set portc.2 off
case 1
set portc.2 on
end select
end sub
sub display
HSerSend 10
HSerSend 13
select case porta.3
case 0
HSerPrint "Night "
case 1
HSerPrint "Day "
end select
select case state
case 0
HSerPrint "Rest "
case 1
HSerPrint "Heat "
case 2
HSerPrint "Cool "
case 3
HSerPrint "H-cool "
end select
test1 = ((ReadAD10(AN0)-18)*5)
test6 = ((ReadAD10(AN0)-18)*5)
test7 = test1 + test6
test7 = test7 / 2
if test7 < min then min = test7
if test7 > max then max = test7
Bin2ascii1 (test7_H)
Bin2ascii2 (test7)
end sub
sub disp1
if portb.1 on then HSerPrint "F"
if portc.5 on then HSerPrint "W"
if portc.0 on then HSerPrint "V"
if portc.3 on then HSerPrint "H"
if porte.3 off then HSerPrint "P"
if porta.4 off then HSerPrint "G"
select case limit
case 0
HSerPrint ":OK "
case 1
HSerPrint "Over "
case 2
HSerPrint "Under "
end select
end sub
select case h2o
case 0
HSerPrint " low H2O"
case 1
HSerPrint " med H2O"
case 2
HSerPrint " full H2O"
end select
end sub
sub disp4
HSerSend 10
HSerSend 13
set portc.1 off 'charge on
select case volt
case >130
set portc.4 on ' load on
case <= 165
solid
case <= 130
loadoff
case >= 166
if volt <= 179 then
pwm
end if
case >= 180
coff
end select
test1 = readad(an4)
volt = readad(an4)
select case state1
case 0
HSerPrint "C:OFF "
case 1
HSerPrint "C:SLD "
case 2
HSerPrint "C:PWM "
end select
select case portc.4
case 0
HSerPrint "L:OFF "
case 1
HSerPrint "L:ON "
end select
end sub
sub disp3
HSerPrint "Bv:"
test1 = test1-40
if test1>= 1000 then test1 = 0
bin2ascii2(test1)
set portc.1 off
wait 1 ms
test1 = readad(an12)
set portc.1 on
HSerPrint " Pv:"
test1 = (test1 *4)
bin2ascii2(test1)
end sub
sub getinfo
If RCIF On Then
HSerReceive tempz
if tempz = 48 then answer = 1
end if
end sub
sub getdata
if loc = 4 then
SerReceive 1, tempe
if tempe <> 36 then loc = 0
if tempe = 36 then loc = 5
end if
if loc = 3 then
SerReceive 1, tempd
if tempd <> 36 then loc = 4
if tempd = 36 then loc = 1
end if
if loc = 2 then
SerReceive 1, tempc
if tempc <> 36 then loc = 3
if tempc = 36 then loc = 1
end if
if loc = 1 then
SerReceive 1, tempb
if tempb <> 36 then loc = 2
if tempb = 36 then loc = 1
end if
if loc = 0 then
SerReceive 1, tempa
if tempa <> 36 then loc = 0
if tempa = 36 then loc = 1
end if
if loc = 5 then
tempa = 0
tempe = 0
tempb = tempb - 48
tempd = tempc - 48
tempd = tempd - 48
if tempb = 0 then watering
if tempb = 1 then dwater
if tempb = 2 then nwater
if tempb = 3 then dcool
if tempb = 4 then ncool
if tempb = 5 then dheat
if tempb = 6 then nheat
loc = 0
end if
end sub
sub watering
select case tempd
case 0
waterer = 0
case 1
waterer = 1
end select
end sub
sub dwater
waterd = (tempc*10)+ tempd
end sub
sub nwater
watern = (tempc*10)+ tempd
end sub
sub dcool
coold = (tempc*10)+ tempd
end sub
sub ncool
cooln = (tempc*10)+ tempd
end sub
sub dheat
heatd = (tempc*10)+ tempd
end sub
sub nheat
heatn = (tempc*10)+ tempd
end sub
sub day
mode = 0
if porta.4 off then GHM = GHM + 10
test1 = ReadAD(AN0)-5
test6 = ReadAD(AN0)-5
test7 = test1 + test6
test1 = ReadAD(AN0)-5
test7 = test1 + test7
test6 = ReadAD(AN0)-5
test7 = test6 + test7
test7 = test7 / 4
if test7 < heatd then heat ' 0.01960784 v/#
if test7 >= heatd then
if test7 < coold then norm
end if
if test7 >= coold then
if test7 < waterd then cool
end if
if test7 >= waterd then water
end sub
sub night
mode = 1
if porta.4 off then GHM = GHM + 10
test1 = ReadAD(AN0)-5
test6 = ReadAD(AN0)-5
test7 = test1 + test6
test1 = ReadAD(AN0)-5
test7 = test1 + test7
test6 = ReadAD(AN0)-5
test7 = test6 + test7
test7 = test7 / 4
if test7 < heatn then heat ' 0.01960784 v/#
if test7 >= heatn then
if test7 < cooln then norm
end if
if test7 >= cooln then
if test7 < watern then cool
end if
if test7 >= watern then water
end sub
sub over
limit = 1
end sub
sub under
limit = 2
end sub
sub heat
state = 10
EHM = EHM + 10
set portc.3 on 'h
set portb.1 off 'f
set portc.5 off 'o
set portc.0 off 'w
if readad(an0) > 23 then limit = 0
if ReadAD(AN0) <= 23 then under
end sub
sub cool
state = 2
set portc.3 off 'h
set portb.1 on 'f
set portc.5 off 'w
set portc.0 on 'v
if readad(an0) < 46 then limit = 0
end sub
sub water
state = 3
set portc.3 off 'h
set portb.1 on 'f
set portc.5 on 'o
set portc.0 on 'w
if readad(an0) < 46 then limit = 0
if ReadAD(AN0) >= 46 then over
end sub
sub norm
state = 0
set portc.3 off 'h
set portb.1 off 'f
set portc.5 off 'o
set portc.0 off 'w
end sub
sub coff
state1 = 0
HPWM 2, 10, 255
set portc.1 on 'charge off
set portc.4 on ' load on
end sub
sub solid
HPWM 2, 10,0
state1 = 1
set portc.1 off 'charge on
set portc.4 on ' load on
end sub
sub pwm
if volt >= 165 and if volt <= 167 then HPWM 2, 10, 50
if volt >= 168 and if volt <= 170 then HPWM 2, 10, 100
if volt >= 171 and if volt <= 174 then HPWM 2, 10, 150
if volt >= 175 then HPWM 2, 10, 200
state1 = 2
set portc.4 on ' load on
end sub
sub loadoff
set portc.4 off ' load off
volt = readad(an4)
set portc.1 off ' solid charge on
if ReadAD(an4) > 155 then
set portc.4 on 'load on
end if
end sub
sub Bin2ascii1 (LCDValue)#NR
sertho = 0
SErtho = LCDValue + 48
end sub
if sertho = 51 then
LCDValueTemp = LCDValue + 768
end if
if sertho = 49 then
LCDValueTemp = LCDValue + 256
end if
if sertho = 50 then
LCDValueTemp = LCDValue + 512
end if
if sertho = 48 then
LCDValueTemp = LCDValue
end if
lcdvaluetemp = lcdvalue / 10000
SERtho = LCDValueTemp + 48
if sertho<>48 then
HSerSend Sertho
end if
LCDValue = lcdvalue - LCDValueTemp * 10000
lcdvaluetemp = lcdvalue / 1000
SERCEN = LCDValueTemp + 48
if sercen<>48 then
HSerSend SerCen
end if
LCDValue = lcdvalue - LCDValueTemp * 1000
the new Sourceforge code tags are the worst, right back to where we started from, before the "improvements".
When it comes to printing a zero, it never gets there because of this code. That is SerUn should always be printed and not tested by a conditional statement.
SERUN = LCDValue + 48
if serun<>48 then
HSerPrint "."
HSerSend Serun
end if
Also,could be some subtle changes to GCBasic coding as explained here and and an additional reference in that post to Hugh's fix.
Lots of gyrations going on with the bin2ascii code and subs. Why not just use the lcd.h code or the bin2ascii in an "as word" form, and skip trying to keep track of the bin2ascii_H and bin2ascii in two different subs?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the pic sends out zeros fine when i want them, it's when I send it a zero form hyperterminal, and it should enter the "getinfo" sub that the pic freezes up
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
HERE IS THE RELEVENT PARTS:
#chip 16F767, 12 'mhz
#config MCLRE=off, WDT=off
lcdcon = 0
CCP2=RC1
#define USART_BLOCKING
#define SerInPort PORTc.7
#define SerOutPort PORTc.6
#define USART_BAUD_RATE 9600 'the speed you want
InitUsart
On Interrupt UsartRX1Ready call rec_data
dir porte.3 in 'pilot
dir porta.0 in 'temp inside
dir porta.1 in 'humid inside
dir porta.2 in 'pressure
dir porta.3 in 'photo
dir porta.4 in 'gas heat in
dir porta.5 in 'bat volt
dir portc.0 out 'opener
dir portc.1 out 'charge
dir portc.2 out 'watering
dir portc.3 out 'elec heat out
dir portc.4 out 'load off
dir portc.5 out 'cooling h2o
dir portc.7 in 'serial in
dir portc.6 out 'serial out
dir portb.0 in 'pv+
dir portb.1 out 'fan
dir portb.2 in 'rain
dir portb.3 in 'out temp
dir portb.4 in 'out humid
dir portb.5 in 'wind
dir portb.6 in 'high water
dir portb.7 in 'med water
dim test1 as word
dim test2 as word
dim test3 as word
dim lcdvaluetemp as word
dim lcdvalue as word
dim rain as word
dim test5 as word
dim test6 as word
dim test7 as word
dim test4 as byte
dim state as byte
dim limit as byte
dim min as word
dim max as word
dim EHM as byte
dim EHH as word
dim GHM as byte
dim GHH as word
dim h2o as byte
dim heatd as byte
dim heatn as byte
dim coold as byte
dim cooln as byte
dim waterd as byte
dim watern as byte
dim test8 as Word
dim volt as byte
dim state1 as byte
dim loc as byte
dim tempa as byte
dim tempb as byte
dim tempc as byte
dim tempd as byte
dim tempe as byte
dim tempz as byte
tempa = 0
tempe = 0
waterer = 0
waterd = 41
watern = 41
coold = 38
cooln = 34
heatd = 29
heatn = 26
ghh = 0
ghm = 0
ehm = 0
ehh = 0
limit = 0
state = 0
wait 1 s
min = (ReadAD10(AN0)-18)*5
max = min
rain = 0
rains = 0
loc = 0
'Main routine
Start:
HSerSend 12
HSerSend 13
wait 1 ms
test1 = ((ReadAD10(AN0)-18)*5) 'temp inside
Bin2ascii1 (test1_H)
Bin2ascii2 (test1)
HSerPrint "F "
test2 = ((ReadAD10(AN1)/13)*10)+30 'humid inside
Bin2ascii1 (test2_H)
Bin2ascii2 (test2)
HSerPrint "%RH "
test3 = ((ReadAD10(AN2)/8)*10)-29 'pres
Bin2ascii1 (test3_H)
Bin2ascii2 (test3)
HSerPrint "kPa "
test1 = ((ReadAD10(AN9)-9)*5) 'temp outside
Bin2ascii1 (test1_H)
Bin2ascii2 (test1)
HSerPrint "Fout "
test2 = (ReadAD10(AN11)/13)*10 'humid outside
Bin2ascii1 (test2_H)
Bin2ascii2 (test2)
HSerPrint "%RHout "
test3 = ReadAD10(AN13) -198 'wind
test3 = test3 /5
if test3 >= 65000 then test3 = 0
Bin2ascii1 (test3_H)
Bin2ascii2 (test3)
HSerPrint "mph "
if rains = 0 then
if portb.2 off then rains = 1
end if
if rains = 1 then
if portb.2 on then rains = 0
rain = rain + 1
end if
Bin2ascii1 (rain_H)
Bin2ascii2 (rain)
HSerPrint "in rain "
if porta.3 on then day
if porta.3 off then night
if EHM = 600 then
EHH = EHH + 10
EHM = 0
end if
if GHM = 600 then
GHH = GHH + 10
GHM = 0
end if
h2o = 0
if portb.7 off then h2o = 1
if portb.6 off then h2o = 2
if waterer = 1 then set portc.2 on
if waterer = 0 then set portc.2 off
display
if state1 = 1 then HSerPrint "C:SLD " ''* IF I ADD THIS LINE OR ANY OTHER LINE
IT DOES NOT REPOND TO MY QUERY,
BUT IF A REMOVE IT, IT WORKS FINE?
wait 3 s
goto start
sub display
HSerSend 10
HSerSend 13
if porta.3 on then HSerPrint "Day "
if porta.3 off then HSerPrint "Night "
if state = 0 then HSerPrint "Rest "
if state = 1 then HSerPrint "Heat "
if state = 2 then HSerPrint "Cool "
if state = 3 then HSerPrint "H-cool "
test5 = ((ReadAD10(AN0)-18)*5)
test6 = ((ReadAD10(AN0)-18)*5)
test7 = test5 + test6
test7 = test7 / 2
if test7 < min then min = test7
if test7 > max then max = test7
Bin2ascii1 (test7_H)
Bin2ascii2 (test7)
end sub
sub rec_data
If RCIF On Then
HSerReceive tempz
if tempz = 48 then display_data
end if
end sub
sub display_data
HSerPrint "Got it"
end sub
sub Bin2ascii1 (LCDValue)#NR
sertho = 0
SErtho = LCDValue + 48
end sub
sub Bin2ascii2 (LCDValue)#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
if sertho = 51 then
LCDValueTemp = LCDValue + 768
end if
if sertho = 49 then
LCDValueTemp = LCDValue + 256
end if
if sertho = 50 then
LCDValueTemp = LCDValue + 512
end if
if sertho = 48 then
LCDValueTemp = LCDValue
end if
lcdvaluetemp = lcdvalue / 10000
SERtho = LCDValueTemp + 48
if sertho<>48 then
HSerSend Sertho
end if
LCDValue = lcdvalue - LCDValueTemp * 10000
lcdvaluetemp = lcdvalue / 1000
SERCEN = LCDValueTemp + 48
if sercen<>48 then
HSerSend SerCen
end if
LCDValue = lcdvalue - LCDValueTemp * 1000
lcdvaluetemp = lcdvalue / 100
SERCEN = LCDValueTemp + 48
'if sercen<>48 then
HSerSend SerCen
'end if
LCDValue = LCDValue - LCDValueTemp * 100
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
HSerSend Serdec
LCDValue = LCDValue - LCDValueTemp * 10
SERUN = LCDValue + 48
if serun<>48 then
HSerPrint "."
HSerSend Serun
end if
end sub
when the line that is commented on is in it will run but does not repond to my serial in query, without the line it will run and respond fine, and the actual command on that line, can be almost anything readad, bin2ascii, etc, why?
Hello,
What are State and State1 ?
You well dim state1 and state and you include them in conditions but we never find them anywhere in your program .
Also they never obtain the values you hope .State1 will never be 1 and state will never be 1 , 2 or 3 . It will only be 0
I'am not sure but I think It's the reason why your program does not responds.
CG
it was just part of the program, here is the full program, it runs fine and compiles, but when i send it a serial "0" it locks up and does nothing, i have made some changes to it to try and frre up memory and clean it up:
#chip 16F767, 12 'mhz
#config MCLRE=off, WDT=off
lcdcon = 0
CCP2=RC1
#define USART_BLOCKING
#define SerInPort PORTc.7
#define SerOutPort PORTc.6
#define USART_BAUD_RATE 9600 'the speed you want
InitUsart
On Interrupt UsartRX1Ready call getinfo
dir porte.3 in 'pilot
dir porta.0 in 'temp inside
dir porta.1 in 'humid inside
dir porta.2 in 'pressure
dir porta.3 in 'photo
dir porta.4 in 'gas heat in
dir porta.5 in 'bat volt
dir portc.0 out 'opener
dir portc.1 out 'charge
dir portc.2 out 'watering
dir portc.3 out 'elec heat out
dir portc.4 out 'load off
dir portc.5 out 'cooling h2o
dir portc.7 in 'serial in
dir portc.6 out 'serial out
dir portb.0 in 'pv+
dir portb.1 out 'fan
dir portb.2 in 'rain
dir portb.3 in 'out temp
dir portb.4 in 'out humid
dir portb.5 in 'wind
dir portb.6 in 'high water
dir portb.7 in 'med water
dim test1 as word
dim lcdvaluetemp as word
dim lcdvalue as word
dim rain as word
dim test6 as word
dim test7 as word
dim min as word
dim max as word
dim EHM as word
dim EHH as word
dim GHM as word
dim GHH as word
tempa = 0
tempe = 0
waterer = 0
waterd = 41
watern = 41
coold = 38
cooln = 34
heatd = 29
heatn = 26
ghh = 0
ghm = 0
ehm = 0
ehh = 0
limit = 0
state = 0
wait 1 s
min = (ReadAD10(AN0)-18)*5
max = min
rain = 0
rains = 0
loc = 0
tempz = 0
answer = 0
'Main routine
Start:
main1
main2
main3
display
disp1
disp2
disp4
disp3
if answer = 1 then
HSerPrint "Got it"
answer = 0
end if
wait 2 s
goto start
sub main1
HSerSend 12
HSerSend 13
wait 1 ms
test1 = ((ReadAD10(AN0)-18)*5) 'temp inside
Bin2ascii1 (test1_H)
Bin2ascii2 (test1)
HSerPrint "F "
test1 = ((ReadAD10(AN1)/13)*10)+30 'humid inside
Bin2ascii1 (test1_H)
Bin2ascii2 (test1)
HSerPrint "%RH "
test1 = ((ReadAD10(AN2)/8)*10)-30 'pres
Bin2ascii1 (test1_H)
Bin2ascii2 (test1)
HSerPrint "kPa "
test1 = ((ReadAD10(AN9)-9)*5) 'temp outside
Bin2ascii1 (test1_H)
Bin2ascii2 (test1)
HSerPrint "Fout "
test1 = (ReadAD10(AN11)/13)*10 'humid outside
Bin2ascii1 (test1_H)
Bin2ascii2 (test1)
HSerPrint "%RHout "
test1 = ReadAD10(AN13) -198 'wind
test1 = test1 /5
if test1 >= 65000 then test1 = 0
end sub
sub main2
select case test1
case <=20
HSerPrint "0"
case <= 50
HSerPrint "<5"
case <=100
HSerPrint "5-10"
end select
HSerPrint "mph "
select case rains
case 0
if portb.2 off then rains = 1
case 1
if portb.2 on then
rains = 0
rain = rain + 1
end if
end select
Bin2ascii1 (rain_H)
Bin2ascii2 (rain)
HSerPrint "in rain "
select case porta.3
case 0
night
case 1
day
end select
end sub
sub main3
select case ehm
case 600
EHH = EHH + 10
EHM = 0
end select
select case ghm
case 600
GHH = GHH + 10
GHM = 0
end select
h2o = 0
if portb.7 off then h2o = 1
if portb.6 off then h2o = 2
select case waterer
case 0
set portc.2 off
case 1
set portc.2 on
end select
end sub
sub display
HSerSend 10
HSerSend 13
select case porta.3
case 0
HSerPrint "Night "
case 1
HSerPrint "Day "
end select
select case state
case 0
HSerPrint "Rest "
case 1
HSerPrint "Heat "
case 2
HSerPrint "Cool "
case 3
HSerPrint "H-cool "
end select
test1 = ((ReadAD10(AN0)-18)*5)
test6 = ((ReadAD10(AN0)-18)*5)
test7 = test1 + test6
test7 = test7 / 2
if test7 < min then min = test7
if test7 > max then max = test7
Bin2ascii1 (test7_H)
Bin2ascii2 (test7)
end sub
sub disp1
if portb.1 on then HSerPrint "F"
if portc.5 on then HSerPrint "W"
if portc.0 on then HSerPrint "V"
if portc.3 on then HSerPrint "H"
if porte.3 off then HSerPrint "P"
if porta.4 off then HSerPrint "G"
select case limit
case 0
HSerPrint ":OK "
case 1
HSerPrint "Over "
case 2
HSerPrint "Under "
end select
end sub
sub disp2
HSerPrint "min"
Bin2ascii1 (min_H)
Bin2ascii2 (min)
HSerPrint ":"
Bin2ascii1 (max_H)
Bin2ascii2 (max)
HSerPrint "max"
HSerPrint " EH"
Bin2ascii1 (EHH_H)
Bin2ascii2 (EHH)
HSerPrint ":"
Bin2ascii2 (EHM)
HSerPrint " GH"
Bin2ascii1 (GHH_H)
Bin2ascii2 (GHH)
HSerPrint ":"
Bin2ascii2 (GHM)
select case h2o
case 0
HSerPrint " low H2O"
case 1
HSerPrint " med H2O"
case 2
HSerPrint " full H2O"
end select
end sub
sub disp4
HSerSend 10
HSerSend 13
set portc.1 off 'charge on
select case volt
case >130
set portc.4 on ' load on
case <= 165
solid
case <= 130
loadoff
case >= 166
if volt <= 179 then
pwm
end if
case >= 180
coff
end select
test1 = readad(an4)
volt = readad(an4)
select case state1
case 0
HSerPrint "C:OFF "
case 1
HSerPrint "C:SLD "
case 2
HSerPrint "C:PWM "
end select
select case portc.4
case 0
HSerPrint "L:OFF "
case 1
HSerPrint "L:ON "
end select
end sub
sub disp3
HSerPrint "Bv:"
test1 = test1-40
if test1>= 1000 then test1 = 0
bin2ascii2(test1)
set portc.1 off
wait 1 ms
test1 = readad(an12)
set portc.1 on
HSerPrint " Pv:"
test1 = (test1 *4)
bin2ascii2(test1)
end sub
sub getinfo
If RCIF On Then
HSerReceive tempz
if tempz = 48 then answer = 1
end if
end sub
sub getdata
if loc = 4 then
SerReceive 1, tempe
if tempe <> 36 then loc = 0
if tempe = 36 then loc = 5
end if
if loc = 3 then
SerReceive 1, tempd
if tempd <> 36 then loc = 4
if tempd = 36 then loc = 1
end if
if loc = 2 then
SerReceive 1, tempc
if tempc <> 36 then loc = 3
if tempc = 36 then loc = 1
end if
if loc = 1 then
SerReceive 1, tempb
if tempb <> 36 then loc = 2
if tempb = 36 then loc = 1
end if
if loc = 0 then
SerReceive 1, tempa
if tempa <> 36 then loc = 0
if tempa = 36 then loc = 1
end if
if loc = 5 then
tempa = 0
tempe = 0
tempb = tempb - 48
tempd = tempc - 48
tempd = tempd - 48
if tempb = 0 then watering
if tempb = 1 then dwater
if tempb = 2 then nwater
if tempb = 3 then dcool
if tempb = 4 then ncool
if tempb = 5 then dheat
if tempb = 6 then nheat
loc = 0
end if
end sub
sub watering
select case tempd
case 0
waterer = 0
case 1
waterer = 1
end select
end sub
sub dwater
waterd = (tempc*10)+ tempd
end sub
sub nwater
watern = (tempc*10)+ tempd
end sub
sub dcool
coold = (tempc*10)+ tempd
end sub
sub ncool
cooln = (tempc*10)+ tempd
end sub
sub dheat
heatd = (tempc*10)+ tempd
end sub
sub nheat
heatn = (tempc*10)+ tempd
end sub
sub day
mode = 0
if porta.4 off then GHM = GHM + 10
test1 = ReadAD(AN0)-5
test6 = ReadAD(AN0)-5
test7 = test1 + test6
test1 = ReadAD(AN0)-5
test7 = test1 + test7
test6 = ReadAD(AN0)-5
test7 = test6 + test7
test7 = test7 / 4
if test7 < heatd then heat ' 0.01960784 v/#
if test7 >= heatd then
if test7 < coold then norm
end if
if test7 >= coold then
if test7 < waterd then cool
end if
if test7 >= waterd then water
end sub
sub night
mode = 1
if porta.4 off then GHM = GHM + 10
test1 = ReadAD(AN0)-5
test6 = ReadAD(AN0)-5
test7 = test1 + test6
test1 = ReadAD(AN0)-5
test7 = test1 + test7
test6 = ReadAD(AN0)-5
test7 = test6 + test7
test7 = test7 / 4
if test7 < heatn then heat ' 0.01960784 v/#
if test7 >= heatn then
if test7 < cooln then norm
end if
if test7 >= cooln then
if test7 < watern then cool
end if
if test7 >= watern then water
end sub
sub over
limit = 1
end sub
sub under
limit = 2
end sub
sub heat
state = 10
EHM = EHM + 10
set portc.3 on 'h
set portb.1 off 'f
set portc.5 off 'o
set portc.0 off 'w
if readad(an0) > 23 then limit = 0
if ReadAD(AN0) <= 23 then under
end sub
sub cool
state = 2
set portc.3 off 'h
set portb.1 on 'f
set portc.5 off 'w
set portc.0 on 'v
if readad(an0) < 46 then limit = 0
end sub
sub water
state = 3
set portc.3 off 'h
set portb.1 on 'f
set portc.5 on 'o
set portc.0 on 'w
if readad(an0) < 46 then limit = 0
if ReadAD(AN0) >= 46 then over
end sub
sub norm
state = 0
set portc.3 off 'h
set portb.1 off 'f
set portc.5 off 'o
set portc.0 off 'w
end sub
sub coff
state1 = 0
HPWM 2, 10, 255
set portc.1 on 'charge off
set portc.4 on ' load on
end sub
sub solid
HPWM 2, 10,0
state1 = 1
set portc.1 off 'charge on
set portc.4 on ' load on
end sub
sub pwm
if volt >= 165 and if volt <= 167 then HPWM 2, 10, 50
if volt >= 168 and if volt <= 170 then HPWM 2, 10, 100
if volt >= 171 and if volt <= 174 then HPWM 2, 10, 150
if volt >= 175 then HPWM 2, 10, 200
state1 = 2
set portc.4 on ' load on
end sub
sub loadoff
set portc.4 off ' load off
volt = readad(an4)
set portc.1 off ' solid charge on
if ReadAD(an4) > 155 then
set portc.4 on 'load on
end if
end sub
sub Bin2ascii1 (LCDValue)#NR
sertho = 0
SErtho = LCDValue + 48
end sub
sub Bin2ascii2 (LCDValue)#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
if sertho = 51 then
LCDValueTemp = LCDValue + 768
end if
if sertho = 49 then
LCDValueTemp = LCDValue + 256
end if
if sertho = 50 then
LCDValueTemp = LCDValue + 512
end if
if sertho = 48 then
LCDValueTemp = LCDValue
end if
lcdvaluetemp = lcdvalue / 10000
SERtho = LCDValueTemp + 48
if sertho<>48 then
HSerSend Sertho
end if
LCDValue = lcdvalue - LCDValueTemp * 10000
lcdvaluetemp = lcdvalue / 1000
SERCEN = LCDValueTemp + 48
if sercen<>48 then
HSerSend SerCen
end if
LCDValue = lcdvalue - LCDValueTemp * 1000
lcdvaluetemp = lcdvalue / 100
SERCEN = LCDValueTemp + 48
'if sercen<>48 then
HSerSend SerCen
'end if
LCDValue = LCDValue - LCDValueTemp * 100
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
HSerSend Serdec
LCDValue = LCDValue - LCDValueTemp * 10
SERUN = LCDValue + 48
if serun<>48 then
HSerPrint "."
HSerSend Serun
end if
end sub
the new Sourceforge code tags are the worst, right back to where we started from, before the "improvements".
When it comes to printing a zero, it never gets there because of this code. That is SerUn should always be printed and not tested by a conditional statement.
Also,could be some subtle changes to GCBasic coding as explained here and and an additional reference in that post to Hugh's fix.
Lots of gyrations going on with the bin2ascii code and subs. Why not just use the lcd.h code or the bin2ascii in an "as word" form, and skip trying to keep track of the bin2ascii_H and bin2ascii in two different subs?
Well ok then, at least the code tags are back to step 2. If preview came back, at least we could tell how things would look.
the pic sends out zeros fine when i want them, it's when I send it a zero form hyperterminal, and it should enter the "getinfo" sub that the pic freezes up