Code:
'****************************************************************
' Include files and configure timers
DEFINE WRITE_INT 1
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas"
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _MyTimer, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
endasm
T1CON = %00000001 ; free-running, 1:1 prescaler
@ INT_ENABLE TMR1_INT ; enable Timer1 interrupts
ENABLE DEBUG
'****************************************************************
and now the configs
Code:
'****************************************************************
;Initialization
init:
LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD
option=1
Blue_Day_Cycle = NIGHT
White_Day_Cycle = NIGHT
b_cnt = 0
w_cnt = 0
gosub read_eeprom 'Read in the data needed for the lighting periods
gosub Calc_Fade
'****************************************************************
;************ Main Program Loop *************
'****************************************************************
Main:
If SetButton=0 then ; jump to programming
goto mainmenu
endif
timeH=(RTCHour>>4) 'convert the BCD format of the hours register and store in variable timeH
timeH=(timeH &$03)*10
timeH=timeH+(RTCHour&$0F)
timeM=(RTCMin>>4)
timeM=(timeM &$07)*10
timeM=timeM+(RTCMin&$0F) 'convert the BCD format of the mins register and store in variable timeM
'if B_On_Time_H = timeH and B_On_Time_M = timeM then Blue_Day_Cycle = DAWN
'if W_On_Time_H = timeH and W_On_Time_M = timeM then White_Day_Cycle = DAWN
'if B_Off_Time_H = timeH and B_Off_Time_M = timeM then Blue_Day_Cycle = DUSK
'if W_Off_Time_H = timeH and W_Off_Time_M = timeM then Blue_Day_Cycle = DUSK
'if B_On_Time_H = timeH and B_On_Time_M = timeM then Blue_Day_Cycle = DAWN
gosub calc_fade
'*** Do BLUE daily cycle
select case Blue_Day_Cycle
case DAWN
lcdout $FE,$94,"BL: DAWN "
if b_cnt = B_Fadein_time and B_PWM < B_Max then
B_PWM = B_PWM + 1
b_cnt = 0
endif
if B_PWM = b_max then
Blue_Day_Cycle = DAY
endif
case DAY
lcdout $FE,$94,"BL: DAY "
if timeH = B_Off_Time_H and timeM = B_Off_Time_M then
Blue_Day_Cycle = DUSK
b_cnt = 0
endif
CASE DUSK
lcdout $FE,$94,"BL: DUSK "
if b_cnt >= B_Fadeout_time and B_PWM > B_Min then
B_PWM = B_PWM - 1
b_cnt = 0
endif
if B_PWM = b_min then
Blue_Day_Cycle = NIGHT
endif
case NIGHT
lcdout $FE,$94,"BL: NIGHT"
if timeH = B_On_Time_H and timeM = B_On_Time_M then
Blue_Day_Cycle = DAWN
b_cnt = 0
endif
end select
'*** Do WHITE daily cycle
select case White_Day_Cycle
case DAWN
lcdout $FE,$94+11,"WT: DAWN "
if w_cnt = w_Fadein_time and W_PWM < w_max then
W_PWM = W_PWM + 1
w_cnt = 0
endif
if W_PWM = W_max then White_Day_Cycle = DAY
case DAY
lcdout $FE,$94+11,"WT: DAY "
if timeH = W_Off_Time_H and timeM = W_Off_Time_M then
White_Day_Cycle = DUSK
w_cnt = 0
endif
CASE DUSK
lcdout $FE,$94+11,"WT: DUSK "
if w_cnt >= w_Fadeout_time and W_PWM > w_min then
W_PWM = W_PWM - 1
w_cnt = 0
endif
if W_PWM = W_min then White_Day_Cycle = NIGHT
case NIGHT
lcdout $FE,$94+11,"WT: NIGHT"
if timeH = W_On_Time_H and timeM = W_On_Time_M then
White_Day_Cycle = DAWN
w_cnt = 0
endif
end select
hpwm 1,W_PWM,1500
hpwm 2,B_PWM,1500
lcdout $FE,$80,"BLUES ",dec3 (B_PWM *100)/255,"%"
lcdout $FE,$C0,"WHITES ",dec3 (W_PWM *100)/255,"%"
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)," C"
I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl] ; read DS1307 chip
If RTCHour.6=1 then
CounterA=(RTCHour>>4)&$01 ' Work-Out 12 or 24 hour Display for Hours
else
CounterA=(RTCHour>>4)&$03
endif
CounterA=CounterA*10+(RTCHour&$0F) ' Display Hours appropriately for 12 or 24 hour Mode
If RTCHour.6=1 then
LCDOut $FE,$D4,#CounterA
else
LCDOut $FE,$D4,#CounterA Dig 1,#CounterA Dig 0
endif
LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F
GOTO Main
'****************************************************************
;************ Main Program Loop END *************
'****************************************************************
' Timer used to scale the PWM pulse
MyTimer:
Tick_Tmr = Tick_Tmr + 1
if Tick_Tmr >149 then ;179
Tick_Tmr = 0
b_cnt = b_cnt + 1
W_cnt = W_cnt + 1
endif
@ INT_RETURN
'****************************************************************
Bookmarks