gramo
New Member
All finished, heres the code;
You can modify the Symbols Containing the Min and Max voltage values that are allowed for each gear.
The program can probably be tweaked - eg I left the volt display on there for debugging and you can remove it once you feel happy you know all of the volages are correct.
Watch the circuit in action here The SIM appears laggy as there are 7 Signal gererators in use. It will be much faster in real time.
Code:
Device 16F876
Declare XTAL 20
Config XT_OSC , WDT_OFF , PWRTE_ON , BODEN_OFF , LVP_OFF , CPD_OFF, CP_OFF , DEBUG_OFF
Declare LCD_TYPE 0
Declare LCD_DTPIN PORTB.4
Declare LCD_ENPIN PORTB.3
Declare LCD_RSPIN PORTB.2
Declare LCD_INTERFACE 4
Declare LCD_LINES 2
Dim KMH As Float
Dim Temp_Float As Float
Dim KMHT As DWord
Dim KMH_Last As DWord
Dim Result As Word
Dim Total As Float
Dim Last_Result As Float
Dim X As Byte
Symbol _1_Min = 1.243
Symbol _1_Max = 2.355
Symbol _2_Min = 2.356
Symbol _2_Max = 3.194
Symbol _3_Min = 3.195
Symbol _3_Max = 3.709
Symbol _4_Min = 3.710
Symbol _4_Max = 4.307
Symbol _5_Min = 4.308
Symbol _5_Max = 4.674
Symbol _6_Min = 4.675
Symbol _6_Max = 4.810
Symbol _N_Min = 4.811
Symbol _N_Max = 5.245
TRISC.0 = 1
DelayMS 1000
Cls
Print At 1,5, "KM/Hr"
KMHT = 0
TRISA.0 = 1
ADCON1 = %10000000 ' Set analogue input, Vref is Vdd
Start:
Result = 0
Total = 0
X = 0
Repeat
Result = ADIN 0
Result = Result * 2
Total = Total + Result
Inc X
Until X = 15
Total = Total / 15
Total = Total * 5 / 1023
Select Total
Case _1_Min To _1_Max
Print At 2, 1, "1st Gear ", DEC3 Total, "V"
Case _2_Min To _2_Max
Print At 2, 1, "2nd Gear ", DEC3 Total, "V"
Case _3_Min To _3_Max
Print At 2, 1, "3rd Gear ", DEC3 Total, "V"
Case _4_Min To _4_Max
Print At 2, 1, "4th Gear ", DEC3 Total, "V"
Case _5_Min To _5_Max
Print At 2, 1, "5th Gear ", DEC3 Total, "V"
Case _6_Min To _6_Max
Print At 2, 1, "6th Gear ", DEC3 Total, "V"
Case _N_Min To _N_Max
Print At 2, 1, "Neutral ", DEC3 Total, "V"
Case Else
Print At 2, 1, "Unknown ", DEC3 Total, "V"
EndSelect
KMHT = Counter PORTC.0, 250
If KMHT = 0 Then Goto Display
Temp_Float = KMHT
Temp_Float = Temp_Float * 4 * 7.2
KMH = Temp_Float / 1000
KMHT = KMH
Display:
If KMH_Last <> KMHT Then
Print At 1, 1, DEC3 KMHT
KMH_Last = KMHT
EndIf
GoTo Start
You can modify the Symbols Containing the Min and Max voltage values that are allowed for each gear.
The program can probably be tweaked - eg I left the volt display on there for debugging and you can remove it once you feel happy you know all of the volages are correct.
Watch the circuit in action here The SIM appears laggy as there are 7 Signal gererators in use. It will be much faster in real time.