Using 2 or 3 data lines to the74hc595's
#1 data linefor the RED and Green LEDs alternating around the perimeter of theChristmas tree
#2 data lineforsome of the WHITE AND BLUE LEDS in the field
#3 data linetocontrol the remaining WHITE AND BLUE LED's in the field but using PWM
Lookedat the SF PWM module and thinking of using the software PWM I used onmy previous stars
Thisis a gradual bright then dim
*****************************************************************************
}
'Program:CHRISTMAS STAR:
Device=18F43K22
Clock=8
//int osc and IO pin libraries
Include"intosc.bas"
#optionDIGITALIO_INIT= true //automatically call setalldigital
Include"setdigitalio.bas"
//hardware
DimINDEX AsLongWord //4294967295
DimCounterAsWord
DimCounter_upAsWord
DimCounter_downAsWord
DimmAsByte
DimwAsByte
DimxAsByte
DimyAsByte
DimzAsByte
DimbrightAsWord
DimdimmerAsWord
DimBright_1AsLongWord //a wider range of settings FOR A SMOOTHER TRANSITION
DimDimmer_1AsLongWord
DimBright_2AsLongWord //a wider range of settings
DimDimmer_2AsLongWord
DimSUB_COUNTAsLongWord
ConstBLUE_A(16)AsByte=(%00000000,
%00000000,
%00100000, //
%00010000, //
%00000000,
%00000000,
%00000000,
%00000000, //xxxxxxxxxxxx2
%00000000,
%00000000,
%00100000, //
%00010000, //
%00000000,
%00000000,
%00000000,
%00000000)
ConstBLUE_B(16)AsByte= (%10000000, //
%01000000, //
%00100000, //
%00010000, //
%00001000, //
%00000000,
%00000000,
%00000000,//xxxxxxxxxxx5
%10000000, //
%01000000, //
%00100000, //
%00010000, //
%00001000, //
%00000000,
%00000000,
%00000000)
ConstBLUE_C(16)AsByte= (%10000000, //
%01000000, //
%00100000,//
%00000000,
%00001000, //
%00000100, //
%00000010,//
%00000000, //xxxxxxxxxxxxxxxxxxxx6
%10000000,//
%01000000, //
%00100000,//
%00000000,
%00001000, //
%00000100, //
%00000010,//
%00000000)
ConstBLUE_D(16)AsByte= (%10000000,
%01000000,//
%00100000, //
%00010000, //
%00000000,
%00000000,
%00000000,
%00000001,//xxxxxxxxxx5
%10000000,
%01000000,//
%00100000, //
%00010000, //
%00000000,
%00000000,
%00000000,
%00000001)//
ConstWHITE_A(8)AsByte=(%10000000,
%01000000,
%00000000,
%00010000,
%00001000,
%00000100,
%00000010,
%00000001)
ConstWHITE_B(8)AsByte=(%00000000,
%00000000,
%00000000,
%00000000,
%00000000,
%00000100,
%00000010,
%00000001)
ConstWHITE_C(8)AsByte=(%00000000,
%00000000,
%00000000,
%00010000,
%00000000,
%00000000,
%00000000,
%00000001)
ConstWHITE_D(8)AsByte=(%10000000,
%00000000,
%00000000,
%00000000,
%00001000,
%00000100,
%00000010,
%00000000)
ConstBLUE_E(16)AsByte = (%00000100,
%00000010,
%00000001, //3
%00000000,
%00000000,
%00000100,
%00000010,
%00000001,
%00000100,
%00000010,
%00000001,
%00000000,
%00000000,
%00000100,
%00000010,
%00000001)
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ConstWHITE_Af(1)AsByte=(%11100111)
//-------------------------------------
//PATTERNSUBROUTES
SubFLICKER_1()
INDEX= 1
Repeat
Forx= 0 To7 //WHITE
Forz= 0 To7 //BLUE
PORTA= WHITE_A(x)
DelayMS(1000)
PORTA= BLUE_A(z)
DelayUS(50)
PORTB= WHITE_B(x)
DelayMS(1000)
PORTB= BLUE_B(z)
DelayUS(50)
PORTC= WHITE_C(x)
DelayMS(1000)
PORTC= BLUE_C(z)
DelayUS(50)
PORTD= WHITE_D(x)
DelayMS(1000)
PORTD= BLUE_D(z)
DelayUS(50)
PORTE= BLUE_E(z)
DelayUS(50)
INDEX= (INDEX + 1)
Next
Next
UntilINDEX>= 10000
EndSub
SubFLICKER_2()
INDEX=1
Counter_down= 1
Repeat
Forx= 0 To7
Forz= 0 To16 //allthe blue leds
PORTA= WHITE_A(x)
DelayUS(Counter_down)
PORTA= BLUE_A(z)
DelayUS(25)
PORTB= WHITE_B(x)
DelayUS(Counter_down)
PORTB= BLUE_B(z)
DelayUS(25)
PORTC= WHITE_C(x)
DelayUS(Counter_down)
PORTC= BLUE_C(z)
DelayUS(25)
PORTD= WHITE_D(x)
DelayUS(Counter_down)
PORTD= BLUE_D(z)
DelayUS(25)
PORTE= BLUE_E(z)
DelayUS(10)
INDEX= (INDEX + 1)
Counter_down= (Counter_down + 1) //dimmingeffect
Next
Next
IfCounter_down>= 2000
Then
Counter_down= 1 //resetcounter_down back to 1
EndIf
UntilINDEX>= 10000
EndSub
SubFLICKER_3() //gradualdim to bright
INDEX= 1
Counter= 5
Repeat
Forx= 0 To7
Forz= 0 To7
PORTA= WHITE_A(x)
DelayUS(Counter)
PORTA= BLUE_A(z)
DelayUS(50)
PORTB= WHITE_B(x)
DelayUS(Counter)
PORTB= BLUE_B(z)
DelayUS(50)
PORTC= WHITE_C(x)
DelayUS(Counter)
PORTC= BLUE_C(z)
DelayUS(50)
PORTD= WHITE_D(x)
DelayUS(Counter)
PORTD= BLUE_D(z)
DelayUS(50)
PORTE= BLUE_E(z)
DelayUS(50)
INDEX= (INDEX + 1)
Next
Next
Counter= (Counter +1)
UntilINDEX>= 10000
EndSub
//zzzzzzzzzzzzzzzzzzzzzzzzzz
SubAll_off()
PORTE=%000
PORTD=%00000000
PORTC=%00000000
PORTA=%00000000
PORTB=%00000000
EndSub
//zzzzzzzzzzzzzzzzzzzzzzzzzzzzz
SubFade()
bright= 5000
dimmer= 1
Bright_1= 1 //bright_1 is ON time variable
Dimmer_1= 5000 //dimmer_1is OFF time variable
Repeat
PORTA= %11011111
PORTB= %00000111
PORTC= %00010001
PORTD= %10001110
PORTE= %000
DelayUS(Bright_1)
PORTA= %00000000
PORTB= %00000000
PORTC= %00000000
PORTD= %00000000
//DIMMING
DelayUS(Dimmer_1)
Bright_1= (Bright_1 +1) //increase ON time BY 1
Dimmer_1= (Dimmer_1 - 1) //decreaseOFF time BY 1
Until
Bright_1>= 3000 //HIGHBRIGHT
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//resetvalues
Bright_2= 5000
Dimmer_2= 1
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Repeat
PORTA= %11011111
PORTB= %00000111
PORTC= %00010001
PORTD= %10001110
DelayUS(Bright_1)
PORTA= %00000000
PORTB= %00000000
PORTC= %00000000
PORTD= %00000000
DelayUS(Dimmer_2) //full dim FIRST PASS IN LOOP
Bright_2= (Bright_2 - 1)
Dimmer_2= (Dimmer_2 + 1)
Until
Bright_2= 1
//resetvaluesxxxxxxxxxxxxxx
Bright_2= 1
Dimmer_2= 5000
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
EndSub
//zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
//-------------------------------------
//start of main program
//-------------------------------------
main:
//init hdw
//LED port - all outputs 2 LEDs per port in parallel 330 ohm resistor
TRISA= 0 //SET ALL PORTS AS OUTPUTS
TRISB= 0
TRISC= 0
TRISD= 0
TRISE= 0
PORTE=%000 //TURNOFF ALL PORTS
PORTD=%00000000
PORTC=%00000000
PORTA=%00000000
PORTB=%00000000
Bright_1= 0
Dimmer_1= 0
Bright_2= 0
Dimmer_2= 0
setalldigital
Whiletrue
Fade() //ADDA COUNTER TO MAKE IT LONGER
FLICKER_1()
All_off() //indicates sequence change
DelayMS(50)
FLICKER_2()
All_off() //indicates sequence change
DelayMS(50)
FLICKER_3()
Wend