tags. By typing [code] and [/co de] (without the space) before and after your code, it makes it a lot easier to read.
Mike.
Edit, I see you added it now so ignore the above.
' PicBasic Pro program to read DS1620 3-wire temperature sensor connected to PORTC.0
‘PORTC.1 and PORTC.2
' and display temperature on 2nd line of LCD AND display fuel state on LCD line 1
‘inputs are PORTB1 (DS1620) PORTB4 (DS1620) and PORTB6 (pushbutton switch)
‘Outputs are PORTB1 (SOLENOID 1) PORTB5 (SOLENOID 2) and LCD Display 2 X 16 or 2 X 20 in 4 bit mod
‘IF PORTB.6 = 1 the switch is closed on pin RB6 (pushbutton pressed)
‘IF and ONLY IF BOTH DS1620’s connected to PORTB.1 AND PORTB.4 are HIGH then BOTH OUTPUTS on PORTB.2 and ‘PORTB.5 are set HIGH driving (through a transistor switch) a relay on each OUTPUT port.
‘IF the switch is closed on PORTB.6 then OUTPUTS on PORTB.1 goes LOW and PORTB.5 goes HIGH AND the display ‘shows the word FLUSHING for a period of 10 seconds and then all outputs reset to a LOW state and LCD displays the ‘word DIESEL
‘”HOPEFULLY” and hopefully using a 16F877 PIC CHIP
' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Alias pins
RST var PORTC.0 ' Reset pin
DQ var PORTC.1 ' Data pin
CLK var PORTC.3 ' Clock pin
' Allocate variables
temp var word ' Storage for temperature
Low RST ' Reset the device
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start
Lcdout $fe, 1, “DIESEL” $C0 "Temp in degrees C" ' Display sign-on message
input PORTB.1
output PORTB.2
input PORTB.4
output PORTB.5
input PORTB.6
output PORTB.7
MAIN
if PORTB.1=1 then
if PORTB.4=1 then
if PORTB.6=0 then SOLENOID
Endif
If PORTB.1=1 then
If PORTB.4=1 then
If PORTB.6=1 then PURGE
Endif
' Temploop to read the temperature and display on LCD
Temploop:
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0
Pause 1000 ' Wait 1 second for conversion to complete
RST = 1
Shiftout DQ, CLK, LSBFIRST, [$aa] ' Send read command
Shiftin DQ, CLK, LSBPRE, [temp\9] ' Read 9 bit temperature
RST = 0
' Display the decimal temperature
Lcdout $fe,$C0, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
Goto Temploop ' Do it forever
‘PURGE flushes IP pump of oil and replaces it with diesel
Purge:
Output PORTB.2 1
Output PORTB.5 0
Lcdout $fe “FLUSHING”
Pause 1000 ’10 second hold before solenoids are reset
Output PORTB.2 0
Output PORTB.5 0
Lcdout $fe “Diesel”
‘SOLENOID send outputs to solenoids and display fuel state on LCD
SOLENOID:
Output PORTB.2 1
Output PORTB,5 1
Lcdout $fe “VEG-OIL”
Main:
If (PORTB.1=1) and (PORTB.4=1) and (PORTB.6=0) then
Lcdout $fe,1,"VEG-OIL"
PORTB.2=1
PORTB.6=1
Endif
If (PORTB.1=1) and (PORTB.4=1) and (PORTB.6=1) then
Lcdout $fe,1,"FLUSHING"
PORTB.2=1
PORTB.5=0
Pause 1000
Lcdout $fe,1,"DIESEL"
PORTB.2=0
PORTB.5=0
Endif
Goto Main
DEVICE = 16F877 ' We'll use a PIC16F877 PICmicro
XTAL = 4 ' With a 4MHz crystal
' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Alias pins
RST var PORTC.0 ' Reset pin
DQ var PORTC.1 ' Data pin
CLK var PORTC.3 ' Clock pin
' Allocate variables
temp var word ' Storage for temperature
Low RST ' Reset the device
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start
Lcdout $fe,1, "DIESEL"
Lcdout $fe,$C0, "Temp in degrees C" ' Display sign-on message
input PORTB.1
output PORTB.2
input PORTB.4
output PORTB.5
input PORTB.6
output PORTB.7
IF PORTB.1 = 1 AND PORTB.4 = 1 AND PORTB.6 = 0 GOTO SOLENOID
ENDIF
IF PORTB.1 = 1 AND PORTB.4 = 1 AND PORTB.6 = 1 GOTO PURGE
ENDIF
' Temploop to read the temperature and display on LCD
Temploop:
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0
Pause 1000 ' Wait 1 second for conversion to complete
RST = 1
Shiftout DQ, CLK, LSBFIRST, [$aa] ' Send read command
Shiftin DQ, CLK, LSBPRE, [temp\9] ' Read 9 bit temperature
RST = 0
' Display the decimal temperature
Lcdout $fe,$C0, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
Goto Temploop ' Do it forever
‘PURGE flushes IP pump of oil and replaces it with diesel
Purge:
Output PORTB.2 1
Output PORTB.5 0
Lcdout $fe, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 1000
Output PORTB.2 0
Output PORTB.5 0
Lcdout $fe, "Diesel"
‘SOLENOID send outputs to solenoids and display fuel state on LCD
SOLENOID:
Output PORTB.2 1
Output PORTB,5 1
Lcdout $fe, "VEG-OIL"
karenhornby said:Can this circuit/code be in a "smaller" pic? other than the 16F877 ie one with less lines.
DEVICE = 16F877 ' We'll use a PIC16F877 PICmicro
XTAL = 4 ' With a 4MHz crystal
' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Alias pins
RST var PORTC.0 ' Reset pin
DQ var PORTC.1 ' Data pin
CLK var PORTC.3 ' Clock pin
' Allocate variables
temp var word ' Storage for temperature
Low RST ' Reset the device
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start
Lcdout $fe,1, "DIESEL"
Lcdout $fe,$C0, "Temp in degrees C" ' Display sign-on message
input PORTB.1 'Input from DS1620 in Thermostat mode (only HIGH or LOW)
output PORTB.2 'OUTPUT to Solenoid 1
input PORTB.4 ' Input from DS1620 in Thermostat mode (only HIGH or LOW)
output PORTB.5 'OUTPUT to Solenoid 2
input PORTB.6 'INPUT from Pushbutton Switch
output PORTB.7
MAIN:
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN TestSolenoid
' Temploop to read the temperature and display on LCD
Temploop:
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0
Pause 1000 ' Wait 1 second for conversion to complete
RST = 1
Shiftout DQ, CLK, LSBFIRST, [$aa] ' Send read command
Shiftin DQ, CLK, LSBPRE, [temp\9] ' Read 9 bit temperature
RST = 0
' Display the decimal temperature
Lcdout $fe,$C0, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
Goto MAIN ' Do it forever
‘PURGE flushes IP pump of oil and replaces it with diesel
Purge:
Output PORTB.5
LOW PORTB.2
Lcdout $fe, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 1000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe, "Diesel"
LOW PORTB.5
LOW PORTB.2
END
‘SOLENOID send outputs to solenoids(Switches fuel supply from Diesel to Veg-Oil)
'and display fuel state on LCD
SOLENOID:
Output PORTB.2
Output PORTB.5
Lcdout $fe, "VEG-OIL"
GOTO TempLoop
TestSolenoid: 'check to see if PURGE button is pressed
if PORTB.6 = 0 then SOLENOID
if PORTB.6 = 1 then PURGE
karenhornby said:I put the END command there because IF the subroutine PURGE gets called, then the program ends once that section has done its bit.
\Hopefully that makes sense?
Oh the 1st 2 DS1620's DONT need clocking, they are running in thermostat mode with only a 1 wire output, pin 5 either high or low, only other 2 connections are +5V and 0V (once the temperature thresholds have been programmed into it.
MAIN:
high PORTB.0 'toggle the clock pin.
Pause 10 'the conversion will be complete
Low PORTB.0 'before the inputs are read further down.
' Temploop to read the temperature and display on LCD
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0
Pause 1000 ' Wait 1 second for conversion to complete
RST = 1
Shiftout DQ, CLK, LSBFIRST, [$aa] ' Send read command
Shiftin DQ, CLK, LSBPRE, [temp\9] ' Read 9 bit temperature
RST = 0
' Display the decimal temperature
Lcdout $fe,$C0, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
if PORTB.6 = 0 then
'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"
else
'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2
endif
endif
Goto MAIN ' Do it forever
Lcdout $fe, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 1000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe, "Diesel"
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
if PORTB.6 = 0 then
'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"
else
'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2
endif
endi
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
[COLOR="Blue"] if PORTB.6 = 0 then
'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"
else
'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2
endif[/COLOR]
endif
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
if PORTB.6 = 0 then
[COLOR="Red"] 'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"[/COLOR]
else
[COLOR="green"] 'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2[/COLOR]
endif
endif
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
if PORTB.6 = 0 then
'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"
else
'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2
[COLOR="Blue"] While(PORTB.6=0) 'wait for button to be pressed again
Wend 'this is short for while end[/COLOR]
endif
endif
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?