Code:
'*******************************************************************************
' Variables
'*******************************************************************************
DecButton var PORTA.0 ' Press to Decrement Button
SetButton var PORTA.1 ' Press to Set/memorise Button
IncButton var PORTA.2 ' Press to Increment Button
H_butt VAR PORTA.2
M_butt VAR PORTA.0
S_butt VAR PORTA.1
Counter1 var word
' LED variables - Whites:
W_Min var word 'Min Light value
W_Max var word 'Max Light value
' LED variables - Blues:
B_Min var word 'Min Light value
B_Max var word 'Max Light value
'PWM Variables where the current output values are stored
W_PWM var word 'Whites
B_PWM var word 'Royal Blues
HzTimer VAR Word '1/2 second counter (2 Hz)
HH VAR Byte ' Hours 0-23
MM VAR ByTE ' Minutes 0-59
SS VAR Byte ' Seconds 0-59
col VAR Byte ' colon 1=on, 0=0ff
old_ss var byte
'*******************************************************************************
Blue_Day_Cycle var word 'Store for which part of the day cycle we are in
White_Day_Cycle var word
' Constants for the current running mode cycle for the lights
DAWN con 0
DAY con 1
DUSK con 2
NIGHT con 3
'*******************************************************************************
;Initialization
LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD
LCDOUT $FE,1
lcdout $FE,$C0," Version R "
pause 2000 'wait 2 seconds so they can see it
lcdout $FE,1 'Clear the screen
HzTimer=$7A12 'for 1/2 Sec
HH=19:MM=59:SS=50:col=0 'initial conditions (19:59 )
B_MAX=255
W_MAX=255
'*******************************************************************************
'************ Main Program Loop *************
'*******************************************************************************
Main:
ClockLoop: IF intcon.2=0 THEN ClockLoop 'Poll for TMRO overflow
INTCON.2=0 ' Clear TMRO overflow flag
HzTimer=HzTimer-$1000 'decrement timer count
IF HzTimer < $1000 THEN
IF Col=10 THEN ' update time'
SS=SS+1
IF SS=60 THEN ' minute
SS=0
MM=MM+1
IF MM=60 THEN ' hour
MM=0
HH=HH+1
IF HH=24 THEN HH=0
ENDIF
counter1 = (HH*60)+MM
ENDIF
ENDIF
Col=Col+1
HzTimer=HzTimer+$7A12 ' Add 0.5 seconds to count
ELSE
' Do something here but must be less than 65.5 mSec
ENDIF
if Col=11 then
Col=1
endif
LCDOut $FE,$D4,#HH DIG 1,#HH DIG 0,":",#MM DIG 1,#MM DIG 0,":",#SS DIG 1,#SS Dig 0
If Counter1 < 1200 then
Blue_day_cycle = NIGHT
endif
if Counter1 = 1200 then
Blue_day_cycle = DAWN
endif
If Counter1 < 1200 then
White_day_cycle = NIGHT
endif
if Counter1 = 1200 then
White_day_cycle = DAWN
endif
'*** Do BLUE daily cycle
select case Blue_Day_Cycle
case DAWN
lcdout $FE,$80+13,"DAWN "
if ss//1= 0 then
if ss != old_ss then
B_PWM=B_PWM+1
old_ss=ss
endif
endif
if B_PWM = b_max then
Blue_Day_Cycle = DAY
endif
case DAY
lcdout $FE,$80+13,"DAY "
if counter1 =1210 then
Blue_day_cycle = DUSK
endif
CASE DUSK
lcdout $FE,$80+13,"DUSK "
if ss//1= 0 then
if ss != old_ss then
B_PWM=B_PWM-1
old_ss=ss
endif
endif
if B_PWM = b_min then
Blue_Day_Cycle = NIGHT
endif
case NIGHT
lcdout $FE,$80+13,"NIGHT"
B_PWM=B_min
end select
'*** Do WHITE daily cycle
select case White_Day_Cycle
case DAWN
lcdout $FE,$C0+13,"DAWN "
if ss//1= 0 then
if ss != old_ss then
W_PWM = W_PWM+1
old_ss=ss
endif
endif
if W_PWM = W_max then
White_Day_Cycle = DAY
endif
case DAY
lcdout $FE,$C0+13,"DAY "
if counter1 =1210 then
White_day_cycle = DUSK
endif
CASE DUSK
lcdout $FE,$C0+13,"DUSK "
if ss//1= 0 then
if ss != old_ss then
W_PWM=W_PWM-1
old_ss=ss
endif
endif
if W_PWM = W_min then
White_Day_Cycle = NIGHT
endif
case NIGHT
lcdout $FE,$C0+13,"NIGHT"
W_PWM=W_min
end select
hpwm 1,W_PWM,200
hpwm 2,B_PWM,200
If (B_PWM * 100)/255 = 100 then
lcdout $FE,$80,"BLUES ",dec3 (B_PWM *100)/255,"%"
endif
If (B_PWM * 100)/255 =0 or (B_PWM * 100)/255 <10 then
lcdout $FE,$80,"BLUES ",dec1 (B_PWM *100)/255,"% "
endif
if (B_PWM * 100)/255 >=10 and (B_PWM * 100)/255 <100 then
lcdout $FE,$80,"BLUES ",dec2 (B_PWM *100)/255,"% "
endif
If (W_PWM*100)/255 >= 100 then
lcdout $FE,$C0,"WHITES ",dec3 (W_PWM *100)/255,"%"
endif
If (W_PWM * 100)/255 <=0 or (W_PWM * 100)/255 <10 then
lcdout $FE,$C0,"WHITES ",dec1 (W_PWM *100)/255,"% "
endif
if (W_PWM * 100)/255 >=10 AND (W_PWM * 100)/255 <100 then
lcdout $FE,$C0,"WHITES ",dec2 (W_PWM *100)/255,"% "
endif
'Get and display the temperature
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
temperature = temperature */ 1600
lcdout $FE,$D4+11,"TEMP ",DEC(temperature / 100),$DF,"C"
GOTO Main
''****************************************************************
';************ Main Program Loop END *************
''****************************************************************
Any suggestions ?
Bookmarks