;Ford Ranger Lighting and Accessory Controller
;May 2013
;40x2 Main processor coding
;Slot 0
#slot0
low d.3 'Set relay for power control
setfreq m16
symbol jumpslot= b6
gosub readdata
fvrsetup FVR2048 ;set the ADC reference voltage to 2.048v
adcconfig %1000 ;Vref+ is FVR, Vref- is 0V
if jumpslot=>1 and jumpslot=<5 then 'If returning from another slot, send to the main menu
gosub draw_main_menu
goto main_loop
endif
if jumpslot=7 then goto pin_lock
#no_data 'Enable to stop it clearing the eeprom
dirsA = %11111111 ;1=Output 0=input
dirsB = %11110010
dirsC = %01110111
dirsD = %01100011
Symbol pinE = pinb.7 : Symbol dirE = dirb.7 ; 0 = Idle 1 = Active
Symbol pinRS = pinb.5 : Symbol dirRS = dirb.5 ; 0 = Command 1 = Data
Symbol pinD4 = pinb.6 : Symbol dirD4 = dirb.6 ; LCD Data Line 4
Symbol pinD5 = pinc.5 : Symbol dirD5 = dirc.5 ; LCD Data Line 5
Symbol pinD6 = pinc.4 : Symbol dirD6 = dirc.4 ; LCD Data Line 6
Symbol pinD7 = pinB.1 : Symbol dirD7 = dirB.1 ; LCD Data Line 7
symbol Bluetoothdata=b28 'Set up the bluetooth variable
'_______________________________________________________________________________________________
PowerOnReset:
Gosub InitialiseLcd
'B0 is used as variable for Oled
symbol sfx = b1 ;SFX 1=on 0=off
symbol countloop = b2 ;counter loop for general timing use
countloop=0
symbol rearlights = b3
'b4 is used as a for loop variable
symbol instantmode= b5 ;What lights are on full beam
symbol drlstat=b7 ;Status of the ignition input
symbol outer130stat=b8 ;status of the full beam input
symbol inner130stat=b9
symbol DRLs = b10
symbol hazard = b11
symbol Rearultrasonics = b12
symbol Sparetyreloop = b13
symbol Pager = b14
symbol Rearlidlock = b15
symbol screensaveron = b16
symbol voltageoff = b17
symbol pin1 = b18
symbol pin2 = b19
symbol pin3 = b20
symbol pin4 = b21
'b22,b23,b24 used as variables for bintoascii conversion
symbol line=b25 'Value of the required display line starting point
symbol menu = b26
symbol rearworkstat = b27 'Status of the rear work lights (1=on)
symbol sequence=b29 'Which headlight sequence is selected (0=off)
symbol quote=b30 'Required text to display on LCD
symbol outerroofstat=b31
symbol innerroofstat=b32
symbol abarstat=b33
symbol flashcheck=b34 'Logs whether its checked for a headlight flash
symbol reqlight=b35 'Which light to flash (retrived from memory)
symbol readaddress=b36 'Used in the flash lights routine
symbol flashdelay=b37 'Time between flashes of sequenced lights
symbol general=b38 'General use variable
symbol ledbarover=b39 'Led bar over-ride 1=on
symbol blueleds=b40 'Whether blue leds are on
symbol ignlock=b41 'Whether ignition lock is on
symbol blueledstat=b42 'Status of blue leds
'b43 used as general variable
symbol flashdelaytotal=w22 'Flash delay after multiplication
symbol voltagevalue=w23 'Current value of input voltage
symbol voltagetarget=w24 'Voltage target to switch off lights
'b50 used as general variable
symbol emergencyoff=b51 'If this equals 1 then switch of all lights due to low battery
symbol screensaver=w26 'Screensaver is active if this equals 1
symbol lightmode=b54 'The 4x4 quick change mode (AUX)
symbol screensaverdelay=b55 'Slows the occurances of checking the screensaver
menu=1 ;Menu counter
screensaver=0
system_reset: 'Holding ENTER for 60 seconds resets the pincode (used the screensaver variable)
if pind.4=1 then
screensaver=screensaver+1
endif
if screensaver>65000 then
write 10,1
write 11,1
write 12,1
write 13,1
sound c.6, (114,50)
goto reset_skip
endif
if pind.4=1 then system_reset
reset_skip:
screensaver=0
'write 0,1 'Sound
'write 1,3 'Rear lights
'write 2,2 'DRLs - Default is on with ignition
'write 3,0 'Lightmode Whether the lights work on full beam (AUX ON/OFF)
'write 4,0 'Rear Ultrasonics
'write 5,0 'Spare tyre loop
'write 6,0 'Pager
'write 7,0 'Rear lid lock
'write 8,1 'Blue leds On as default
'write 9,1 'Voltage auto-off On as default
'write 10,1 'Pin 1
'write 11,1 'Pin 2
'write 12,1 'Pin 3
'write 13,1 'Pin 4'
'write 14,1 'Sequence selected 1 set as default
'write 15,1 'Instant mode What lights are on full beam when they are on
'write 16,4 'Flash delay 1 set as default
'write 17,120 'Voltage target 'Set as 12v as default
'write 199,5,1,0,4,6,3,2 'Sequence 1 'setup the sequences
'write 209,0,1,5,4,2,3,6 'Sequence 2
'write 219,3,2,1,0,4,6,5 'Sequence 3
'write 229,4,0,1,5,3,2,6 'Sequence 4
'write 239,0,1,2,3,4,5,6 'Sequence 5
'write 249,5,0,1,2,3,4,6 'Sequence 6
gosub readdata
flashdelaytotal=flashdelay*100 'converted speed of flash
'rearlights=3 'This sets the rear lights to default igniton 'auto' mode
pause 200
jumpslot=7 ' jump across and display startup message
run 3
'_________________________________________________________________________________________________________________________________
pin_lock:
jumpslot=0
if pin1=1 and pin2=1 and pin3=1 and pin4=1 then goto pin_skip ;If pin is disabled, skip to main menu
jumpslot=3
run 3
pin_skip:
gosub draw_main_menu
;__________________________________________________________________________________________________________________________________
Main_loop:
jumpslot=0
Gosub draw_arrow:
do
if pinc.7=1 then exit
if pind.4=1 then exit
;_________________________________________________________________________________________________________________________________
ignition_present_check: ;Shutdown system if ignition goes off
fvrsetup FVR2048 ;set the ADC reference voltage to 2.048v
adcconfig %1000 ;Vref+ is FVR, Vref- is 0V
readadc10 d.7,voltagevalue ;Obtain reading from voltage input
if voltagevalue>10 then
voltagevalue=voltagevalue*10/46+10 ;Calculation to obtain voltage (when no voltage is present, the calculation will show 6v - hence the reset)
endif
if sfx=1 and voltagevalue<60 then
pause 1000
gosub play_double_tone
endif
if voltagevalue<60 then ;End code if voltage is under 6v
pause 1000
b0=%00000001: Gosub sendcmdbyte 'Clear display
line=148
quote=45
gosub print2lcd
pause 3000
gosub clear3
write 3,lightmode 'Store whether the full beam is in Aux on or Aux off mode
high d.3 'Change state of supply relay to kill the 12v supply
end
endif
;__________________________________________________________________________________________________________________________________
if screensaveron=0 then
screensaver=screensaver+1
endif
if screensaver>2000 and screensaveron=0 then 'If no buttons are pressed after the count, then start displaying the screensaver
screensaveron=1
b0=%00000001: Gosub sendcmdbyte 'Clear display
screensaver=0
endif
screensaverdelay=screensaverdelay+1 'Increase the delay.
if screensaveron=0 then skipped_screensaver_display
if screensaverdelay<>50 then skipped_screensaver_display