using a RTC in SF basic

MrDEB

Well-Known Member
I have a DS-1302 RTC module but how to use it?
I recall Jon Chandler made a vu meter clock but what he used for timing?
Am planning on a clock that has no hands, just LEDs but precision would be nice.
 
and separate data lines for the different colored Leds

I am sorry to be harsh, but you have more resistance to actually LEARNING AND UNDERSTANDING something than anybody I know.

The concept was fully explained in post #192 and others.

To update the LEDs, one byte is shifted out for EVERY 74595 in the string, EVERY TIME. This isn't complicated. Set up an array of bytes equal to the number of 74595s. If you set each byte to zero, all the LEDs will be off. If you set each byte to 255 (i.e., %11111111), all the LEDs will be on. If you want to change the LEDs for one 74595, just change its byte to what you want (say %10101010 to have alternating LEDs on) and shift out ALL THE BYTES.

If you want randon LEDs on, set the byte to a random number....and SHIFT OUT ALL THE BYTES. You don't have to change all the bytes every time, but you do have to SHIFT THEM ALL OUT EVERY TIME.

Using multiple data lines only confuses this.



The picture below shows an instrument designed to my patent (designed by an EE). All of the LEDs are controlled by 74595s on A SINGLE DATA STREAM. Many times per second. And the 74595s could handle many more without breaking a sweat.

Don't try to be creative when you don't even understand THE BASIC CONCEPT. As Beau's videos show, controlling numerous LEDs from one data stream very quickly is easy.

Don't draw more schematics. Don't lay out more circuit boards. Unless and until you somehow manage to understand the basic concepts.

Of course I know this well-intentioned advice will be ignored. I have tried and failed.

 
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


Dim
Counter_upAsWord


Dim
Counter_downAsWord


Dim
mAsByte


Dim
wAsByte


Dim
xAsByte


Dim
yAsByte


Dim
zAsByte


Dim
brightAsWord


Dim
dimmerAsWord


Dim
Bright_1AsLongWord //a wider range of settings FOR A SMOOTHER TRANSITION


DimDimmer_1AsLongWord


Dim
Bright_2AsLongWord //a wider range of settings


DimDimmer_2AsLongWord





Dim
SUB_COUNTAsLongWord


Const
BLUE_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








For
x= 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





Until
INDEX>= 10000





EndSub











Sub
FLICKER_2()


INDEX=1


Counter_down= 1


Repeat


For
x= 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


If
Counter_down>= 2000


Then


Counter_down= 1 //resetcounter_down back to 1


EndIf


Until
INDEX>= 10000


EndSub





Sub
FLICKER_3() //gradualdim to bright


INDEX= 1


Counter= 5


Repeat








For
x= 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
 
I mean here is my bit banged Arduino code that I used in my clock to shift the data. Anyone worth their weight should be able to convert it into just about any language they wanted. ... You could probably fold it into a single line of code. No need to throw a huge bloated library at it for a solution.

Note: The 595 is so fast, that code delays were not necessary.

Code:
void LoadClock(int _Data){
      for (int Bit = 0; Bit < 8; Bit++){
        digitalWrite(Data,bitRead(_Data,Bit));
        digitalWrite(ShiftClock,HIGH);
        digitalWrite(ShiftClock,LOW);
      }
      digitalWrite(RegClock,HIGH);
      digitalWrite(RegClock,LOW);
}
 
the code in post#303 was pertaining only to a software form of PWM I wrote couple years ago
And yes it works
If I have RED and GREEN LEDs on the perimeter chasing around the tree I need one data source
RED LEDs = 10101010
GREEN LEDs = 01010101
for the field I need a separate data source, so the field LEDs are not chasing each other. These using PWM maybe from the code in post #303
At least that what I think
 
If I have RED and GREEN LEDs on the perimeter chasing around the tree I need one data source
RED LEDs = 10101010
GREEN LEDs = 01010101

That will give you ALL red or ALL green. They won't be chasing. That's what you want, dump the '595s and wire the red LEDs to one honking large mosfet and the green LEDs to another honking large mosfet.

The chasing effect I mentioned was one small possibility out of an infinite number of things that could be done. Shrug. Why limit the possibilities from the start?

You just don't get this. It's beyond you ability to understand apparently. I'm done trying to explain. If 3 or 4 people are telling you the same thing, and you choose to ignore the advice and repeated explanations, don't come crying to them when wanderer pile of crap you do doesn't work.

And please properly format or delete your code in post #303. It goes on for FORTY ONE SCREENS on my phone.





I had to include both images. Both reflect my feelings on this.
 
MrDEB, these pictures show your code as it appears in post #303. All 41 screens of it! Crap. Even thumbnail take 8 screens. No pictures – just go look at the mess!

Do you not know how to edit? Or you expect people to deal with your crap?


 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…