karenhornby
New Member
Hi
I've "designed" a program for a Pic 16F877A that will be the main part of my conversion from Diesel to Vegetable oil in my car.
What I want to do is using the a/d convertor in the 16F877A and the fuel sensor in the fuel tank (basically a variable resistor) drive line 3 of a 4 X 20 LCD display showing the word "DIESEL" and then the bar graph corrosponding to the level in the tank
and the same on line 4 but showing the word "OIL" and the same bar graph but obviously driven for a different fuel level sensor in the 2nd tank
I dont know the values of the "pots" (variable resistors) yet, but
Has anyone any idea how to write code to do this? PREFERABLY using Picbasic Pro, although if its in any other kind of basic I might be able to convert it ( or code all ready to use )
What I've got so far is this: although so far it's using a 2 X 16 lcd display
It works well, Inputs PORTC.0 and PORTC.3 are the triggers from 2 X DS1620's in thermostat modes which go high once preset temperatures are reached, this then triggers 2 solenoid valves on PORTE.0 and PORTE.1
When I've reached my destination I press button PORTD.1 which then gets rid of the oil out of the system for a set amount of time before switching back to Diesel
Feel free to use this if it's any use to anyone
Oh forgot to mention, the 2nd line of the LCD displays the temperature outside the car using a DS1820
I've "designed" a program for a Pic 16F877A that will be the main part of my conversion from Diesel to Vegetable oil in my car.
What I want to do is using the a/d convertor in the 16F877A and the fuel sensor in the fuel tank (basically a variable resistor) drive line 3 of a 4 X 20 LCD display showing the word "DIESEL" and then the bar graph corrosponding to the level in the tank
and the same on line 4 but showing the word "OIL" and the same bar graph but obviously driven for a different fuel level sensor in the 2nd tank
I dont know the values of the "pots" (variable resistors) yet, but
Has anyone any idea how to write code to do this? PREFERABLY using Picbasic Pro, although if its in any other kind of basic I might be able to convert it ( or code all ready to use
What I've got so far is this: although so far it's using a 2 X 16 lcd display
It works well, Inputs PORTC.0 and PORTC.3 are the triggers from 2 X DS1620's in thermostat modes which go high once preset temperatures are reached, this then triggers 2 solenoid valves on PORTE.0 and PORTE.1
When I've reached my destination I press button PORTD.1 which then gets rid of the oil out of the system for a set amount of time before switching back to Diesel
Feel free to use this if it's any use to anyone
Oh forgot to mention, the 2nd line of the LCD displays the temperature outside the car using a DS1820
Code:
'****************************************************************
'* Name : TEST1.BAS *
'* Author : Karen *
'* Notice : Copyright (c) 2008 . *
'* Date : 09/04/2008 *
'* Version : 1.0 *
'* Notes :Program for Auto switching Diesel/Veg Oil on my car*
'* : *
'****************************************************************
'
Define LOADER_USED 1
@ __CONFIG _HS_OSC & _LVP_OFF
' Define various stuff
DEFINE OSC 8
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus .7
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 5 ' Set LCD Enable bit i.e, PORTE.4
DEFINE LCD_BITS 4 ' Set LCD bus size ot 4 bit Upper Nibble (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD to 4 Lines
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us
TRISC.1 = 1
INPUT PORTC
' Allocate variables
command var byte ' Storage for command
i var byte ' Storage for loop counter
temp var word ' Storage for temperature
DQ var PORTA.5 ' Alias DS1820 data pin
DQ_DIR var TRISA.5 ' Alias DS1820 data direction pin
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", $FE,$C0, " Please Wait" ' Display sign-on message
Pause 3000
' Mainloop to read the temperature and display on LCD
mainloop:
Gosub init1820 ' Init the DS1820
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $44 ' Start temperature conversion
Gosub write1820
Pause 100 ' Wait 0.1 seconds for conversion to complete
Gosub init1820 ' Do another init
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $be ' Read the temperature
Gosub write1820
Gosub read1820
' Display the decimal temperature
IF PORTC.0 = 0 AND PORTC.3 = 0 then lcdout $FE,1," Diesel", $FE,$C0,"Temp", $fe, $C7, dec (temp >> 1), ".", dec (temp.0 * 5), $DF, "C": LOW PORTE.0: LOW PORTE.1
IF PORTC.0 = 1 AND PORTC.3 = 0 then gosub Tempcheck
IF PORTC.0 = 0 AND PORTC.3 = 1 then gosub Tempcheck
If PORTC.0 = 1 AND PORTC.3 = 1 then gosub Oil
IF PORTD.1 = 1 then gosub Purging
Goto mainloop ' Do it forever
Tempcheck:
lcdout $FE,1," TEMP LOW", $FE,$C0,"Still on DIESEL"
LOW PORTE.0: LOW PORTE.1
return
Purging:
LCDOUT $FE,1," PURGING Please",$FE,$C0," WAIT"
HIGH PORTE.0
LOW PORTE.1
Pause 10000
gosub Stop1
Goto mainloop
Stop1:
LOW PORTE.0
LOW PORTE.1
LOW PORTD.1
LCDOUT $FE,1," Turn OFF",$FE,$C0," Engine NOW"
while PORTD.1=0 'Give driver chance to turn engine off or wait for button to be pressed again
wend
pause 1000 'so a very quick button press is NOT recognised and the program stays paused
Goto Tempcheck
OIL:
LCDOUT $FE,1," Veg-Oil", $FE,$C0,"Temp", $fe, $C7, dec (temp >> 1), ".", dec (temp.0 * 5), $DF, "C"
HIGH PORTE.0
HIGH PORTE.1
return
' Initialize DS1820 and check for presence
init1820:
Low DQ ' Set the data pin low to init
Pauseus 500 ' Wait > 480us
DQ_DIR = 1 ' Release data pin (set to input for high)
Pauseus 100 ' Wait > 60us
If DQ = 1 Then
Lcdout $fe, 1, "DS1820 not present"
Pause 500
Goto mainloop ' Try again
Endif
Pauseus 400 ' Wait for end of presence pulse
Return
' Write "command" byte to the DS1820
write1820:
For i = 1 to 8 ' 8 bits to a byte
If command.0 = 0 Then
Gosub write0 ' Write a 0 bit
Else
Gosub write1 ' Write a 1 bit
Endif
command = command >> 1 ' Shift to next bit
Next i
Return
' Write a 0 bit to the DS1820
write0:
Low DQ
Pauseus 60 ' Low for > 60us for 0
DQ_DIR = 1 ' Release data pin (set to input for high)
Return
' Write a 1 bit to the DS1820
write1:
Low DQ ' Low for < 15us for 1
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
Pauseus 60 ' Use up rest of time slot
Return
' Read temperature from the DS1820
read1820:
For i = 1 to 16 ' 16 bits to a word
temp = temp >> 1 ' Shift down bits
Gosub readbit ' Get the bit to the top of temp
Next i
Return
' Read a bit from the DS1820
readbit:
temp.15 = 1 ' Preset read bit to 1
Low DQ ' Start the time slot
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
If DQ = 0 Then
temp.15 = 0 ' Set bit to 0
Endif
Pauseus 60 ' Wait out rest of time slot
Return
End
Last edited: