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 FUEL SUPPLY
input PORTB.4 ' Input from DS1620 in Thermostat mode (only HIGH or LOW)
output PORTB.5 'OUTPUT to Solenoid 2 FUEL RETURN
input PORTB.6 'INPUT from Pushbutton Switch
output PORTC.2 ' Output to Transistor to control LCD Power on
[COLOR="Red"]input PORTD.0 'input to check MAIN power to circuit still alive
output PORTD.1 'Output to Piezo sounder[/COLOR]
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
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"
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
IF PORTB.6 = 0 AND PORTD.1 = 0 THEN
LOW PORTB.2 'switch fuel to diesel
HIGH PORTB.5 'fuel return goes to diesel tank
[COLOR="Red"]HIGH PORTD.2 'SOUND ALARM SIGNAL
Lcdout $fe,2, "PRESS THE BUTTON"[/COLOR]
else
IF PORTB.6 = 0 AND PORTD.1 = 1 THEN
HIGH PORTB.2 'fuel switches to veg oil
HIGH PORTB.5 'fuel return goes to veg oil tank
Lcdout $fe,2, "Veg-Oil"
else
HIGH PORTB.2 'switch fuel to Diesel
LOW PORTB.5 'keep fueel return to OIL tank
Lcdout $fe,2, "FLUSHING" ;clears Injection pump of Veg-Oil
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5 'switch car to Diesel Fuel
LOW PORTB.2 'switch fuel return to Diesel Fuel
While PORTB.6=0 'wait for button to be pressed again
WEND
endif 'this is short for while end
endif
endif
Goto MAIN ' Do it forever