Fixed the code, added fading when going into standby mode and corrected some errors:

Code:

;LED Backlight PWM program V3 with instantaneous fading
;Written for Mazda3 CarPC by Tim Stocker
;
;Output 2 - LED Backlight
;Input 4 - LDR with 10Kohm Resistor
;Input 0 - Power-on V+ from monitor (9.45V = 65 w/100kOhm & 33.3kOhm voltage divider)
symbol LED = 2
symbol LDR = 4
symbol PWR = 0
setfreq m8 ;overclocking to 8MHz
Startup:
readadc PWR,b3
if b3<50 then Standby
readadc LDR,b1
if b1>=160 then Sunny
if b1>80 and b1<160 then Dusk
if b1<=80 then Night
goto startup
Sunny:
readadc PWR,b3
if b3<50 then subsunny
pwmout LED, 86, 275
readadc LDR,b1
if b1<=160 then DES_Sunny_to_Dusk
goto Sunny
subsunny:
b4=255
goto Standby
DES_Sunny_to_Dusk:
readadc PWR,b3
if b3<50 then subsunny
b2=255
for b2 = 255 to 100 step -1
pwmout LED, 88, b2
pause 15
next b2
goto Dusk
ASC_Dusk_to_Sunny:
readadc PWR,b3
if b3<50 then subdusk
b2=100
for b2 = 100 to 254
pwmout LED, 88, b2
pause 15
next b2
goto Sunny
Dusk:
readadc PWR,b3
if b3<50 then subdusk
pwmout LED, 90, 100
readadc LDR,b1
if b1>=180 then ASC_Dusk_to_Sunny
if b1<=80 then DES_Dusk_to_Night
goto Dusk
subdusk:
b4=100
goto Standby
ASC_Night_to_Dusk:
readadc PWR,b3
if b3<50 then subnight
b2=20
for b2 = 20 to 100
pwmout LED, 92, b2
pause 20
next b2
goto Dusk
DES_Dusk_to_Night:
readadc PWR,b3
if b3<50 then subdusk
b2=100
for b2 = 100 to 20 step -1
pwmout LED, 92, b2
pause 20
next b2
goto Night
Night:
readadc PWR,b3
if b3<50 then subnight
pwmout LED, 94, 20
readadc LDR,b1
if b1>=100 then ASC_Night_to_Dusk
goto Night
subnight:
b4=20
goto Standby
Standby:
b2=b4
for b2 = b4 to 0 step -1
pwmout LED, 86, b2
pause 5
next b2
do
pwmout LED, off
readadc PWR,b3
loop until b3>50
goto Startup

## Bookmarks